Giter Site home page Giter Site logo

sympy-live's Introduction

SymPy

pypi version Join the chat at https://gitter.im/sympy/sympy Zenodo Badge Downloads GitHub Issues Git Tutorial Powered by NumFocus Commits since last release

SymPy Banner

See the AUTHORS file for the list of authors.

And many more people helped on the SymPy mailing list, reported bugs, helped organize SymPy's participation in the Google Summer of Code, the Google Highly Open Participation Contest, Google Code-In, wrote and blogged about SymPy...

License: New BSD License (see the LICENSE file for details) covers all files in the sympy repository unless stated otherwise.

Our mailing list is at https://groups.google.com/forum/?fromgroups#!forum/sympy.

We have a community chat at Gitter. Feel free to ask us anything there. We have a very welcoming and helpful community.

Download

The recommended installation method is through Anaconda, https://www.anaconda.com/products/distribution

You can also get the latest version of SymPy from https://pypi.python.org/pypi/sympy/

To get the git version do

$ git clone https://github.com/sympy/sympy.git

For other options (tarballs, debs, etc.), see https://docs.sympy.org/dev/install.html.

Documentation and Usage

For in-depth instructions on installation and building the documentation, see the SymPy Documentation Style Guide.

Everything is at:

https://docs.sympy.org/

You can generate everything at the above site in your local copy of SymPy by:

$ cd doc
$ make html

Then the docs will be in _build/html. If you don't want to read that, here is a short usage:

From this directory, start Python and:

>>> from sympy import Symbol, cos
>>> x = Symbol('x')
>>> e = 1/cos(x)
>>> print(e.series(x, 0, 10))
1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + 277*x**8/8064 + O(x**10)

SymPy also comes with a console that is a simple wrapper around the classic python console (or IPython when available) that loads the SymPy namespace and executes some common commands for you.

To start it, issue:

$ bin/isympy

from this directory, if SymPy is not installed or simply:

$ isympy

if SymPy is installed.

Installation

SymPy has a hard dependency on the mpmath library (version >= 0.19). You should install it first, please refer to the mpmath installation guide:

https://github.com/fredrik-johansson/mpmath#1-download--installation

To install SymPy using PyPI, run the following command:

$ pip install sympy

To install SymPy using Anaconda, run the following command:

$ conda install -c anaconda sympy

To install SymPy from GitHub source, first clone SymPy using git:

$ git clone https://github.com/sympy/sympy.git

Then, in the sympy repository that you cloned, simply run:

$ pip install .

See https://docs.sympy.org/dev/install.html for more information.

Contributing

We welcome contributions from anyone, even if you are new to open source. Please read our Introduction to Contributing page and the SymPy Documentation Style Guide. If you are new and looking for some way to contribute, a good place to start is to look at the issues tagged Easy to Fix.

Please note that all participants in this project are expected to follow our Code of Conduct. By participating in this project you agree to abide by its terms. See CODE_OF_CONDUCT.md.

Tests

To execute all tests, run:

$./setup.py test

in the current directory.

For the more fine-grained running of tests or doctests, use bin/test or respectively bin/doctest. The master branch is automatically tested by GitHub Actions.

To test pull requests, use sympy-bot.

Regenerate Experimental LaTeX Parser/Lexer

The parser and lexer were generated with the ANTLR4 toolchain in sympy/parsing/latex/_antlr and checked into the repo. Presently, most users should not need to regenerate these files, but if you plan to work on this feature, you will need the antlr4 command-line tool (and you must ensure that it is in your PATH). One way to get it is:

$ conda install -c conda-forge antlr=4.11.1

Alternatively, follow the instructions on the ANTLR website and download the antlr-4.11.1-complete.jar. Then export the CLASSPATH as instructed and instead of creating antlr4 as an alias, make it an executable file with the following contents:

#!/bin/bash
java -jar /usr/local/lib/antlr-4.11.1-complete.jar "$@"

After making changes to sympy/parsing/latex/LaTeX.g4, run:

$ ./setup.py antlr

Clean

To clean everything (thus getting the same tree as in the repository):

$ git clean -Xdf

which will clear everything ignored by .gitignore, and:

$ git clean -df

to clear all untracked files. You can revert the most recent changes in git with:

$ git reset --hard

WARNING: The above commands will all clear changes you may have made, and you will lose them forever. Be sure to check things with git status, git diff, git clean -Xn, and git clean -n before doing any of those.

Bugs

