SymPy Android app

527 views
Skip to first unread message

David Li

unread,
Mar 21, 2013, 10:00:49 PM3/21/13
to sy...@googlegroups.com
I don't know if any of the developers are aware of this (it's not mentioned on this mailing list), but it looks like someone's made an Android app using SymPy:

(developer says it uses SymPy at https://www.vertinode.nl/projects)

The visual design of the app is really nice. It also gives "hints" on how to perform operations like differentiation, though it seems to only be able to give one step (and for sin(x) it says to use the chain rule?). It's limited compared to Gamma, but has a nice keyboard and is very smooth. Unfortunately it uses a server to perform actual computations. None of it seems to be open-source, either. I'm not sure what it uses for math rendering either.

Aaron Meurer

unread,
Mar 21, 2013, 10:23:27 PM3/21/13
to sy...@googlegroups.com
Actually there are a handful of apps both on Android and iOS (and also
some of the other ones) using SymPy. We should start a wiki page
listing them all.

I don't have an Android phone, and BlueStacks doesn't seem to support
OAuth Google sign-in, so I can't test this. Any idea what SymPy
version it is using?

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

David Li

unread,
Mar 22, 2013, 9:45:55 AM3/22/13
to sy...@googlegroups.com

Nope, it isn't stated anywhere in the app or on the website.

You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/So8awjcpQq8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.

Aaron Meurer

unread,
Mar 22, 2013, 1:00:57 PM3/22/13
to sy...@googlegroups.com
On Mar 22, 2013, at 10:51 AM, Alexander Overvoorde <over...@gmail.com> wrote:

Hi,

I'm the developer of the app you're talking about. I had the idea for the app itself
for a while, but it took me a long time to find a suitable CAS. Sympy seemed to
be the most complete package of all open source solutions available and it's written
in a language I'm familiar with.

Unfortunately it's quite difficult to embed the Python runtime on Android, let alone
getting an entire library to run, so I decided to build an API for it instead. The server
uses bottle and requests look like this:


The code supporting this is about 700 lines long. It currently uses Python 0.7.2 grabbed
from the Google Code archive. It runs this on Python 2.7.

The code for the app is currently not open source because I've had some bad experiences
with releasing code for products like this. It has in the past resulted in fragmentation
and people simply taking code/UI elements and using them in their app without attribution.
I'm not currently capable of providing the required support for an open source project like this.

I could release the server code and allow people to run their own server, but I think this
only has a use if at some point in the future would decide to shut down the regular server.

I do believe in open source (https://github.com/Overv), but I currently see MathStep as a
sort of demo project of my capabilities. I'm a pretty young developer (19 years) and personal
work to put on my resume is everything to me right now. This requires a certain degree of
control that I've lost with a particular Android open source project in the past. I realise that
it is a bit morally dubious to use an open source library in commercial work, but I hope that
I've made up a bit for this by offering a well thought out interface for the library.

Well you're free to do whatever you want. There's a reason SymPy is BSD. 

I'm actually personally more curious what the server code looks like, as that's the code that actually calls SymPy. 


I've noticed that equation solving in SymPy is still a little bit lacking and I'd like to contribute
to this component in the near future. I'm a fan of the project and I hope to make meaningful
contributions to it once I've gotten more Python experience.

That would be great. Also if there any bugs in SymPy that you've found or issues you've had to work around, it would be for our mutual benefit to have them fixed upstream. 


As for the math rendering, it's a homegrown solution. It treats the input expression as a mostly
1 dimensional drawing and offsets the y for exponents and uses special treatment for fractions.
It allows me to specify a width and height and it takes care of the scale automatically, which is
something not many other solutions offer.

So the rendering is done client side?

Aaron Meurer


Op vrijdag 22 maart 2013 03:23:27 UTC+1 schreef Aaron Meurer het volgende:

Alexander Overvoorde

unread,
Mar 22, 2013, 2:49:55 PM3/22/13
to sy...@googlegroups.com
Op vrijdag 22 maart 2013 18:00:57 UTC+1 schreef Aaron Meurer het volgende:

I'm actually personally more curious what the server code looks like, as that's the code that actually calls SymPy. 

You can find the server code here:


It's fairly straight forward with some caveats, like the conversion from my app's expression syntax to sympy's.
The syntax differs because I was originally working on my own CAS that actually provided detailed explanations.
 
So the rendering is done client side?

Yep, it's drawn with Bitmap and Canvas objects in Java. 

David Li

unread,
Mar 22, 2013, 3:12:45 PM3/22/13
to sy...@googlegroups.com

If you're interested in functionality for explanations of derivatives and integrals, there is some code at https://github.com/sympy/sympy_gamma/pull/8. I'm currently working on integrating the integral functionality into the core SymPy project.

--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/So8awjcpQq8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.

David Joyner

unread,
Mar 22, 2013, 3:18:25 PM3/22/13
to sy...@googlegroups.com
On Thu, Mar 21, 2013 at 10:23 PM, Aaron Meurer <asme...@gmail.com> wrote:
> Actually there are a handful of apps both on Android and iOS (and also
> some of the other ones) using SymPy. We should start a wiki page
> listing them all.

There is this:
http://www.robertocolistete.net/Python/SymPy/
but it is a bit outdated.

Aaron Meurer

unread,
Mar 23, 2013, 1:52:20 PM3/23/13
to sy...@googlegroups.com
On Fri, Mar 22, 2013 at 12:49 PM, Alexander Overvoorde
<over...@gmail.com> wrote:
> Op vrijdag 22 maart 2013 18:00:57 UTC+1 schreef Aaron Meurer het volgende:
>>
>>
>> I'm actually personally more curious what the server code looks like, as
>> that's the code that actually calls SymPy.
>
>
> You can find the server code here:
>
> http://privatepaste.com/897af10e52
>
> It's fairly straight forward with some caveats, like the conversion from my
> app's expression syntax to sympy's.
> The syntax differs because I was originally working on my own CAS that
> actually provided detailed explanations.

Cool. So some comments:

- I think you'll get a much more robust system for converting SymPy to
your syntax is you create a custom printer. See the stuff in
sympy/printers for documentation and several examples. For example,
with a printer, it's trivial to make all instances of exp() print as
e^. You just have to override _print_exp() in your Printer subclass
(on a side note, there's also
https://code.google.com/p/sympy/issues/detail?id=1799 for this
specific issue).

- You should be careful about calling simplify() at the beginning of
each function. It can be expensive sometimes and it can potentially
rewrite an expression in such a way that the function in question
won't give the desired output any more.

- The example from your screenshot of multiple integration is
technically wrong. The arbitrary constant of an integral of a function
in x and y with respect to x should be an arbitrary function of y.

- You might be careful with the caveat with limit() that it defaults
to the limit from the left, not the bidirectional limit (see
https://code.google.com/p/sympy/issues/detail?id=1000). Most users
might not expect this.

- You should avoid using strings to check things. They are
inefficient, and can lead to incorrect results if someone uses tricky
symbol names. You can check everything just by looking at the
expression tree. For example, to see if an expression contains certain
functions, just use expr.atoms().

- You might appreciate some of the new parsing code that is in the git
version of SymPy. It lets you do things like implicit multiplication
and application (like x y instead of x*y, or cos x instead of cos(x),
or even cos^2 (x) instead of cos(x)**2). The API is in flux, though,
so be aware of that.

As I mentioned, I don't have an Android device to test this on, but it
looks like people like it. Maybe I'll get my friend to let me borrow
his phone.

Aaron Meurer

>
>>
>> So the rendering is done client side?
>
>
> Yep, it's drawn with Bitmap and Canvas objects in Java.
>

Alexander Overvoorde

unread,
Mar 25, 2013, 6:20:14 AM3/25/13
to sy...@googlegroups.com
Thanks for all the information! Although the documentation was very helpful
for using SymPy to do operations, I found the info on inspecting expression
trees a bit lacking (it took a while to even find atoms). Your comments are
very helpful for improving these parts of the code.

For simplify, would you suggest to show the simplification
but use the original expression as input for operations? My
reasoning was that simplifying first would lower the workload
for certain trivial input like deriving sin(x)^2+cos(x^2).

The implicit multiplication and and optional parentheses
in the parser are useful, but in my case the expression
passed to SymPy is generated from an expression tree,
so the multiplications are already in explicit form and functions
have parentheses.

How safe would it be to use the git version? It would be
cool to use the latest and greatest version.

Let me know if you get to try the app and have any remarks :)

Op zaterdag 23 maart 2013 18:52:20 UTC+1 schreef Aaron Meurer het volgende:

Ondřej Čertík

unread,
Mar 25, 2013, 8:04:20 AM3/25/13
to sy...@googlegroups.com
Hi Alexander,
> I've noticed that equation solving in SymPy is still a little bit lacking
> and I'd like to contribute
> to this component in the near future. I'm a fan of the project and I hope to
> make meaningful
> contributions to it once I've gotten more Python experience.
>
> As for the math rendering, it's a homegrown solution. It treats the input
> expression as a mostly
> 1 dimensional drawing and offsets the y for exponents and uses special
> treatment for fractions.
> It allows me to specify a width and height and it takes care of the scale
> automatically, which is
> something not many other solutions offer.


Nice work. You are definitely more than welcome to use SymPy in any
way you see fit.
That was one of the reasons we chose the BSD license, so that SymPy
can be used commercially
without problems.

Ondrej

Aaron Meurer

unread,
Mar 26, 2013, 12:57:07 AM3/26/13
to sy...@googlegroups.com
On Mon, Mar 25, 2013 at 4:20 AM, Alexander Overvoorde
<over...@gmail.com> wrote:
> Thanks for all the information! Although the documentation was very helpful
> for using SymPy to do operations, I found the info on inspecting expression
> trees a bit lacking (it took a while to even find atoms). Your comments are
> very helpful for improving these parts of the code.

The most basic expression tree methods are on Basic (like .args,
.atoms(), .xreplace(), .subs(), .func, .match(), and.replace()), and
the mathematically relevant ones are on Expr (like .as_numer_denom(),
.as_*(), and .expand()) . See
http://docs.sympy.org/dev/modules/core.html.

I agree we could use better guides for this, though. How does the
first part of the guide at https://github.com/sympy/sympy/pull/1849
look for this (I know it doesn't mention atoms, but it talks about
other expression tree manipulation things)?

>
> For simplify, would you suggest to show the simplification
> but use the original expression as input for operations? My
> reasoning was that simplifying first would lower the workload
> for certain trivial input like deriving sin(x)^2+cos(x^2).
>
> The implicit multiplication and and optional parentheses
> in the parser are useful, but in my case the expression
> passed to SymPy is generated from an expression tree,
> so the multiplications are already in explicit form and functions
> have parentheses.
>
> How safe would it be to use the git version? It would be
> cool to use the latest and greatest version.

We keep the git version very stable. We use Travis CI to test all pull
requests, and so nothing is merged in unless the tests are passing.
You can see if the current tests are passing at
https://travis-ci.org/sympy/sympy/builds. As you can see, they very
rarely aren't.

Occasionally bugs slip in, but the major ones are caught and fixed
pretty quickly. If you compare it to the number of bug fixes that go
in, the git version is much better than the release.

The main thing about git is that any new APIs since the last release
are considered fair game to change without warning. APIs that have
been in a release will be deprecated if possible if they change. For
your program, this probably isn't an issue, except for maybe some new
stuff that might be coming in the parsing module.

Aaron Meurer
> Visit this group at http://groups.google.com/group/sympy?hl=en-US.

Alexander Overvoorde

unread,
Mar 26, 2013, 10:23:39 AM3/26/13
to sy...@googlegroups.com
I've got SymPy successfully running on SL4A (Android scripting environment) right now, so embedding it in the app may not be that far off.
Running the code in a normal Python interpreter seems like a cleaner solution regardless.

Op zaterdag 23 maart 2013 13:59:55 UTC+1 schreef F. B. het volgende:
What about working on SymPy's compatibility on Jython? I guess that once SymPy is able to run on Jython, it would be very straightforward to write an Android app.

Jython compiles Python source code to Java bytecode, making its methods accessible from Java code. Android apps are usually written in Java, then compiled to Java bytecode, after which the Java bytecode gets translated into Dalvik bytecode for usage on Android devices.

I think the most difficult part of this idea is just getting SymPy to work on Jython, after which it would be pretty easy to translate SymPy code to the Android natively-supported Dalvik bytecode. Besides, achieving Java compatibility would allow to easily port SymPy to any Java-based platform.
Reply all
Reply to author
Forward
0 new messages