JMIG57762019-06-23T22:55:38+00:00https://jmig5776.github.io/Jogi Miglanijmig5776@gmail.comGSoC 2019 - Week 42019-06-22T00:00:00+00:00https://jmig5776.github.io//gsoc-week-4<p>This was the fourth week meeting with the GSoC mentors which was scheduled on
Sunday 22th June, 2019 between 12:30 - 01:30 PM (IST). Me and Yathartha
were the attendees of the meeting.</p>
<ul>
<li>Discussing previous week’s progress</li>
</ul>
<p>In the previous week many things happened very suddenly. In the starting of the
week it was decided that we had to create a function <code class="highlighter-rouge">power_list</code> which could
return powers. So I thought to create this type of function as a new feature in
this PR <a href="https://github.com/sympy/sympy/pull/17043">#17043</a>.
But as @jksoum and @smichr advised that this function can act as
helper function in <code class="highlighter-rouge">bivariate</code> itself so it was decided to make it as helper
function there. And we discussed the code for handling modular equations also.</p>
<ul>
<li>
<p>Next week goals</p>
</li>
<li>
<p>Implementing and get plan for defining imageset union</p>
</li>
</ul>
<p>As per the timeline we decided that Imageset Union should be defined first rather
than code for handling nested trigonometric equation solver. So according to
timeline this week goes for discussion and getting plan for implementing imageset
union. A PR <a href="https://github.com/sympy/sympy/pull/17079">#17079</a> is also started
based on fundamental approach to solve the problem.</p>
<ul>
<li>Getting merge Lambert Solver</li>
</ul>
<p>Most of the work had been done only a little improvement is to be done in <code class="highlighter-rouge">power_list</code>
function. Hope it gets merged by this week.</p>
<p>Code improvement takes time!!</p>
GSoC 2019 - Week 32019-06-16T00:00:00+00:00https://jmig5776.github.io//gsoc-week-3<p>This was the third week meeting with the GSoC mentors which was scheduled on
Sunday 16th June, 2019 between 12:00 - 01:00 PM (IST). Me, Amit, Yathartha and
Shekhar were the attendees of the meeting. In this meeting mainly it was discussed
to improve the code quality and make routine of independent working code.</p>
<ul>
<li>Code quality</li>
</ul>
<p>Every programmer should master this skill to write a good quality code. Everything from
naming, documentation to make routines includes in this skill.</p>
<p>And we discussed mainly the code for the PR <a href="https://github.com/sympy/sympy/pull/16890">#16890</a>
and realising that a new function <code class="highlighter-rouge">power_list</code> to be made to return all the
powers of symbols present in an expression.</p>
<p>Learning new skills!!</p>
GSoC 2019 - Week 22019-06-08T00:00:00+00:00https://jmig5776.github.io//gsoc-week-2<p>This was the second week meeting with the GSoC mentors which was scheduled on
Saturday 8th June, 2019 between 12:00 - 01:00 PM (IST). Me, Amit, Yathartha and Harsh
were the attendees of the meeting. It was a surprise having Harsh on this meeting.
In this meeting we mainly discussed about how to integrate lambert another way because
the existing method in PR <a href="https://github.com/sympy/sympy/pull/16890">#16890</a> is
not trustworthy and upto the mark. So this week I will try to implement the method
or approach told by Yathartha. Important lesson learned in this meeting was that
the method that I implement should have these following qualities to be a better
software developer:-</p>
<ul>
<li>Proof Of Correctness</li>
</ul>
<p>This is very important because I should have a plan before I get to code. Many
things already get straightened up while planning for what to implement and it
ultimately reduces coding time and let us get a more accurate and concrete code.</p>
<ul>
<li>Clean and Understandable Code</li>
</ul>
<p>This factor is also very important to write a code that is easily understandable.
It is better for us as well as it also persuade new contributors easily who are
willing to contribute.</p>
<ul>
<li>Extensible Code</li>
</ul>
<p>A well written code is always extensible. Proper techniques should be learned to
write an extensible code rather than a code that looks like patch.</p>
<p>In this week I also started a PR <a href="https://github.com/sympy/sympy/pull/16976">#16976</a>
to handle modular equations.<br />
It was a worth it meeting because I got to learn various important and necessary
qualities from all of the mentors. Harsh was also glad that we were trying to focus
on well written clean code.</p>
<p>A lot more to learn and implement :) !!</p>
GSoC 2019 - Week 12019-06-02T00:00:00+00:00https://jmig5776.github.io//gsoc-week-1<p>This was the first week meeting with the GSoC mentors which was scheduled on
Sunday 2nd June, 2019 between 11:30 AM - 12:30 PM (IST). Me, Amit and Yathartha
were the attendees of the meeting. In this meeting we mainly discussed about the
problems and implementation for my pull request <a href="https://github.com/sympy/sympy/pull/16890">#16890</a>
to complete the lambert solver.<br />
As Amit requested changes at the pull request to describe the problem in detail,
to give proof of correctness and describe the plan more briefly. So here below
are the all details for what I am trying to achieve and how I am trying to
achieve this:-</p>
<h3 id="current-implementation">Current Implementation</h3>
<p>Let me show here code from <code class="highlighter-rouge">_lambert</code> function to show the current
implementation so that I could describe the problem in detail:-</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">u</span> <span class="o">=</span> <span class="n">Dummy</span><span class="p">(</span><span class="s">'rhs'</span><span class="p">)</span>
<span class="n">sol</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c"># check only real solutions:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]:</span>
<span class="n">l</span> <span class="o">=</span> <span class="n">LambertW</span><span class="p">(</span><span class="n">d</span><span class="o">/</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">c</span><span class="o">*</span><span class="n">d</span><span class="o">/</span><span class="n">a</span><span class="o">/</span><span class="n">b</span><span class="p">)</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">f</span><span class="o">/</span><span class="n">a</span><span class="p">),</span> <span class="n">k</span><span class="p">)</span>
<span class="c"># if W's arg is between -1/e and 0 there is</span>
<span class="c"># a -1 branch real solution, too.</span>
<span class="k">if</span> <span class="n">k</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">l</span><span class="o">.</span><span class="n">is_real</span><span class="p">:</span>
<span class="k">continue</span>
<span class="n">rhs</span> <span class="o">=</span> <span class="o">-</span><span class="n">c</span><span class="o">/</span><span class="n">b</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span><span class="o">/</span><span class="n">d</span><span class="p">)</span><span class="o">*</span><span class="n">l</span>
<span class="n">solns</span> <span class="o">=</span> <span class="n">solve</span><span class="p">(</span><span class="n">X1</span> <span class="o">-</span> <span class="n">u</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">tmp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">solns</span><span class="p">):</span>
<span class="n">solns</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">rhs</span><span class="p">)</span>
<span class="n">sol</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">solns</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">return</span> <span class="n">sol</span>
</code></pre></div></div>
<p>Explanation of for loop:</p>
<ol>
<li><code class="highlighter-rouge">k == -1</code> :- In this case all the real solutions are considered due to <code class="highlighter-rouge">not l.is_real</code>.</li>
<li><code class="highlighter-rouge">k == 0</code> :- In this case all the solutions come out to be real as always.</li>
</ol>
<h3 id="what-solutions-are-missed">What solutions are missed?</h3>
<p>The solutions are missed due to the argument inside the <code class="highlighter-rouge">LambertW</code> function of value</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>l = LambertW(d/(a*b)*exp(c*d/a/b)*exp(-f/a), k)
</code></pre></div></div>
<p>While converting all lambert solvable equations to this form
<code class="highlighter-rouge">F(X, a..f) = a*log(b*X + c) + d*X + f = 0</code> some solutions get missed.</p>
<p>For eg:
Consider the equation <code class="highlighter-rouge">(a/x + exp(x/2)).diff(x) = 0</code> which is
<code class="highlighter-rouge">-a/x**2 + exp(x/2)/2 = 0</code>(Please take note of the <code class="highlighter-rouge">x**2</code> in denominator of a).
And we can also write this equation as <code class="highlighter-rouge">-a/(-x)**2 + exp(x/2)/2 = 0</code>.
What sympy do is to convert this equation to this form:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>F(X, a..f) = a*log(b*X + c) + d*X + f = 0
</code></pre></div></div>
<p>which will be <code class="highlighter-rouge">2*log(x) + x/2 - log(a) = 0</code> and <code class="highlighter-rouge">2*log(-x) + x/2 - log(a) = 0</code> respectively:
So solutions corresponding to both equations are:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2*log(x) + x/2 - log(a) = 0 --> [4*LambertW(sqrt(2)*sqrt(a)/4)] --> this is currently included
2*log(-x) + x/2 - log(a) = 0 --> [4*LambertW(-sqrt(2)*sqrt(a)/4)] --> this is missed
</code></pre></div></div>
<h3 id="what-type-of-lambert-type-equation-it-is-for">What type of lambert type equation it is for?</h3>
<p>This is for the equations where the changing of cofficients of the target equation doesn’t
change the original equation just like the above case.</p>
<h3 id="whats-the-current-algorithm-to-solve-such-type-of-equation-and-whats-wrong-with-current-logic">What’s the current algorithm to solve such type of equation and what’s wrong with current logic?</h3>
<p>Current implementation is shown above and what is wrong is that it is not considering
the other logarithm equations which are originated from the original equation.
<code class="highlighter-rouge">2*log(-x) + x/2 - log(a) = 0</code> in case of <code class="highlighter-rouge">(a/x + exp(x/2)).diff(x) = 0</code>.</p>
<h3 id="whats-the-proposed-solution">What’s the proposed solution?</h3>
<p>This problem can be solved by two methods as follows:</p>
<ul>
<li>Combining all the logarithm forms generated by the original equation(by taking abs)
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2*log(x) + x/2 - log(a) = 0 + 2*log(-x) + x/2 - log(a) = 0
\ /
\ /
\ /
2*log(abs(x)) + x/2 - log(a) = 0
</code></pre></div> </div>
<p>I think this method is not viable at this time as it will be very complex to solve
the equation invloving abs with log.</p>
</li>
<li>This method I propose to solve this problem i.e considering all solutions and
eliminating by substitution.
For example for this equation <code class="highlighter-rouge">(1/x + exp(x/2)).diff(x) = 0</code>
Possible solutions considered <code class="highlighter-rouge">[4*LambertW(-sqrt(2)*sqrt(a)/4), 4*LambertW(sqrt(2)*sqrt(a)/4), \
4*LambertW(-sqrt(2)*sqrt(a)/4, -1), 4*LambertW(sqrt(2)*sqrt(a)/4, -1)]</code>
Solutions after filtering from checksol <code class="highlighter-rouge">[4*LambertW(-sqrt(2)*sqrt(a)/4), 4*LambertW(sqrt(2)*sqrt(a)/4)]</code>.</li>
</ul>
<h3 id="why-is-the-proposed-solution-better-and-how-it-wont-effect-the-other-equations-no-side-effects">Why is the proposed solution better and how it won’t effect the other equations (no side effects)?</h3>
<p>This method involves less computation to solve this problem i.e considering all solutions and
eliminating by substitution rather than first converting the given equation to target equation
in which we doesn’t know about coffecient of logarithmic equation and solving it again by
making different equations from it in case of abs taken.</p>
<p>This doesn’t effect other equation because the only thing we are doing is considering all solutions
and not changing code for other type of equations. And we are using checksol to check the correct solutions.</p>
<h3 id="what-is-the-testing-strategy-to-verify-that-the-proposed-solution-works">What is the testing strategy to verify that the proposed solution works?</h3>
<p>Testing strategy should be to involve the cases where current implementation is
missing other logarithmic equations.</p>
<h3 id="which-examplesequations-are-we-going-to-use-to-make-sure-that-those-are-necessary-and-sufficient-for-testing-purposes">Which examples/equations are we going to use to make sure that those are necessary and sufficient for testing purposes?</h3>
<p>According to me these tests are sufficient test this strategy:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>assert solve((a/x + exp(x/2)).diff(x), x) == \
[4*LambertW(-sqrt(2)*sqrt(a)/4), 4*LambertW(sqrt(2)*sqrt(a)/4)]
assert solve(x*log(x) + 3*x + 1, x) == \
[exp(-3 + LambertW(-exp(3))), exp(-3 + LambertW(-exp(3), -1))]
assert solve((1/x + exp(x/2)).diff(x, 2), x) == \
[6*LambertW((-1)**(S(1)/3)/3), 6*LambertW((-1)**(S(1)/3)/3, -1)]
assert solve(-x**2 + 2**x, x) == [2, 4, -2*LambertW(log(2)/2)/log(2)]
# issue 4271
assert solve((a/x + exp(x/2)).diff(x, 2), x) == \
[6*LambertW(-(-1)**(S(1)/3)*a**(S(1)/3)/3),
6*LambertW((-1)**(S(1)/3)*a**(S(1)/3)/3),
6*LambertW(-(-1)**(S(1)/3)*a**(S(1)/3)/3, -1),
6*LambertW((-1)**(S(1)/3)*a**(S(1)/3)/3, -1)]
assert solve(x**2 - y**2/exp(x), x, y, dict=True) == \
[{x: 2*LambertW(-y/2)}, {x: 2*LambertW(y/2)}]
</code></pre></div></div>
<h3 id="some-test-cases-that-fail-due-to-some-other-reasons">Some test cases that fail due to some other reasons</h3>
<ul>
<li>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>assert solve((1/x + exp(x/2)).diff(x), x) == \
[4*LambertW(-sqrt(2)/4), 4*LambertW(sqrt(2)/4), 4*LambertW(-sqrt(2)/4, -1)]
assert solve(x**2 - 2**x, x) == [2, 4]
</code></pre></div> </div>
<p>These tests are failing because checksol returns false but expected to return true
Although <code class="highlighter-rouge">_lambert</code> is returning correct solutions of equation.</p>
</li>
<li>
<p><code class="highlighter-rouge">assert solve(a/x + exp(x/2), x) == [2*LambertW(-a/2), 2*LambertW(a/2)]</code>
In this case <code class="highlighter-rouge">2*LambertW(a/2)</code> which is not a solution is included because checksol returns none.</p>
</li>
<li>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>>>>solve((1/x + exp(x/2)).diff(x, 2), x)
[6*LambertW((-1)**(1/3)/3), 6*LambertW((-1)**(1/3)/3, -1)]
</code></pre></div> </div>
<p>here <code class="highlighter-rouge">(-1)**1/3</code> can have these values <code class="highlighter-rouge">-1, 1/6(1 - I*3**1/3), 1/6(1 + I*3**1/3)</code>
but sympy only take <code class="highlighter-rouge">(-1)**1/3</code> to be <code class="highlighter-rouge">1/6(1 - I*3**1/3)</code> whereas
real solutions are <code class="highlighter-rouge">[6*LambertW(-1/3), 6*LambertW(-1/3, -1)]</code></p>
</li>
</ul>
<h3 id="why-including-checksol-in-_solve_lambert-">Why including checksol in <code class="highlighter-rouge">_solve_lambert</code> ?</h3>
<p>Due to this test case:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>p = symbols('p', positive=True)
eq = 4*2**(2*p + 3) - 2*p - 3
assert _solve_lambert(eq, p, _filtered_gens(Poly(eq), p)) == [
-S(3)/2 - LambertW(-4*log(2))/(2*log(2))]
</code></pre></div></div>
<p>To remove the solutions which were supposed to be checked by checksol later in solve.</p>
<p>Pardon me if I missed a thing!!</p>
GSoC 2019 - Community bonding period2019-05-23T00:00:00+00:00https://jmig5776.github.io//gsoc-cbp<p>My first meeting with the GSoC mentors was on Saturday 18th May, 2019 scheduled
between 11:30 AM - 12:30 PM (IST). Me, Amit and Yathartha were the attendees of
the meeting. As per the community bonding period the first meeting was meant to
increase the familiarity between me and my mentors and we also discussed about
completing lambert solver. Major points discussed in the meeting are:-</p>
<ul>
<li>
<p>Schedule and frequency of meetings.</p>
</li>
<li>
<p>How to proceed with completing lambert, understanding existing code and
writing tests for it.</p>
</li>
</ul>
<p>As of now I have looked few things:</p>
<ul>
<li>
<p>How <code class="highlighter-rouge">lambert</code> works in <code class="highlighter-rouge">bivariate</code>.</p>
</li>
<li>
<p>How equations are converted to target equation.</p>
</li>
<li>
<p>Filtering out the tests to include all solutions.</p>
</li>
<li>
<p>What will be the flow to fix this problem.</p>
</li>
</ul>
<p>In the previous days I have been understanding the flow of <code class="highlighter-rouge">bivariate</code> along with
<code class="highlighter-rouge">solve</code> and <code class="highlighter-rouge">solveset</code>. It might take time for me to go through it and arrive
at a good plan but I am trying to learn the art of general aspects of a open
source software. I believe in understanding rather than rushing. The mentors were
very kind and helpfull.</p>
<p>Hope things go as planned!!</p>