Coder Social home page Coder Social logo

visma's Introduction

visma - VISual MAth

A math equation solver and visualizer

visma

Build Status Codacy Badge Coveralls Coverage

An equation solver and visualizer, which aims to help in grasping how mathematical equations are transformed and solved. By this the threshold for obtaining deeper mathematical understanding can be reduced.

Installation

PyPI PyPI - Python Version

NOTE: VISualMAth is supported for python3 and above only. The recommended installation method is through pip/pip3.

  • To install do
$ pip3 install visualmath

This sets up the environment to run on your computer.

  • For launching visma do
$ visma
>>> gui
  • For windows user (and those for whom) the above launching option is not available, to launch visma do, from here you will be redirected to VisMa interactive shell, which can be used to open GUI or CLI
$ python3
>>> from visma.main import init
>>> init()
Welcome! This is Visual Maths Interactive Shell...
type 'help' for a User Manual and Ctrl + D to Exit prompt

>>> simplify(2 + x + 11)
INPUT: 2.0 + x + 11.0
OPERATION: simplify
OUTPUT: 13.0 + x

2.0 + x + 11.0

(Adding 11.0 and 2.0)
13.0 + x

>>> 
[5]+  Stopped                 python3

Download:

GitHub release GitHub repo size in bytes

If visma is to be installed locally or for development:

  • Download the source zip and extract.
  • For installing dependencies, from source folder do
$ pip3 install -r requirements.txt
  • For launching do
$ python3 main.py

NOTE: If using pip instead of pip3 for installing, make sure to check if the pip exists in python3 library by checking the pip version.

$ pip --version

Docs

Github Wiki GitHub code size in bytes

For code documentation and learning how to use visma check out the wiki.

Demo

Below are some demos showing visma and its capabilities:

  • GUI visma

  • CLI

To see all features of visma, check this out.

Contribute:

GitHub pull requests GitHub issues Zulip

PRs are welcomed. For contributing to visma refer CONTRIBUTING.md. If there are any issues or ideas they can be addressed through the issues or in chat room.

License:

License: GPL v3

visma is distributed under the GNU GPL-3 or later.

visma's People

Contributors

8hantanu avatar abhishekti7 avatar abishekseshan avatar alii-khaled avatar alpeshjamgade avatar ayush9398 avatar hornig avatar krishnaw14 avatar notimeforcaution avatar pranavvardia avatar pulkitmishra avatar shubhamjain7 avatar sidkothiyal avatar supragya avatar vaishnaviganamukkala avatar vicennial avatar vidhanarya avatar zer-0-ne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

visma's Issues

Visma cannot handle simplifications with multiple parentheses

As stated in Issue #78, it was given that "visma cannot calculate fractional powers", I would like to generalise the problem as visma cannot simplify/calculate equations with multiple parentheses such as (4 + (5 + 4))

(aero) vidhanarya@macbookpro:visma$ python3 main.py
>>> simplify(4^0.571)
INPUT: 2.2038102317532213
OPERATION: simplify
OUTPUT: 2.2038102317532213

2.2038102317532213


>>> simplify(4^(4/7))
Invalid Expression
>>> simplify(4 + 5)
INPUT: 4.0 + 5.0
OPERATION: simplify
OUTPUT: 9.0

4.0 + 5.0

(Adding 5.0 and 4.0)
9.0


>>> simplify(4 + (4 + 1))
Invalid Expression

Here answer to simplify(4^0.571) is same as simplify(4^(4/7)). One possible solution is checking for number of '(' in 'commandExec' function (cli.py) and then recursively simplify from the last parentheses such that,
simplify(4 + (4 + (4 + 1))) is
-> simplify(4 + (4 + 5))
-> simplify(4 + 9)
-> INPUT: 13
OPERATION: simplify
OUTPUT: 9

Crash when I type list

image
image
I'm trying to type equation like 99+(x+2), but when I was trying to type ')' then it crashed.

Tokenize module doesn't recognize `pow` operator in many cases

Problem: Tokenizer module doesn't seem to recognise '^' (power operator) in many cases.

