Jekyll2020-02-12T19:09:19+00:00https://8hantanu.me/atom.xmlShantanu’s ShallopShantanu's shallop - random patterns ...Shantanu MishraMathjax Test2018-09-06T00:00:00+00:002018-09-06T07:00:00+00:00https://8hantanu.me/gecko%20taco/2018/09/06/mathjax-test<p><strong>How to approach the following two dimensional recurrence relation ?</strong></p>
<p>For <script type="math/tex">i,j\ge2</script>,</p>
<script type="math/tex; mode=display">a_{i,\ j}\ =\ a_{i,\ j-1}\ +\ a_{i-1,\ j-1}</script>
<p>where <script type="math/tex">a_{p,\ 1}=1</script> (for <script type="math/tex">p\ge1</script>) and <script type="math/tex">a_{1,\ q} = 1</script> (for <script type="math/tex">q\ge1)</script>.</p>
<p><strong>Solution</strong>:</p>
<p>One way to go about this and generally about solving recurrence relations is to use generating functions, in this case this will lead to two variable generating function.</p>
<p>Let’s suppose we have <script type="math/tex">f(x,y)=\sum_{i,j=0}^{\infty}a_{i,j} x^i y^j</script> formal powers series which encodes coefficients of your sequence. For simplicity, here we have it shifted, so actually <script type="math/tex">a_{0,q}=a_{p,0}=1</script>, but don’t worry about that, we can shift this back at the end. Now let’s play with coefficients a little to see if we can get better form of <script type="math/tex">f(x,y)</script>:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
f(x,y)&=\sum_{i,j=0}^{\infty}a_{i,j} x^i y^j \\
&=a_{0,0}+\sum_{i=1}^{\infty}a_{i,0} x^i+\sum_{j=1}^{\infty}a_{0,j} y^j + \sum_{i,j=1}^{\infty}a_{i,j} x^i y^j \\
\end{align} %]]></script>
<p>Now we have shifted the indices (you will see later why), but before proceeding, notice <script type="math/tex">a_{0,0}=1</script> and that</p>
<script type="math/tex; mode=display">\sum_{i=1}^{\infty}a_{i,0} x^i = x+x^2+x^3+\dots = \frac{x}{1-x}</script>
<p>and similarly for the second sum. So overall we have</p>
<script type="math/tex; mode=display">f(x,y) = 1+\frac{x}{1-x}+\frac{y}{1-y}+\sum_{i,j=1}^{\infty}a_{i,j} x^i y^j</script>
<p>Now for the rightmost sum, lets write</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\sum_{i,j=1}^{\infty}a_{i,j} x^i y^j &= \sum_{i,j=1}^{\infty}(a_{i,j-1}+a_{i-1,j-1}) x^i y^j \\
&= \sum_{i,j=1}^{\infty}a_{i,j-1} x^i y^j+\sum_{i,j=1}^{\infty}a_{i-1,j-1} x^i y^j \\
&= y\sum_{i,j=1}^{\infty}a_{i,j-1} x^i y^{j-1}+xy\sum_{i,j=1}^{\infty}a_{i-1,j-1} x^{i-1} y^{j-1}\\
\end{align} %]]></script>
<p>Here we have just applied the recurrence relation (this is why we moved the <script type="math/tex">0</script> indices out before) and then moved the <script type="math/tex">x</script>,<script type="math/tex">y</script> out of the sum, so that indices match. Now lets just re-index the sum</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\sum_{i,j=1}^{\infty}a_{i,j} x^i y^j &= y\sum_{i,j=1}^{\infty}a_{i,j-1} x^i y^{j-1}+xy\sum_{i,j=1}^{\infty}a_{i-1,j-1} x^{i-1} y^{j-1}\\
&= y\sum_{i=1,j=0}^{\infty}a_{i,j} x^i y^{j}+xy\sum_{i,j=0}^{\infty}a_{i,j} x^{i} y^{j}\\
&= y\left(\sum_{i=0,j=0}^{\infty}a_{i,j} x^i y^{j}-\sum_{j=0}^{\infty}a_{0,j}\right)+xy\sum_{i,j=0}^{\infty}a_{i,j} x^{i} y^{j}\\
&= y\left(f(x,y)-\sum_{j=0}^{\infty}a_{0,j}\right)+xyf(x,y)\\
&= y\left(f(x,y)-\frac{1}{1-y}\right)+xyf(x,y)\\
\end{align} %]]></script>
<p>Here we have just substituted back the definition of <script type="math/tex">f(x,y)</script> itself. Now putting back together we have</p>
<script type="math/tex; mode=display">\begin{align}
f(x,y)=1+\frac{x}{1-x}+\frac{y}{1-y}+ y\left(f(x,y)-\frac{1}{1-y}\right)+xyf(x,y)\\
\end{align}</script>
<p>and after some simple algebraic manipulations we finally get:</p>
<script type="math/tex; mode=display">\begin{align}
f(x,y) = \frac{1}{(1-x)(1-y-xy)}\\
\end{align}</script>
<p>Now the <script type="math/tex">f(x,y)</script> encodes all of the coefficients in a compact way. We can now try to write it in a way that will allow us to see the coefficients more clearly.</p>
<p>For this notice that <script type="math/tex">\frac{1}{1-x}=1+x+x^2+x^3+\dots</script>. Also second expression is well known generating function <script type="math/tex">\frac{1}{1-y-yx}=\frac{1}{1-y(x+1)}=\sum_{i,j=0}^{\infty}\binom{j}{i} x^i y^j.</script></p>
<p>So we can view our function in this form as a product</p>
<script type="math/tex; mode=display">f(x,y) = (1+x+x^2+x^3+\dots) \left(\sum_{i,j=0}^{\infty}\binom{j}{i} x^i y^j\right)</script>
<p>Now to ask what is the value of <script type="math/tex">a_{i,j}</script> is same as to ask what coefficient of <script type="math/tex">x^i y^j</script> is in this product. It is not hard to see that it will be <script type="math/tex">\binom{j}{i}+\binom{j}{i-1}+\dots+\binom{j}{0}</script>. So overall, also with correcting the original offset from <script type="math/tex">i</script> to <script type="math/tex">i-1</script> and <script type="math/tex">j</script> to <script type="math/tex">j-1</script>, we get</p>
<script type="math/tex; mode=display">a_{i,j} = \sum_{k=0}^{i-1}\binom{j-1}{k}.</script>Shantanu MishraHow to approach the following two dimensional recurrence relation ?GSoC’18 log#06: Packing Up2018-08-11T00:00:00+00:002018-08-11T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/08/11/gsoc-log06-packing-up<p>This is GSoC’18 log#06. Here I will cover on what I have done in week #12-13. Link to the <a href="https://8hantanu.me/gsoc18/2018/07/28/gsoc-log05-dynamic-simplification-and-plotting.html" title="GSoC'18 log#05">previous log</a>. The work in these two weeks involved packaging and documenting the code.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<h2 id="done-so-far">Done so far…</h2>
<p>Deciding which packaging style to choose was a difficult task. Though there were a number of options available for packaging python apps I couldn’t find one which makes it simple for packaging it for windows. I managed to convert the source into a single executable file using <strong>pyinstaller</strong> but the performance was compromised.</p>
<p>Finally I went with <strong>PyPI</strong>. A simple <em>setup.py</em> was created which contained information about the dependencies to be installed. Installing <strong>visma</strong> is quite simple now. To install just type:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>pip3 <span class="nb">install </span>VISualMAth
</code></pre></div></div>
<p>And to launch type:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>visma
</code></pre></div></div>
<p>I also modified the <em>run</em> script which can be used by future developers to install, test and package <strong>visma</strong>. Below are the available options in the new <em>run</em> script.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ ./run
Enter command arguments with run
./run install - Install all dependencies for visma
./run visma - Open visma GUI
./run test - Run all the tests and generates coverage report
./run test path/to/test_file.py - Runs all tests and shows coverage for given file
./run test syntax - Run syntax test using pylama
./run test modules - Run tests using pytest for all modules
./run test coverage - After running all the tests, open coverage report
./run pack - Generate builds for visma package
./run pack upload - Generate builds and then upload to test.pypi.org
./run pack final - Generate builds and upload final build to pypi.org
./run clean - Clean all cache, reports and builds
</code></pre></div></div>
<p>The <em>plotter</em> has been divided into two separate tabs i.e. 2D plot and 3D plot. The appropriate tab will be focused while plotting a given input. Also I have embedded the settings menu into the UI instead of creating a pop-up one. The settings contain options to enable/disable UI elements, change font sizes, change plot’s axis ranges and mesh density etc.</p>
<p>Plotting an equation in different axis ranges helps in visualizing it in a better way. The below demo justifies the previous statement.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo6.gif" alt="visma-demo6" class="align-center" /></p>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>The github wiki is yet to be updated. It will contain the user and developer manual. Some more inline comments and docstrings can be added.</p>
<p>Though the GSoC period is coming to an end, there are still a lot of new things I want to implement in <strong>visma</strong>. I am thinking of making <strong>visma</strong> accessible from the terminal itself. A webapp is also on my mind (will implement after adding some more useful features).</p>Shantanu MishraThis is GSoC’18 log#06. Here I will cover on what I have done in week #12-13. Link to the previous log. The work in these two weeks involved packaging and documenting the code.GSoC’18 log#05: Dynamic Simplification and Plotting2018-07-28T00:00:00+00:002018-07-28T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/07/28/gsoc-log05-dynamic-simplification-and-plotting<p>This is GSoC’18 log#05. Here I will cover on what I have done in week #10-11. Link to the <a href="https://8hantanu.me/gsoc18/2018/07/14/gsoc-log04-develop-test-repeat.html" title="GSoC'18 log#04">previous log</a>. The work during this period is mostly done in <a href="https://github.com/aerospaceresearch/visma/blob/master/visma/gui">visma/gui</a>.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<h2 id="done-so-far">Done so far…</h2>
<p>A quick solver (<a href="https://github.com/aerospaceresearch/visma/blob/master/visma/gui/qsolver.py">visma/gui/qsolver.py</a>) has been implemented which dynamically simplifies the expression as the user inputs. Instead of implementing the <em>logger</em> which was supposed to report if the input expression is invalid, I have implemented this feature in the <em>qsolver</em> itself. It lets the user know what is missing in the input or if the input syntax is wrong.</p>
<p>A basic <em>plotter</em> using <strong>matplotlib</strong> was implemented in the first phase which plotted the result in 2D. It is now modified for plotting graphs in both 2D and 3D. The 3D graph is a mesh which resembles the surface of the input. Given the input, <em>plotter</em> decides (based on the number of variables and the type of input) in which dimension is the graph to be plotted.</p>
<p>The <em>plotter</em> logic is:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="n">noOfVars</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">eqType</span> <span class="o">==</span> <span class="s">"expression"</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">noOfVars</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">eqType</span> <span class="o">==</span> <span class="s">"equation"</span><span class="p">):</span>
<span class="n">graphVars</span><span class="p">,</span> <span class="n">func</span> <span class="o">=</span> <span class="n">plotIn2D</span><span class="p">(</span><span class="n">LHStok</span><span class="p">,</span> <span class="n">RHStok</span><span class="p">,</span> <span class="n">variables</span><span class="p">)</span>
<span class="k">elif</span> <span class="p">(</span><span class="n">noOfVars</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">eqType</span> <span class="o">==</span> <span class="s">"expression"</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">noOfVars</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">eqType</span> <span class="o">==</span> <span class="s">"equation"</span><span class="p">):</span>
<span class="n">graphVars</span><span class="p">,</span> <span class="n">func</span> <span class="o">=</span> <span class="n">plotIn3D</span><span class="p">(</span><span class="n">LHStok</span><span class="p">,</span> <span class="n">RHStok</span><span class="p">,</span> <span class="n">variables</span><span class="p">)</span>
</code></pre></div></div>
<p>The above snippet can be found <a href="https://github.com/aerospaceresearch/visma/blob/4476efceddabb7e543332e377062e8d166591844/visma/gui/plotter.py#L22">here</a>.</p>
<p>For example:</p>
<ul>
<li>
<p>If input is <strong>x^2</strong> , the plot <strong>f(x) = x^2</strong> is plotted in 2D.</p>
</li>
<li>
<p>If input is <strong>x^2 + y^2 = 5</strong> , the plot <strong>x^2 + y^2 - 5 = 0</strong> is plotted in 2D.</p>
</li>
<li>
<p>If input is <strong>x^2 - 2*y</strong> , the plot <strong>x^2 - 2y = 0</strong> is plotted in 3D. This case (expression type with 2 variables) needs a fix. A plot for <strong>f(x,y) = x^2 - 2y</strong> must be plotted instead.</p>
</li>
<li>
<p>If input is <strong>x^2/2 + y^2/5 = z</strong> , the plot <strong>0.5x^2 + 0.2y^2/5 - z = 0</strong> is plotted in 3D.</p>
</li>
</ul>
<p>Below the <em>qsolver</em> and <em>plotter</em> can be seen in action.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo5.gif" alt="visma-demo5" class="align-center" /></p>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>Almost all of the basic work related to GUI is finished. I will try to enhance the UI by adding settings menu and options to enable or disable certain UI elements. A simple option for enabling/disabling <em>qsolver</em> has been already added.</p>
<p>In the coming days, I will package <strong>visma</strong> for all desktop operating systems(Linux, Mac, and Windows). I am looking into pyinstaller for packaging <strong>visma</strong> for windows. Also in the final weeks, I will write docstrings and inline comments for the code, and update the github wiki.</p>
<p>Link to <a href="https://github.com/aerospaceresearch/visma" title="visma">project source</a> and <a href="https://github.com/aerospaceresearch/visma/projects/1" title="Project Progress">to-do board</a>.</p>Shantanu MishraThis is GSoC’18 log#05. Here I will cover on what I have done in week #10-11. Link to the previous log. The work during this period is mostly done in visma/gui.GSoC’18 log#04: Develop, Test, Repeat2018-07-14T00:00:00+00:002018-07-14T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/07/14/gsoc-log04-develop-test-repeat<p>This is GSoC log#04 (view log#03 <a href="https://8hantanu.me/gsoc18/2018/06/30/gsoc-log03-finding-the-unknown.html">here</a>). Here I will cover on what I have done in week #08-09 and a gist of what has been accomplished in Phase II coding period and what is to be done in the final coding period.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<h2 id="done-so-far">Done so far…</h2>
<ul>
<li>Added tests using pytest</li>
<li>Code coverage using coverage.py through pytest</li>
<li>Added variable substitution methods</li>
<li>Created an equation solver in multi-variables</li>
<li>Initialized work on matrices</li>
<li>Ported source to Python3 and using PyQt5</li>
</ul>
<p>Variable substitution and matrices will be used to solve multiple equations at once. The matrices will be used for solving multiple linear equations. The variable substitution will be used to solve the rest of the equation types.</p>
<p>Almost all test cases have been added to the tests module. Tests have been integrated to Travis CI. So any new commit/pull request by anyone will go through all test cases’ check.
Checking code-coverage through tests has helped me to see clearly which parts of the code are unused. View <a href="https://coveralls.io/github/8hantanu/visma">code-coverage</a>.</p>
<p>Below is an example dump generated after running tests through pytest.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>pytest
<span class="o">===============================</span> <span class="nb">test </span>session starts <span class="o">================================</span>
platform linux2 <span class="nt">--</span> Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /Projects/GitHub/visma, inifile: setup.cfg
plugins: pylama-7.4.3
collected 25 items
tests/test_calculus.py .. <span class="o">[</span> 8%]
tests/test_functions.py .. <span class="o">[</span> 16%]
tests/test_io.py .... <span class="o">[</span> 32%]
tests/test_matrix.py ....... <span class="o">[</span> 60%]
tests/test_simplify.py ... <span class="o">[</span> 72%]
tests/test_solvers.py .. <span class="o">[</span> 80%]
tests/test_transform.py .. <span class="o">[</span> 88%]
tests/test_utils.py ... <span class="o">[</span>100%]
<span class="o">============================</span> 25 passed <span class="k">in </span>0.93 seconds <span class="o">=============================</span>
</code></pre></div></div>
<h2 id="phase---2-deliverables">Phase - 2 deliverables:</h2>
<ul>
<li><strong>Modules created</strong>:
<ul>
<li><strong>Solver</strong> - An equation solver</li>
<li><strong>Tests</strong> - Added tests for all modules</li>
<li><strong>Matrix</strong> - Support for functions in matrix</li>
<li><strong>Utils</strong> - Simple universal methods</li>
</ul>
</li>
<li><strong>Enhancements</strong>:
<ul>
<li>Ported code base to python3 from python2</li>
<li>Moved to PyQt5 from PyQt4</li>
</ul>
</li>
</ul>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>Most of the time of final period will be spent on working on the missing test cases and integrating the different kinds of solvers and matrices with the GUI. Also, calculus functionalities will be enhanced and support for more functions will be added.</p>
<p>GUI will be enhanced. Logger will be added and plotter will be modified to support equations in multiple variables. Here is a sneak peek of the dynamic simplifier I am working on.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo4.gif" alt="visma-demo4" class="align-center" /></p>
<p>Link to <a href="https://github.com/aerospaceresearch/visma" title="visma">project source</a> and <a href="https://github.com/aerospaceresearch/visma/projects/1" title="Project Progress">to-do board</a>.</p>Shantanu MishraThis is GSoC log#04 (view log#03 here). Here I will cover on what I have done in week #08-09 and a gist of what has been accomplished in Phase II coding period and what is to be done in the final coding period.GSoC’18 log#03: Finding the Unknown2018-06-30T00:00:00+00:002018-05-30T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/06/30/gsoc-log03-finding-the-unknown<p>This is GSoC’18 log#03. Here I will cover on what I have done in week #06-07. Link to the <a href="https://8hantanu.me/gsoc18/2018/06/16/gsoc-log02-integrating-the-integrator.html" title="GSoC'18 log#02">previous log</a>.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<h2 id="done-so-far">Done so far…</h2>
<p>I have implemented a simple solver which is capable of solving a given variable in terms of other variables and numbers. Below is a simple example of how the solver works.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">x</span><span class="o">^</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">-</span> <span class="n">z</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># solving for x
</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span><span class="n">y</span> <span class="o">-</span> <span class="n">z</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># simplified and moved to LHS
</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span><span class="n">y</span> <span class="o">=</span> <span class="n">z</span> <span class="o">+</span> <span class="mi">1</span> <span class="c1"># all functions not containing x moved to RHS
</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span> <span class="o">=</span> <span class="p">(</span><span class="n">z</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">y</span> <span class="c1"># inverse method is called
</span><span class="n">x</span> <span class="o">=</span> <span class="p">((</span><span class="n">z</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">^</span><span class="mf">0.5</span> <span class="c1"># final result
</span></code></pre></div></div>
<p>To make the solver some features like expression operations were required.
Also, support for nested expressions has been added. So when operating with expressions the operations will be worked out from inside-out.</p>
<p>While I was working on expressions, I missed a few trivial test cases. Since the number of functions/operations are increasing the number of test cases is increasing.</p>
<p>Hence I decided to automate testing using unit-test. Since this topic was new to me, I tried using various tests available to find which was best suited for <strong>visma</strong>. I started using <strong>doctest</strong> but later moved on to <strong>pytest</strong> for its number of features. Writing a test through pytest is as simple as:-</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">visma.utils.integers</span> <span class="kn">import</span> <span class="n">gcd</span>
<span class="k">def</span> <span class="nf">test_gcd</span><span class="p">():</span> <span class="c1"># simple test for gcd
</span> <span class="k">assert</span> <span class="n">gcd</span><span class="p">([</span><span class="mi">1</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">gcd</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">24</span><span class="p">])</span> <span class="o">==</span> <span class="mi">3</span>
</code></pre></div></div>
<p>While working on these I learned a lot about unit-tests and code-coverage. I used <strong>coverage.py</strong> through <strong>pytest</strong> to measure code-coverage. It helps to know which part of the code is being neglected and helps find missing test cases.</p>
<p>I fiddled a little with the stylesheets in PyQt4 and made the GUI a little cleaner. Below is the solver in action.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo3.gif" alt="visma-demo3" class="align-center" /></p>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>Since the solver for single equation has been implemented, the next thing will be to extend it to solve multiple equations at once. A variable substitution method will be written which will substitute a variable from one equation to the other equation.</p>
<p>Also for multi-variable linear equations, matrix modules will be created and Gauss-Jordan elimination will be used for solving these. The solver will also be modified to support inequality solving.</p>
<p>Since I have just initialized testing using pytest, there are many test cases left to be written. Tests for specifically each module will be created.</p>
<p>Link to <a href="https://github.com/aerospaceresearch/visma" title="visma">project source</a> and <a href="https://github.com/aerospaceresearch/visma/projects/1" title="Project Progress">to-do board</a>.</p>Shantanu MishraThis is GSoC’18 log#03. Here I will cover on what I have done in week #06-07. Link to the previous log.GSoC’18 log#02: Integrating the Integrator2018-06-16T00:00:00+00:002018-06-16T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/06/16/gsoc-log02-integrating-the-integrator<p>This is GSoC log#02 (view log#01 <a href="https://8hantanu.me/gsoc18/2018/05/26/gsoc-log01-making-visma-classy.html">here</a>). Here I will cover on what I have done in week #03-05 and a gist of what has been accomplished in Phase I coding period.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<h2 id="done-so-far">Done so far…</h2>
<ul>
<li>Created parser.py which handles conversion of tokens to LaTeX or strings and vice-versa.</li>
<li>Some simplification issues were fixed</li>
<li>Integrated the differentiation.py and integration.py to the project along with the step-by-step explanation.</li>
<li>Support for partial differentiation and “partial integration” was added.</li>
<li>The code was again refactored to decrease complexity and remove unused modules.</li>
<li>Added factorize.py module. Can currently factorize polynomials.</li>
</ul>
<p>The differentiation.py works for all functions. The integration.py is a tough one. There are going to be many checks for integration as when to apply by-parts or some another method. I am working on a simpler version of integration by-parts algorithm. For now, VisMa supports basic calculus operations. Also, transform module was added to change from one function type to another.</p>
<p>The below demo shows the newly added functionalities like factorizing polynomials, differentiating and integrating expressions with respect to a variable.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo2.gif" alt="visma-demo" class="align-center" /></p>
<h2 id="phase---1-deliverables">Phase - 1 deliverables:</h2>
<ul>
<li><strong>Modules created</strong>:
<ul>
<li><strong>Functions</strong> - All function classes added</li>
<li><strong>GUI/Plotter</strong> - Graph plotting added</li>
<li><strong>IO</strong> - Input, output parsers</li>
<li><strong>Calculus</strong> - Diff and integrate</li>
</ul>
</li>
<li><strong>Issues fixed</strong>:
<ul>
<li>Refactored code to follow object class style</li>
<li>Rectified equation/expression simplifications</li>
<li>Embedded solver into main GUI</li>
<li>Reorganised code into smaller modules</li>
</ul>
</li>
</ul>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>The next thing which I will work on is a basic equation solver. For making the equation solver modules like factorization, expression multiplication and division are required.</p>
<p>Also as the number of functions are increasing, the cases to test are increasing. I will try to automate testing using unit tests.</p>
<p>Most of the time of phase II period will be spent on working on all kinds of solvers. Also, calculus functionalities will be enhanced and support for more types of functions will be added.</p>
<p>Link to <a href="https://github.com/aerospaceresearch/visma" title="visma">project source</a> and <a href="https://github.com/aerospaceresearch/visma/projects/1" title="Project Progress">to-do board</a>.</p>Shantanu MishraThis is GSoC log#02 (view log#01 here). Here I will cover on what I have done in week #03-05 and a gist of what has been accomplished in Phase I coding period.GSoC’18 log#01: Making VisMa *classy*2018-05-26T00:00:00+00:002018-05-26T07:00:00+00:00https://8hantanu.me/hack%20stack/2018/05/26/gsoc-log01-making-visma-classy<p>I came across <a href="https://aerospaceresearch.net">AerospaceResearch.net</a> when browsing through GSoC organizations. It offered projects both in my field of interests and academic domain. I had to make a hard choice between <strong>DirectDemod</strong> and <strong>VisMa</strong> and I finally chose <strong>VisMa</strong> as my project for GSoC.</p>
<p><img src="https://8hantanu.me/assets/images/vismabanner.jpg" alt="visma-banner" class="align-center" /></p>
<p>This is my first GSoC dev log (more to come). Here I will be logging about what I learned, what I have done and what I will do. So following is the work I have done in VisMa. This log covers on what I have done in week#01-02.</p>
<h2 id="done-so-far">Done so far…</h2>
<p>I used the community bonding period to fix minor errors and get more familiar with the source. I restructured the code base so that new modules could be accommodated. Code duplication was reduced using proper imports between modules. New modules like calculus, transform, solvers, gui etc were initialized. A token IDing module was written to handle equations during calculus operations.</p>
<p>Till now VisMa processed input equations into ‘tokens’ which were formatted in the form of python dictionaries. Erm?! Tokens? Check this out.
The main aim during this two week period was to convert all the dictionaries to class-objects i.e. to follow the object-oriented style. Classes for the following function types were created:</p>
<ul>
<li>trigonometric</li>
<li>hyperbolic</li>
<li>exponential</li>
<li>variable</li>
<li>constant</li>
</ul>
<p>While making these, class methods like ‘differentiate’ and ‘inverse’ were added to these function classes.</p>
<p>While everything worked perfectly with objects, the steps animator didn’t comply. The animator used JSON serializer which would use only strings/dictionary format. Although the object properties could be converted to dictionary format, it would defeat the main purpose. So I decided to use TeX to render equations. The step animator was remolded to render the equations in TeX format using matplotlib’s renderer.</p>
<p>An equation plotter was built with the help of matplotlib. The plotter supports plotting equations in one and two variables. While working on the GUI I learned a lot about PyQT4, a GUI library for python. I have updated the GUI so that the plotter and step-animator are embedded in the main window itself. Here is the new GUI in action.</p>
<p><img src="https://8hantanu.me/assets/images/demos/visma/demo1.gif" alt="visma-demo" class="align-center" /></p>
<h2 id="what-i-will-be-doing-next">What I will be doing next…</h2>
<p>The above example is one of the test cases of the input equations. The animator and plotter have to be fixed to run all cases. Adding animations to the animator is one of the things. I will try to add support for a 3d graph as well(for equations in three variables).</p>
<p>The next thing to do will be integrating the token IDing module. The rules of calculus will be based on this IDing module. The code can be optimized by converting some functions to class methods. Also, some work relating to equation solvers will be initiated.</p>
<p>From now on I will be updating the log on a fortnightly basis (read on <a href="https://aerospaceresearch.net/?p=691">AerospaceResearch.net</a>). The project progress can be viewed here. BTW I added a new VisMa logo.</p>
<p align="center"><b>VisMa, now classy and sassy !!</b>
</p>Shantanu MishraI came across AerospaceResearch.net when browsing through GSoC organizations. It offered projects both in my field of interests and academic domain. I had to make a hard choice between DirectDemod and VisMa and I finally chose VisMa as my project for GSoC.