Our issue tracker is at https://github.com/sympy/sympy/issues. Please report any bugs that you find. Or, even better, fork the repository on GitHub and create a pull request. We welcome all changes, big or small, and we will help you make the pull request if you are new to git (just ask on our mailing list or Gitter Channel). If you further have any queries, you can find answers on Stack Overflow using the sympy tag.

Brief History

SymPy was started by Ondřej Čertík in 2005, he wrote some code during the summer, then he wrote some more code during summer 2006. In February 2007, Fabian Pedregosa joined the project and helped fix many things, contributed documentation, and made it alive again. 5 students (Mateusz Paprocki, Brian Jorgensen, Jason Gedge, Robert Schwarz, and Chris Wu) improved SymPy incredibly during summer 2007 as part of the Google Summer of Code. Pearu Peterson joined the development during the summer 2007 and he has made SymPy much more competitive by rewriting the core from scratch, which has made it from 10x to 100x faster. Jurjen N.E. Bos has contributed pretty-printing and other patches. Fredrik Johansson has written mpmath and contributed a lot of patches.

SymPy has participated in every Google Summer of Code since 2007. You can see https://github.com/sympy/sympy/wiki#google-summer-of-code for full details. Each year has improved SymPy by bounds. Most of SymPy's development has come from Google Summer of Code students.

In 2011, Ondřej Čertík stepped down as lead developer, with Aaron Meurer, who also started as a Google Summer of Code student, taking his place. Ondřej Čertík is still active in the community but is too busy with work and family to play a lead development role.

Since then, a lot more people have joined the development and some people have also left. You can see the full list in doc/src/aboutus.rst, or online at:

https://docs.sympy.org/dev/aboutus.html#sympy-development-team

The git history goes back to 2007 when development moved from svn to hg. To see the history before that point, look at https://github.com/sympy/sympy-old.

You can use git to see the biggest developers. The command:

$ git shortlog -ns

will show each developer, sorted by commits to the project. The command:

$ git shortlog -ns --since="1 year"

will show the top developers from the last year.

Citation

To cite SymPy in publications use

Meurer A, Smith CP, Paprocki M, Čertík O, Kirpichev SB, Rocklin M, Kumar A, Ivanov S, Moore JK, Singh S, Rathnayake T, Vig S, Granger BE, Muller RP, Bonazzi F, Gupta H, Vats S, Johansson F, Pedregosa F, Curry MJ, Terrel AR, Roučka Š, Saboo A, Fernando I, Kulal S, Cimrman R, Scopatz A. (2017) SymPy: symbolic computing in Python. PeerJ Computer Science 3:e103 https://doi.org/10.7717/peerj-cs.103

A BibTeX entry for LaTeX users is