Example: If (x + 1)^2 + 1 is given as input, ideally it should be tokenized as [Expression(x + 1), Binary (^), Constant(2), Binary(+), Constant(1)] or as [Expression(x + 1), Constant(2), Binary(+), Constant(1)] (where pow of Expression has to be 2) but it gets tokenized as [Expression(x + 1), Constant(2), Binary(+), Constant(1)] with power of Expression as 1. Which Ideally should not be there.

Expected Outcome: Such inputs should be tokenized as shown above.

Command line interface

Create a CLI for visma. A query like simplify(x + x = 1 - y) should output as follows:

$ visma
>>> simplify(x + x = 1 - y)
INPUT: x + x = 1 - y
OPERATION: simplify
OUTPUT: 2x - 1 + y = 0
STEPS: 
   x + x = 1 - y
⇒  2x = 1 - y                (Adding x and x)
⇒  2x - 1 + y = 0            (Moving rest of the terms to LHS)
>>> ...

Following a specific io syntax

To do:

  • Set a fixed syntax so there is no ambiguity while giving input.
  • Update the wiki by adding a page for input syntax and rules under User Manual section.
  • Output string (from the tokensToString() method) must also follow this syntax as it can be used again in an input.
  • Changes must be made in io/tokenize.py and io/checks.py accordingly.

Some examples:

  • Giving input as sin x is not allowed. The operand must always be contained in brackets like sin(x).
  • Should x^2y be interpretted as (x^2)*y or x^(2y) ?
  • Coefficient must be given before variables i.e 2xy is accepted xy2 is not.
  • Also use * when multiplying with expressions i.e. 2*(x+y) and (x+y)*(x-y) instead of 2(x+y) and (x+y)(x-y).
  • Always use a number before decimal point. Use 0.1 instead of .1 #113

You can list any examples of ambiguous inputs(or any changes if required to the current syntax) in the comments below.
Note: Some of the above examples might not have been implemented yet. Any examples can be suggested which might be helpful when implementing them in future.

Plot in both 2D and 3D