@article{10.7717/peerj-cs.103,
 title = {SymPy: symbolic computing in Python},
 author = {Meurer, Aaron and Smith, Christopher P. and Paprocki, Mateusz and \v{C}ert\'{i}k, Ond\v{r}ej and Kirpichev, Sergey B. and Rocklin, Matthew and Kumar, Amit and Ivanov, Sergiu and Moore, Jason K. and Singh, Sartaj and Rathnayake, Thilina and Vig, Sean and Granger, Brian E. and Muller, Richard P. and Bonazzi, Francesco and Gupta, Harsh and Vats, Shivam and Johansson, Fredrik and Pedregosa, Fabian and Curry, Matthew J. and Terrel, Andy R. and Rou\v{c}ka, \v{S}t\v{e}p\'{a}n and Saboo, Ashutosh and Fernando, Isuru and Kulal, Sumith and Cimrman, Robert and Scopatz, Anthony},
 year = 2017,
 month = Jan,
 keywords = {Python, Computer algebra system, Symbolics},
 abstract = {
            SymPy is an open-source computer algebra system written in pure Python. It is built with a focus on extensibility and ease of use, through both interactive and programmatic applications. These characteristics have led SymPy to become a popular symbolic library for the scientific Python ecosystem. This paper presents the architecture of SymPy, a description of its features, and a discussion of select submodules. The supplementary material provides additional examples and further outlines details of the architecture and features of SymPy.
         },
 volume = 3,
 pages = {e103},
 journal = {PeerJ Computer Science},
 issn = {2376-5992},
 url = {https://doi.org/10.7717/peerj-cs.103},
 doi = {10.7717/peerj-cs.103}
}

SymPy is BSD licensed, so you are free to use it whatever you like, be it academic, commercial, creating forks or derivatives, as long as you copy the BSD statement if you redistribute it (see the LICENSE file for details). That said, although not required by the SymPy license, if it is convenient for you, please cite SymPy when using it in your work and also consider contributing all your changes back, so that we can incorporate it and all of us will benefit in the end.

sympy-live's People

Contributors

aktech avatar asmeurer avatar certik avatar davidar avatar donno2048 avatar gswirski avatar gxyd avatar jtoka avatar krastanov avatar leonelhs avatar lidavidm avatar mateuszkmiecik avatar mattpap avatar normalhuman avatar oscarbenjamin avatar prshnt19 avatar steveanton avatar trishume avatar vks avatar yardstick17 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  avatar

Watchers

 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

sympy-live's Issues

Make the copyright year dynamic

Currently the copyright year is set to 2013, it would better to have a dynamic copyright year, something like: 2013-<current_year>, so that we don't have to update it every year.

dir returns unrendered TeX

Sorry if this is the wrong place to report this issue (Might be MathJax?), but running dir() on something (e.g. '') makes it show plain, unrendered, TeX.

dir('')
\begin{equation_}\begin{bmatrix}add, & class, & contains, & delattr, & doc, & eq, & format, & ge, & getattribute, & getitem, & getnewargs, & getslice, & gt, & hash, & init, & le, & len, & lt, & mod, & mul, & ne, & new, & reduce, & reduce_ex, & repr, & rmod, & rmul, & setattr, & sizeof, & str, & subclasshook, & _formatter_field_name_split, & formatter_parser, & capitalize, & center, & count, & decode, & encode, & endswith, & expandtabs, & find, & format, & index, & isalnum, & isalpha, & isdigit, & islower, & isspace, & istitle, & isupper, & join, & ljust, & lower, & lstrip, & partition, & replace, & rfind, & rindex, & rjust, & rpartition, & rsplit, & rstrip, & split, & splitlines, & startswith, & strip, & swapcase, & title, & translate, & upper, & zfill\end{bmatrix}\end{equation}

Non-commutative multiply triggers inappropriate substitutions

I was playing around with sympy a bit, but almost immediately ran into trouble. Even though I think it's a nice tool, I ran into this too fast to trust it :(

In sympy live I enter:

a, b,c = symbols('a b c', commutative=False)

and I try two operations (x, y are is a symbol in sympy live):

>>> expand((a*(x*b*c+c*b*a)*y)).subs([(b*c,-a),(a*a,-1),(c*b,a)])
         3
x*y + y*a 
>>> expand((a*(x*b*c+c*b*a)*y)).subs([(b*c,-a),(a*a,-1),(c*b,a)]).subs([(b*c,-a),(a*a,-1),(c*b,a)])
x*y - I*y

Note how the imaginary unit appears out of nowhere when the substitution is applied twice. I.e. a**3 is replaced by the imaginary unit.

I think the bug in the implementation is that it infers from a*a == -1 that a == I. This is not correct because the multiplication rules for non-commutative objects are not complex numbers. To quote a familiar example, quaternions have i*i == -1, and j*j == -1 but j is very different from i.

I see how one could work around this by defining a special symbol 'minusOne' together with a very carefully assembled set of substitution rules that mimic multiplication by a scalar, but is that the intended use?

Is there a way to link few lines of code to be executed on sympy live?

I would like to share a code snippet to be executed on sympy live. I can share the code directly and ask the receiver to open sympy live and copy-paste it to see the result. Alternatively, is there a way to just send a link which opens sympy live and executes the attached code snippet?

I'm aware that I can run a query in sympy gamma and share it. But I need to share a few lines of actual sympy code that need to be executed in a consistent manner.

New Voice Commands Feature in Sympy-live

I was thinking of implementing a voice based commands in the feed section as it is difficult to type the expressions, we can use some speech API for that sake
is it good to work on please tell me

Unicode Exception thrown in SymPy Live

After copy&pasting the following lines from this stackexchange question

from sympy import *
x = Symbol("x")
pprint(Integral(sqrt(1/x), x)) 

the following exception is thrown:

Exception in SymPy Live of type 
<type 'exceptions.UnicodeEncodeError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/shell.py", line 763, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/shell.py", line 380, in evaluate
    exec code in statement_module.__dict__
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/sympy/sympy/printing/pretty/pretty.py", line 1825, in pretty_print
    print(pretty(expr, **settings))
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/request_environment.py", line 93, in write
    self._request.errors.write(data)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2320' in position 0: ordinal not in range(128)

On first entry of the above lines, the output is an "ugly" ascii version of the integral, similar as in the stackexchange question. When using the arrow key to re-enter the same line again, or entering anything else, the above exception is thrown.

Problem with solve

I ran into a strange case where solve doesn't return an answer

x_i, y_i = (1.04, 0.0911)
v_xi, v_yi = (4.42, 0.778)
y = -9.8/2*t**2 + v_yi*t + y_i
y
# -4.9*t**2 + 0.778*t + 0.0911

y.diff(t)
# -9.8*t + 0.778

solve( y.diff(t), t)
# expected:  [0.079]   but outputs   [] 

# workaround
solve( y.diff(t).subs({t:z}), z)
[0.0793877551020408]

http://live.sympy.org/?evaluate=x_i%2C%20y_i%20%3D%20(1.04%2C%200.0911)%0A%23--%0Av_xi%2C%20v_yi%20%3D%20(4.42%2C%200.778)%0A%23--%0Ay%20%3D%20-9.8%2F2*t**2%20%2B%20v_yi*t%20%2B%20y_i%0A%23--%0Ay%0A%23--%0Ay.diff(t)%0A%23--%0A%23%20expected%3A%20%20%5B0.079%5D%20%20%20but%20outputs%20%20%20%5B%5D%0Asolve(%20y.diff(t)%2C%20t)%0A%23--%0A%23%20workaround%0Asolve(%20y.diff(t).subs(%7Bt%3Az%7D)%2C%20z)%0A%23--%0A

Not sure what could be behind this. I can confirm it works fine on the command line.

Cannot import autowrap on sympy live

>>> from sympy.utilities.autowrap import autowrap
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/sympy/sympy/utilities/autowrap.py", line 76, in <module>
    from subprocess import STDOUT, CalledProcessError
ImportError: cannot import name STDOUT

Sphinx extension: cannot copy code

If you try to select and copy code in the Sphinx extension, it just runs the code, and deselects it. The only way to do it is to copy the code that gets run in the live shell.

Error in __sympifyit_wrapper when entering fractions

In the latest live shell backed by SymPy 1.5.1, trying to input a fraction expression like

>>> 1/x

clickable

results in an error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/numbers.py", line 1765, in __div__
    return Number.__div__(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/numbers.py", line 766, in __div__
    return AtomicExpr.__div__(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/decorators.py", line 129, in binary_op_wrapper
    return func(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/expr.py", line 233, in __div__
    return Mul(self, Pow(other, S.NegativeOne))
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/cache.py", line 94, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/compatibility.py", line 916, in wrapper
    del cache[oldkey]

KeyError: [<class 'sympy.core.mul.Mul'>, 1, 1/x, <class 'sympy.core.assumptions.ManagedProperties'>, <class 'sympy.core.numbers.One'>, <class 'sympy.core.power.Pow'>]

Works fine in local installation. Normally I would suspect, int_to_Integer but some basic local testing failed to reproduce.

Not sure when __sympifyit_wrapper gets called in the web shell.

This commit might be relevant this commit since it touches __sympifyit, but not sure if it has landed in 1.5.1: sympy/sympy@da1d85b

SymPy Live giving errors

Whenever you evaluate something it says Error: .. Here is an example traceback from the logs

(/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:291)
Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 273, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7cb976f64e72c78c/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/shell.py", line 771, in post
    live.evaluate(PREEXEC, session)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/shell.py", line 453, in evaluate
    if name not in old_globals or val != old_globals[name]:
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/basic.py", line 352, in __ne__
    return not self == other
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/sets/fancysets.py", line 1110, in __eq__
    return other == ComplexRegion(S.Reals*S.Reals)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/sets/fancysets.py", line 856, in __new__
    obj = ImageSet.__new__(cls, Lambda((x, y), x + I*y), sets)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/decorators.py", line 129, in binary_op_wrapper
    return func(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/expr.py", line 151, in __mul__
    return Mul(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/cache.py", line 94, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/base/data/home/apps/s~sympy-live-hrd/57.417397408462217066/sympy/sympy/core/compatibility.py", line 908, in wrapper
    del cache[oldkey]
KeyError: [<class 'sympy.core.mul.Mul'>, I, _y, <class 'sympy.core.assumptions.ManagedProperties'>, <class 'sympy.core.numbers.ImaginaryUnit'>, <class 'sympy.core.symbol.Dummy'>]

Keep location in docs

When you click on an example in the docs that opens the live shell, it causes the docs to scroll so that the example is no longer on the screen. Is it possible to prevent, or at least reduce this?

Exception in SymPy Live

import numpy # doctest:+SKIP
a = numpy.arange(10) # doctest:+SKIP
expr = sin(x)
f = lambdify(x, expr, "numpy") # doctest:+SKIP
f(a) # doctest:+SKIP

Exception in SymPy Live of type
<type 'exceptions.ValueError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
File "/base/data/home/apps/ssympy-live-hrd/56.412575950366508090/shell.py", line 781, in post
live.evaluate(statement, session, printer, stream)
File "/base/data/home/apps/s
sympy-live-hrd/56.412575950366508090/shell.py", line 453, in evaluate
if name not in old_globals or val != old_globals[name]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

f = lambdify(x, expr, "numpy") # doctest:+SKIP
Exception in SymPy Live of type
<type 'exceptions.ValueError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
File "/base/data/home/apps/ssympy-live-hrd/56.412575950366508090/shell.py", line 781, in post
live.evaluate(statement, session, printer, stream)
File "/base/data/home/apps/s
sympy-live-hrd/56.412575950366508090/shell.py", line 453, in evaluate
if name not in old_globals or val != old_globals[name]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
f(a) # doctest:+SKIP
Exception in SymPy Live of type
<type 'exceptions.ValueError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
File "/base/data/home/apps/ssympy-live-hrd/56.412575950366508090/shell.py", line 781, in post
live.evaluate(statement, session, printer, stream)
File "/base/data/home/apps/s
sympy-live-hrd/56.412575950366508090/shell.py", line 453, in evaluate
if name not in old_globals or val != old_globals[name]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
link:https://docs.sympy.org/latest/tutorial/basic_operations.html#lambdify

Trying to assign Matrix expressions to N or Q fails

While browsing this page in the docs, I saw that trying to assign a Matrix object to N fails.

clickable

>>> M = Matrix([0, 0, 1])  # works
>>> N = Matrix([0, 1, 1])  # fails
Exception in SymPy Live of type 
<class 'sympy.core.sympify.SympifyError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 781, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 453, in evaluate
    if name not in old_globals or val != old_globals[name]:
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/matrices.py", line 2360, in __ne__
    return not self == other
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/dense.py", line 47, in __eq__
    other = sympify(other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/sympify.py", line 387, in sympify
    raise SympifyError('could not parse %r' % a, exc)
SympifyError: Sympify of expression 'could not parse u'<function N at 0x3e1746e06668>'' failed, because of exception being raised:
SyntaxError: invalid syntax (<string>, line 1)

Interestingly if you try to assign something simpler like 2 or 2*x it works:

>>> N = 2
>>> N
2

and also after the initial assignment, you can assign the Matrix expression to N w/o a problem:

>>> N = Matrix([0, 1, 1])  # now it works

So it seems there is some issue only when parsing the initial assignment statement N = Matrix([0, 1, 1]) when N is the builtin function.

Further testing

I tried some of the other one-letter builtins and these work fine:

>>> C = Matrix([0, 1, 1])  # ok
... O = Matrix([0, 1, 1])  # ok
... S = Matrix([0, 1, 1])  # ok
... I = Matrix([0, 1, 1])  # ok
... E = Matrix([0, 1, 1])  # ok

But Q fails the same way as N:

>>> Q = Matrix([0, 1, 1])  # fails
Exception in SymPy Live of type 
<class 'sympy.core.sympify.SympifyError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 781, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 453, in evaluate
    if name not in old_globals or val != old_globals[name]:
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/matrices.py", line 2360, in __ne__
    return not self == other
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/dense.py", line 47, in __eq__
    other = sympify(other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/sympify.py", line 387, in sympify
    raise SympifyError('could not parse %r' % a, exc)
SympifyError: Sympify of expression 'could not parse u'<sympy.assumptions.ask.AssumptionKeys object at 0x3e1746cabfd0>'' failed, because of exception being raised:
SyntaxError: invalid syntax (<string>, line 1)

Even more weirdness

Trying to define a regular Python function called N when N is currently defined as a Matrix fails:

clickable

>>> N = 2                      # workaround to make the next line work
>>> N = Matrix([0, 1, 1])      # works since N=2 just before
>>> N0⎤
⎢1⎥
⎣1>>> def N(x):                  # fails
...     return 42
Exception in SymPy Live of type 
<class 'sympy.core.sympify.SympifyError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 781, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/shell.py", line 453, in evaluate
    if name not in old_globals or val != old_globals[name]:
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/matrices.py", line 2360, in __ne__
    return not self == other
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/matrices/dense.py", line 47, in __eq__
    other = sympify(other)
  File "/base/data/home/apps/s~sympy-live-hrd/20200105t193609.423659059328302322/sympy/sympy/core/sympify.py", line 387, in sympify
    raise SympifyError('could not parse %r' % a, exc)
SympifyError: Sympify of expression 'could not parse u'<function N at 0x3e25e073fb90>'' failed, because of exception being raised:
SyntaxError: invalid syntax (<string>, line 1)

When N is a regular int, defining a function works of course

>>> N = 2                      # works
>>> N
2
>>> def N(x):                  # works too
...     return 42
>>> N
<function N at 0x3e25e0741aa0>

Summary

It seems some part of the live shell wrapper logic is trying to parse inputs and simpify them, which works in general, but is causing bad interactions when either the left or the right side of assignment statements are Matrix objects.

Python in the browser as a solution to pickling

Pickling is a problem for SymPy Live as it can lead to strange errors (not everything is picklable); running Python in the browser could avoid this. There are three options here:

  • CPython via Native Client
    • Pros: full CPython
    • Cons: Chrome only, large size
  • CPython via Emscripten
    • Pros: full CPython
    • Cons: slower than CPython, large size, seems to hang/crash browsers (when I tried)
  • PyPy via PyPy.js
    • Pros: relatively small (only 32MB JavaScript)
    • Cons: relatively new, buggy (import random leads to an error)

I'm leaving this here mostly to record ideas/options.

Capital C can't be used as variable name

I tried the following in SymPy Live

C = 3

and it gave me the following error message:

Exception in SymPy Live of type <type 'exceptions.NameError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/50.411508059631415177/shell.py", line 781, in post live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/50.411508059631415177/shell.py", line 453, in evaluate if name not in old_globals or val != old_globals[name]:
  File "/base/data/home/apps/s~sympy-live-hrd/50.411508059631415177/sympy/sympy/core/numbers.py", line 2167, in __ne__ return not self == other
  File "/base/data/home/apps/s~sympy-live-hrd/50.411508059631415177/sympy/sympy/core/numbers.py", line 2164, in __eq__ return Rational.__eq__(self, other)
  File "/base/data/home/apps/s~sympy-live-hrd/50.411508059631415177/sympy/sympy/core/numbers.py", line 1747, in __eq__ other = _sympify(other)
NameError: name 'C' is not defined as a Symbol

Provide live-shell versions in sync with the sympy documentation

Right now, we have latest=0.7.5, but the "show sympy live shell" link on
http://docs.sympy.org/latest/index.html show the 0.7.4.1 version of the sympy. Same displayed for other versions of the documentation. This could confuse our users, e.g. #8012.

I think, we should either disable live shells for "wrong" versions of docs (e.g. keep "show live" link only for the latest version) or we can provide different versions of sympy in live instances ("show live" must point to the live instance with the correct version number).

Over quota error

The website, live.sympy.org is facing denial of service attack from a past few days.
I think we need to increase the upper limit on the number of requests for the website. Or a protection is needed against such attacks.
IMG_20191119_112953

Update SymPy

Is there any reason SymPy hasn't been updated to 0.7.5?

"Make a URL" link results in 404

Enter something in the interactive shell, i.e. "5+5" and press Enter. The result (10) is shown. Click the push pin symbol ("Make a link that evaluates the session history") and click "Make Link" in the following popup.

You will be redirected to a 404: http://live.sympy.org/undefined/?evaluate=5%2B5%0A%23--%0A

Removing the "undefined/" in the URL makes everything work as expected. I don't have an account but suspect this has something to do with non-logged-in users ("undefined" user)?

Show "init_printing" as one of the commands that were run

People can get confused as to how the printing works in SymPy Live and not in a regular shell. I think it should show init_printing() as one of the commands that are run.

It should also probably show this in SymPy's init_session.

Error when run on documentation

When running the first code block on http://docs.sympy.org/latest/modules/combinatorics/fp_groups.html, this error occurs:

>>> from sympy.combinatorics.free_groups import free_group, vfree_group, xfree_group
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named free_groups
>>> from sympy.combinatorics.fp_groups import FpGroup, CosetTable, coset_enumeration_r
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named fp_groups

Bug with Sphinx extension in tutorial

At http://docs.sympy.org/latest/tutorial/basic_operations.html, if you run the block

>>> str_expr = "x**2 + 3*x - 1/2"
>>> expr = sympify(str_expr)
>>> expr
x**2 + 3*x - 1/2
>>> expr.subs(x, 2)
19/2

It runs as

>>> expr = sympify(str_expr)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'str_expr' is not defined
>>> expr
sin(x)
>>> expr.subs(x, 2)
sin(2)

and if you run

>>> import numpy 
>>> a = numpy.arange(10) 
>>> expr = sin(x)
>>> f = lambdify(x, expr, "numpy") 
>>> f(a) 
[ 0.          0.84147098  0.90929743  0.14112001 -0.7568025  -0.95892427
 -0.2794155   0.6569866   0.98935825  0.41211849]

it runs as

>>> a = numpy.arange(10)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'numpy' is not defined
>>> expr = sin(x)
>>> f = lambdify(x, expr, "numpy")
>>> f(a)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

It's not running the first line for some reason.

Command starting with space crashes with UnboundLocalError

Entering 2+2 (2+2 prefixed by a space) results in:

Exception in SymPy Live of type  <type 'exceptions.UnboundLocalError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/b/d/h/a/s~sympy-live-hrd/46.39/shell.py", line 774, in post
    live.evaluate(statement, session, printer, stream)
  File "/b/d/h/a/s~sympy-live-hrd/46.39/shell.py", line 341, in evaluate
    return self.error(stream, self.syntaxerror())
  File "/b/d/h/a/s~sympy-live-hrd/46.39/shell.py", line 252, in syntaxerror
    return ''.join(text), line
UnboundLocalError: local variable 'line' referenced before assignment

adding some new features

hey,i was thinking of adding some new features to sympy live like a counter or dashboard to show how many current online users using the shell,on which devices are they using(ios,android,windows etc..) and from which country are they from.
if you think they are useful ,let me know i will start working on it..

ValueError: The truth value of an array

From Docs Basic_operations.html
In lambdify example:

Python console for SymPy 1.0 (Python 2.7.5)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)

>>> import numpy
>>> a = numpy.arange(10)
>>> expr = sin(x)
Exception in SymPy Live of type 
<type 'exceptions.ValueError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/shell.py", line 781, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/shell.py", line 453, in evaluate
    if name not in old_globals or val != old_globals[name]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> f = lambdify(x, expr, "numpy")
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/utilities/lambdify.py", line 387, in lambdify
    func = eval(lstr, namespace)
  File "<string>", line 1
    lambda _Dummy_797: (<module 'sympy.core.expr' from '/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/expr.pyc'>)
                        ^
SyntaxError: invalid syntax
>>> f(a)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/function.py", line 720, in __new__
    obj = super(AppliedUndef, cls).__new__(cls, *args, **options)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/cache.py", line 93, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/compatibility.py", line 884, in wrapper
    return user_function(*args, **kwds)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/function.py", line 389, in __new__
    pr = max(cls._should_evalf(a) for a in result.args)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/function.py", line 389, in <genexpr>
    pr = max(cls._should_evalf(a) for a in result.args)
  File "/base/data/home/apps/s~sympy-live-hrd/49.400254913747479351/sympy/sympy/core/function.py", line 407, in _should_evalf
    if arg.is_Float:
AttributeError: 'numpy.ndarray' object has no attribute 'is_Float'

BadRequestError

For
M = Matrix(8, 8, [x+i for i in range (64)]) sympy live gives this error

BadRequestError: The value of property "globals" is longer than 1048487 bytes.

I tried in my system it works fine but in sympy live it gives error.

M.rref() also gives Unable to process statement due to its excessive size. error

git submodule update fails

>>> git submodule update
Cloning into 'static'...
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Clone of '[email protected]:sympy/sympy-web-static.git' into submodule path 'static' failed

works for me when changing in .git/config

[submodule "static"]
    url = https://github.com/sympy/sympy-web-static.git

More problems with solve

Running:

>>> solve(x-3,x)

produces results in an error AttributeError: 'Not' object has no attribute 'canonical'. The full stack trace is:

Traceback (most recent call last): File "<string>", line 1, in <module>
File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/solvers/solvers.py", line 889, in solve piece = Lambda(w, Piecewise((w, Ge(w, 0)), (-w, True)))
File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/functions/elementary/piecewise.py", line 110, in __new__ r = cls.eval(*newargs)
File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/functions/elementary/piecewise.py", line 128, in eval or1 = Or(*[cond for (_, cond) in args if cond != true])
File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/core/operations.py", line 410, in __new__ _args = frozenset(cls._new_args_filter(args))
File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/logic/boolalg.py", line 424, in _new_args_filter nc = (~c).canonical AttributeError: 'Not' object has no attribute 'canonical'

Was there some new version of SymPy pushed to app-engine? When is 46.393464279709602171 from?

latex rendering infinite recusion during Matrix display

I ran into a weird latex display bug. To reproduce try running this on http://live.sympy.org

 Matrix([[1/sqrt(2),  1/sqrt(6), -1/sqrt(3)]])

It goes into a recusive loop and then spits out a long stacktrace:

Traceback (most recent call last):
File "/b/d/h/a/s~sympy-live-hrd/46.393.../shell.py", line 373, in displayhook print stringify_func(arg)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../shell.py", line 81, in <lambda> 'latex': lambda arg: latex(arg, mode="equation*"),
...hundreds of lines...
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/latex.py", line 368, in _print_Mul tex += convert(expr)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/latex.py", line 348, in convert term_tex = self._print(term)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/printer.py", line 257, in _print return getattr(self, printmethod)(expr, *args, **kwargs)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/latex.py", line 368, in _print_Mul tex += convert(expr)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/latex.py", line 348, in convert term_tex = self._print(term)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/printer.py", line 257, in _print return getattr(self, printmethod)(expr, *args, **kwargs)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/printing/latex.py", line 326, in _print_Mul expr = -expr
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/core/expr.py", line 112, in __neg__ return Mul(S.NegativeOne, self)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/core/cache.py", line 93, in wrapper retval = cfunc(*args, **kwargs)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/core/compatibility.py", line 881, in wrapper key = make_key(args, kwds, typed) if kwds or typed else args
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/core/compatibility.py", line 813, in _make_key return _HashedSeq(key)
File "/b/d/h/a/s~sympy-live-hrd/46.393.../sympy/sympy/core/compatibility.py", line 791, in __init__ self.hashvalue = hash(tup)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Let me know if I can help fix this somehow.

Fix loading of static files while developing locally

Currently static files are not loaded properly, when running the dev server locally, as the application version comes out to be None and the generated static files url becomes:

http://localhost:8080/static-None/..

While the regex for static files is following:
/static-[0-9a-z]+/(.*)

UnboundLocalError: local variable 'line' referenced before assignment

>>>  simplify(exp(x)/exp(x - 1))
Exception in SymPy Live of type 
<type 'exceptions.UnboundLocalError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/shell.py", line 763, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/shell.py", line 330, in evaluate
    return self.error(stream, self.syntaxerror())
  File "/base/data/home/apps/s~sympy-live-hrd/43.373169527249054993/shell.py", line 241, in syntaxerror
    return ''.join(text), line
UnboundLocalError: local variable 'line' referenced before assignment

Notice the extra space before the input.

Syntax highlighting and recognition of code snippets

Some places code syntax highlighting is not picked up and code is not runnable with SymPy Live. The syntax highlighting might be traced back to whether or not a space is used before a double colon when declaring code blocks as can be seen on this page. Other places SymPy Live recognizes code blocks unless it is only a single line of code which are not "runable" as can be seen on this page

Two binary numbers returning the same gray code?

Can someone please explain the following?

from sympy.combinatorics.graycode import gray_to_bin,bin_to_gray
bin_to_gray('000000000000001111100111')
'000000000000000110010110'
bin_to_gray('000000000000001111100110')
'000000000000000110010110'

Docs live box stays open

When you open the live box in the docs, it stays open on all new pages, even if you close it.

LaTeX parser has antlr dependency

As LaTeX parser requires antlr-python-runtime, the following code block from the docstring throws an error:

    >>> from sympy.parsing.latex import parse_latex  # doctest: +SKIP
    >>> expr = parse_latex(r"\frac {1 + \sqrt {\a}} {\b}")  # doctest: +SKIP
    >>> expr  # doctest: +SKIP
    (sqrt(a) + 1)/b
    >>> expr.evalf(4, subs=dict(a=5, b=2))  # doctest: +SKIP
    1.618

with the following traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/56.412575950366508090/sympy/sympy/parsing/latex/__init__.py", line 31, in parse_latex
    return _latex.parse_latex(s)
  File "/base/data/home/apps/s~sympy-live-hrd/56.412575950366508090/sympy/sympy/parsing/latex/_parse_latex_antlr.py", line 66, in parse_latex
    raise ImportError("LaTeX parsing requires the antlr4 python package,"
ImportError: LaTeX parsing requires the antlr4 python package, provided by pip (antlr4-python2-runtime or antlr4-python3-runtime) or conda (antlr-python-runtime)

Implement automated testing using Selenium

Currently we don't have any tests, it will be great to have some automated tests that would test some basic functionality, like say page title is loaded, sidebar is loaded, input/output is working, etc.

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.