Todo:

  • Modify gui/plotter.py to plot both 2D/3D plots for some functions. (Fixed by #149 )
  • Add support for single variable equations plots(Ex: x = 1, x^2 = 4).

Example:

x^2 + y^2 = 25 can be plotted in both 2D plot(a circle) and 3D plot(a cylinder). Currently this only plotted in 2D.

This decides the dimension of the plot. Modify gui/plotter.py to plot in both figures.

Replace the simplify modules

To do:

Replace most of the methods (for add, sub, mul, div) in the visma/simplify module with class methods in function classes in visma/functions.

Current implementation:

Go through the methods defined in visma/simplify/*.
For example doing a simple operation like addition of two functions tokens would be something like:

sumTok, _, _, _, _ = simplify([tok1, Binary('+'), tok2])

Here tok1, tok2, sumTok can be the subclasses of visma.functions.structure.Function and, Binary and simplify() are imported from visma.functions.operator and visma.simplify.simplify respectively.

Expected outcome:

The sum token must be simply updated by doing

sumTok = tok1 + tok2

Replace the expressionAddition/Subtraction()(and other related methods) in simplify/addsub.py by adding __add__ and __sub__ class method to the various Function classes. Same goes for simplify/muldiv.py.

The following links might also be helpful:

Note: Please DONT add a wrapper function which can be something like this.

def __add__(self, tok):
    sumTok, _, _, _, _ = simplify([self, Binary('+'), tok2])
    return sumTok

The main intention is to make the whole simplification modular and easy when implementing new function classes.

Extras:

  • The methods in matrix/operations.py can be redefined as class methods of Matrix class.
  • Also expression operations can be redefined in Expression class (#141)

Adding a module for Discrete Mathematics

Objectives:

  • Adding a class to contain discrete maths variables. To be added in visma/structure.py. The discrete maths operations are to be performed on these tokens.
  • Basic modules for AND, OR, NOT etc are to be added.

DeprecationWarning while running pytest

Pytest gives the following warning "DeprecationWarning: invalid escape sequence " on running. Should something be done to handle it or should we ignore it?

Multiple Decimal Points Bug

I think this shouldn't be happening, we shouldn't allow inserting more than one decimal point in each (Constant) instance right ?!
and where should we make an assertion to prevent such input from user ?!
Issue

A parsing module for displaying matrices in LaTex

There is a need to create some module for parsing matrix module in GUI. This can be used in displaying simultaneous equation solvers in GUI (which currently displays the result of determinants of matrices directly).

Power gets subtracted from right value

As shown in below (x-y)^2=10 is converted into x-y-8=0. Power is subtracted from right value-
This issue occur when using braces i.g. (), because this expression (X)^2=10 is simplified as x-8=0.
While This is fine x^2=10.
Screenshot from 2019-04-03 01-08-49

GUI not launching

I am new to visma, installed it using pip3 install visualmath
After installation I tried from visma.main import init but it gives error cannot import name 'init' .
Please help!

"0" is not printed as output on visma.

It has been found that 0 is not printed as output on visma. It also leads to abrupt exit on simplifying for simple computations like 2-2 (or any other which results in zero)
The expected outcome should be to handle this case inside visma and also on the CLI developed.

Parser for Converting Matrix into printable string format

  • Parser for Converting Matrix into the printable string format.
  • A separator parser for displaying for converting Matrix operations in CLI/GUI form (the earlier available parser is designed for equations not involving Matrix operations).

“Add Equation” will cause crash

image
image

When I tried to add an empty file twice, then it will crash. The following are my guess:

the first time it will execute the first if statement and pop the equation[0]. However, when it keeps executing the second if statement, the equation will still be an empty list because of the empty file.
the second time when it executes the first if statement, it will case "index out of range".

The solution I thought was, if the user chooses an empty file then it will cause a warning and stop executing the following statement.

Handling cases with multiple parenthesis and expression simplification

To do:

  • Use Expression class as token for inputs containing multiple parentheses.
  • Simplify the expressions recursively while also updating steps and comments list (#129).

Expected outcome:

  • A bool class property named reduced in the Expression class which specifies if the given expression can be further simplified.
  • If the expression is simplified to a single token change the class type from Expression to appropriate Function class. For ex: (x + 2x) reduces to 3x, change token type from Expression to Variable.
  • If the expression is simplified and still contains multiple tokens after simplification, set the self.reduced to true and update the self.tokens with the simplified tokens list. For ex: (x^2 + x + 2x) simplifies (x^2 + 3x) which is not further reducable, therefore set self.reduced to true.
  • Simplification methods for expression add/sub/mul/div must be defined. Better to define them as class methods in Expression class.
  • Update the steps and its comments at each recursive expression simplification.

Refer the io/tokenize.py, io/simplify.py and functions/structure.py modules.

Edit:
Below is what I mean by

Use Expression class as token for inputs containing multiple parentheses

If input is 1 + 2 * (x + (2x + y)) then

Const   Bin   Const   Bin   Expr                           
└─ 1    └─ +  └─ 2    └─ *  └─ [Var   Bin   Expr]
                                └─ x  └─ +  └─ [Var   Bin   Var ]
                                                └─ 2x └─ +  └─ y

The tokens list is to be stored in tokens property of Expression.

GUI not functioning properly

When I try to run visma gui, it gives following warning and gui also doesn't look as expected -

(aero) vidhanarya@vidhanarya-MacBookPro:~/Desktop/Project/visma$ python3 main.py>>> gui
QLayout: Attempting to add QLayout "" to WorkSpace "", which already has a layout

issue-visma

One possible reason I could think is while building visma from source, I encountered following error

(aero) vidhanarya@vidhanarya-MacBookPro:~/Desktop/Project/visma$ python3 main.pyTraceback (most recent call last):
  File "main.py", line 2, in <module>
    from visma.gui.window import initGUI
  File "/home/vidhanarya/Desktop/Project/visma/visma/gui/window.py", line 15, in <module>
    from PyQt5.QtWebEngineWidgets import QWebEngineView
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'

Which was solved by installing PyQt5==5.8.2 instead of using version 5.12 which was installed after

pip3 install -r requirements.txt

I am using Ubuntu 18.04.2 LTS on MacBook Pro (2017 model)
Also, visma was running fine for me on macOS 10.14 (Although that PyQt5 problem was still there)

getVariables Issue

When getVariables take a sin(x) or any thing like that ( cos(x), tanh(y), ...etc. ) it doesn't regard it as a Variable at all which i think should be handled, right ?!

Adding scroll option for step-by-step solutions which go out of assigned area.

Currently, it has been found that for some algebraic expressions, the step-by-step solution go out of bounds of the assigned area and the steps are not visible.
There is a need to add scroll option for those steps which do not fit in the assigned area, though we have an option for changing font-size.
Here is a sample:

Step-by-Step

LaTeX to Text Parser

To support LaTeX expressions as input, a parser is required which converts LaTeX format to text format which can be handled by visma.

Edit:
The function latexToTerms() is to be modified in visma/io/parser.py to enable conversion of LaTeX expression like
download
whose LaTeX string is

$ 1 + \frac{x}{1-x} + y\left(x-\frac{1}{1-y}\right) + \sin 2x $

to visma acceptable string like

1 + x/(1-x) + y*(x - 1/(1-y)) + sin(2x)

Fix view in steps figure

Set the default position of the horizontal scroll bar to center. See module gui/steps.py.

Current Expected
drawing drawing

Extending support for Functions

To do:

Add tokenize and simplify support for different function classes.

Prereq:

Adding simplification support for the functions would be easier after simplify module is updated (#142)

Expected outcome:

  • Create new Function classes or modify existing ones (trig, exp, log etc)
  • Add support for tokenize and relevant checks for function input syntax
  • Add simplification and plotting support (#118)
  • Add integration and differentiation support for the new functions (#32)

Edit:
Related issues: #118, #158, #160

KeyError: 'back' while passing the command 'gui' in CLI

I just started to work on visma, and I have an issue while trying to initiate the GUI.

What have I done

I ran the main.py, and was prompted to the CLI. Tried giving the command 'gui'.

Outcome

I received the following error

error

Log file record

2019-06-26 06:35 - main - INFO: Initialising VisMa...(currently in CLI mode)
2019-06-26 06:35 - window-gui - INFO: Starting VisMa GUI...
2019-06-26 06:35 - window-gui - INFO: Existing VisMa...

Expected Outcome

Visma GUI window must open.

Other ways I tried

  • Tried to initiate GUI from python interpreter after installing visma using pip3 install visualmath.
  • Tried on virtual environment (venv) and without virtual environment.
  • Tried running main.py from the clone of the repository, version 0.2.2, and source zip.
  • Tried running the main.py from source zip in 2 other machines.

I think I'm on the wrong track somewhere and I can't proceed any further because of this. Can someone please look into this and help me out?

Adding modules for Expression simplification

Problem: Certain expressions like (x+y)^2, (x^2 + xy + 1)*(x + y), (x + y)^3 etc. are not simplified by VisMa.

Solution: The problem can be solved by writing a method expressionSimplification inside the Expression Class. Whenever we get an expression while tokenizing input equation, this function can be called.

Pre-requisites: This would be easier to do once the Simplify modules have been refactored.

Related issues: #142, #141

Duplicate history

duplicate
duplicate2
I just wrote a few equations, but the second time I opened the Visma, there are thousands of duplicated histories. It seems like it will double every time it opens.

GUI Crashes for some input forms.

Like Crashing when using input as : sin(x)* , sinn ...etc.
when just entering this input the gui crashes. even if i mistakenly entered more "n" in sin for example.
Also other issue is that after clicking Simplify it deletes every sin, cos, tan, exp, log, .... etc. from the TextBox in the GUI.
I will focus on solving these issues once i have some time.
If anyone will work on it just tell in the comments, so that we don't invent the wheel. 😂 😂.

UnboundLocalError: local variable 'comments' referenced before assignment

This error occurs after we click the Back button instead of solving any algebraic expression wiith respect to any of the variables x,y or z.
The error throws an UnboundLocalError on the local variable comments in main.py in the given line:

self.output = resultLatex(operation, equationTokens, comments, varName)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.