Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
On Mon, May 25, 2020 at 11:39 PM rjf wrote: > > It looks like you have written a recursive descent parser. And a display. > If you were running Maxima on a Pi, (see sourceforge for download) > you would have a parser and a display without writing it yourself. > > Just looking at the code briefly, I think you have to decide > if you actually meet your own specs. I don't know what sympy will > provide, so maybe it is really OK. > > For example, > > a*b*c*d*e = a*g*c*d*f > divide by b*d do you get > > a*c*e = a*g*c*f/b ? > > > or more seriously, (x^2-1)/(x+1) to get (x-1) ? > > I would be surprised if you were the first person to write > a parser like this in Python, but it is a learning experience. as well as a Groebner basis implementation, and a multivariate polynomial factorisation implementation... Well, both are in Sympow: https://docs.sympy.org/latest/modules/polys/reference.html https://docs.sympy.org/latest/tutorial/simplification.html > > Good luck. > > > > > > On Monday, May 25, 2020 at 12:49:09 PM UTC-7, Jonathan wrote: >> >> As promised here is a git repository with a myBinder demonstration of what I >> have so far. Once I extend it to handling inequalities, it will more than >> meet my use case needs. >> >> Some have asked for more specifics. Here is a list of some of the more >> important requirements: >> >> 1) Can be installed in a plain vanilla python3 virtual environment via pip >> or simply as a python file to be loaded. >> 2) Does not conflict with SymPy or NumPy. >> 3) Will load and run fast enough to avoid user complaints on a Raspberry Pi. >> One initial use case is being combined with Pi data acquisition hardware and >> python tools for controlling them. >> 4) Makes sense to scientists in the fields of Physics, Chemistry and Biology. >> >> Thanks, >> Jonathan >> >> On Thursday, May 21, 2020 at 8:30:42 AM UTC-5, Jonathan wrote: >>> >>> Dear All, >>> >>> I have a use case where I need something lighter weight than the whole of >>> Sagemath. I think SymPy + the ability to handle math on symbolic equations >>> as Sagemath does it might be enough. Thus I wanted to see if I could >>> extract from Sagemath the code supporting math on symbolic expressions and >>> overlay that on SymPy or at least use that as a template. Can somebody >>> please point me to the place to start looking in the codebase? >>> >>> To make sure people understand what I am interested in, here is a simple >>> example of the ability I would like to extract: >>> >>>eq1 = p*V==n*R*T >>> >>>eq1 >>> p*V=n*R*T >>> >>>eq2=eq1/V >>> >>>eq2 >>> p=n*R*T/V >>> >>> Thanks, >>> Jonathan > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-devel/579775eb-c74a-4dcc-a76c-8a8ebe6a5ca6%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAAWYfq1Lm3Vn5PFLHxJ%2Bp3T8pzHiCj1GTODPiH0j7Q%3DTXaAEcA%40mail.gmail.com.
Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
You haven't provided enough information about your environment, but it is generally feasible to acquire data in Maxima from a file or a socket or a stream. Or compute numerical stuff, generate random numbers, read from a keyboard, web page...etc. Given that you are familiar with a particular programming language (here, Python) that is not a symbolic math system your approach probably is structured as follows: Your (mostly already written?) python program does stuff A then somehow calls your symbolic math program as a subroutine on data B then does something with the returned answer C . There are a few questions here: your program must format something to be input to the symbolic math program. It could be a string, or maybe something that looks like a tree with pointers, or lisp list. Any of these forms may be tricky to produce correctly. You need to know about the symbolic math pgm. Later, your program must receive an answer from the symbolic program. Maybe it is just "true" or 43. But if it is a symbolic expression, then it is maybe a string or a tree with pointers. Or maybe you are just displaying it?? Anyway, you may need to know even more about the symbolic math pgm. Generally, it may be tricky for your program to accept the answer. (this is really a standard question for the ages -- Physicist: can you do symbolic math for me. Computer scientist: OK, we can compute "sin(x)*exp(x^2)" What are you going to do with this in your Fortran program? Physicist: uh, evaluate it at x=.1, .2, .3 ... Computer scientist: you mean to call a compiler?? you can just let the symbolic math program do the evaluation, write it into a file, or just plot the curve directly.. Physicist: You can do all that? But my program runs ... < excuses...> ) So you are possibly committing yourself to writing a parser, a string output display, calling a compiler??? ... what else? Here's another structure: Start up Maxima and load a program that does "stuff A". It might even do "stuff A" by calling Python. Maxima is written in Lisp, and there are ways of calling Python. Or the code could be written in Lisp (compiled, maybe faster than Python?) or in the Maxima language. Any of these languages can acquire info from a user, if that is what is in your task. Error checking of symbolic formula input is already written. Having done stuff A, the symbolic part is ready to roll.. What to do with the answer? Whatever. Maxima can decompose the answer, or display it or write to a file ... If it is necessary to run in Python, it is again possible to call Python. (And hand it a string or lisp/maxima structure). If python is called, It can return to Maxima, and Maxima can loop back for the next iteration. . If you absolutely have to have Python as "the boss" you could still do this: Start up a python system that does almost nothing but initialize Maxima and call it. Then use the structure outlined above. For what it is worth, I have directly called python library routines (interfaces to multiple-precision arithmetic, as it happens) from lisp. Whether this approach is feasible is probably not a technical question -- just depends on what you are comfortable doing. It may be too late to consider this kind of change, and it may be a bad fit for your application for some other reason. In which case maybe think about this for your next project. If you insist on calling the symbolic math program as a subroutine, perhaps the simplest interface is to invoke Maxima on some input from a command line. If your task is simple enough. RJF On Sunday, May 24, 2020 at 3:49:18 PM UTC-7, Jonathan wrote: > > Although a good idea, I don't think I can make it simple enough to set up > inside a data acquisition environment that depends on Python. This would > require installing Maxima and all the connector software. The people using > this are unlikely to do anything that requires more than a `pip > install...`. Once Sagemath can cleanly install using pip, this problem will > be solved on systems with enough processing power and memory. I've almost > get everything needed working already. I will post a link to the github > repository as soon as I post the first version. > > Thanks to all for the suggestions. > Jonathan > > On Sunday, May 24, 2020 at 12:00:00 PM UTC-5, rjf wrote: >> >> It seems to me that the obvious thing is not to extract parts from >> SageMath, but >> just use Maxima, which is a part, but also an entire symbolic math >> system, >> >> Your example looks like this: ( assignment is ":" equations use "=". >> a command is terminated by ";" ) >> >> eq1 : p*V = n*r*t ; >> eq1/V; >> >>returns p = (n*r*t)/V >> >> RJF >> >> On Friday, May 22, 2020 at 5:47:35 PM UTC-7, Samuel Lelievre wrote: >>> >>> Le samedi 23 mai 2020 02:14:58 UTC+2, Dima: >>> > >>> > Conda does have Sagemath available. >>> > Not 100% sure how it works on Windows,
Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
Although a good idea, I don't think I can make it simple enough to set up inside a data acquisition environment that depends on Python. This would require installing Maxima and all the connector software. The people using this are unlikely to do anything that requires more than a `pip install...`. Once Sagemath can cleanly install using pip, this problem will be solved on systems with enough processing power and memory. I've almost get everything needed working already. I will post a link to the github repository as soon as I post the first version. Thanks to all for the suggestions. Jonathan On Sunday, May 24, 2020 at 12:00:00 PM UTC-5, rjf wrote: > > It seems to me that the obvious thing is not to extract parts from > SageMath, but > just use Maxima, which is a part, but also an entire symbolic math system, > > Your example looks like this: ( assignment is ":" equations use "=". > a command is terminated by ";" ) > > eq1 : p*V = n*r*t ; > eq1/V; > >returns p = (n*r*t)/V > > RJF > > On Friday, May 22, 2020 at 5:47:35 PM UTC-7, Samuel Lelievre wrote: >> >> Le samedi 23 mai 2020 02:14:58 UTC+2, Dima: >> > >> > Conda does have Sagemath available. >> > Not 100% sure how it works on Windows, though. >> >> One can install SageMath from Conda on Linux and macOS. >> Not on Windows. >> > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/3f8e3035-c1ae-4950-96eb-69230861f87a%40googlegroups.com.
Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
It seems to me that the obvious thing is not to extract parts from SageMath, but just use Maxima, which is a part, but also an entire symbolic math system, Your example looks like this: ( assignment is ":" equations use "=". a command is terminated by ";" ) eq1 : p*V = n*r*t ; eq1/V; returns p = (n*r*t)/V RJF On Friday, May 22, 2020 at 5:47:35 PM UTC-7, Samuel Lelievre wrote: > > Le samedi 23 mai 2020 02:14:58 UTC+2, Dima: > > > > Conda does have Sagemath available. > > Not 100% sure how it works on Windows, though. > > One can install SageMath from Conda on Linux and macOS. > Not on Windows. > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/246c6aa5-1c7b-4b73-a5ba-4d5bd1c3d31d%40googlegroups.com.
Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
Le samedi 23 mai 2020 02:14:58 UTC+2, Dima: > > Conda does have Sagemath available. > Not 100% sure how it works on Windows, though. One can install SageMath from Conda on Linux and macOS. Not on Windows. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/f619c40d-bf8a-47db-b088-909e6857e373%40googlegroups.com.
Re: [sage-devel] Re: Could someone point me to the code that supports math on symbolic equations?
On Fri, May 22, 2020 at 04:07:47PM -0700, Jonathan wrote: > Emmanuel, > > Thanks, that is one of the places I was starting. It turns out that doesn't > quite pick up the necessary stuff from the `Expr` type. I have had better > luck extending the base type `Expr`. It was not hard to get the arithmetic > parts (+, -, /,*, pow) working. I'm still looking for/working on a robust > way of extending all the SymPy functions to operate on both the lhs and the > rhs. > > The idea here is not to use solve, but allow students to use it to aid them > in doing algebra without making silly errors. We still need them to decide > on all the steps themselves. This also lets them include units in > calculations in a way that is familiar to physical scientists. > > Anyway, my hope is to get some inspiration from how it is done in Sagemath. > > Although my preference is to use Sagemath because of the inherent power, > this application needs to play nice with *conda and pip installs. So I Conda does have Sagemath available. Not 100% sure how it works on Windows, though. We're planning for this year to get Sagemath pip-installable too. > think it has to be an extension of SymPy rather than trying to convince > people to install the other tools they are using in a Sagemath environment. > > I'm definitely thankful for any suggestions people have. > > Jonathan > On Friday, May 22, 2020 at 11:54:19 AM UTC-5, Emmanuel Charpentier wrote: > > > > Well, you might consider working on the expressions > part>-. A quick test with Sympy: > > > > Python 3.8.3 (default, May 14 2020, 11:03:12) > > [GCC 9.3.0] on linux > > Type "help", "copyright", "credits" or "license" for more information. > > >>> python.el: native completion setup loaded > > >>> from sympy import * > > >>> p,V,n,R,T=symbols("p,V,n,R,T") > > >>> Ex1=p*V-n*R*T > > >>> Ex1 > > -R*T*n + V*p > > >>> Ex1/V > > (-R*T*n + V*p)/V > > >>> solve(Ex1,p) > > [R*T*n/V] > > > > But Sympy *has* the Eq operator, which allows you to build, store and use > > symbolic equations : > > > > >>> Eq1=Eq(p*V, n*R*T) > > >>> Eq1 > > Eq(V*p, R*T*n) > > >>> solve(Eq1,p) > > [R*T*n/V] > > > > OTOH, Sage isn't *that* much heavier than Sympy... > > > > HTH, > > > > Le jeudi 21 mai 2020 15:30:42 UTC+2, Jonathan a écrit : > >> > >> Dear All, > >> > >> I have a use case where I need something lighter weight than the whole of > >> Sagemath. I think SymPy + the ability to handle math on symbolic equations > >> as Sagemath does it might be enough. Thus I wanted to see if I could > >> extract from Sagemath the code supporting math on symbolic expressions and > >> overlay that on SymPy or at least use that as a template. Can somebody > >> please point me to the place to start looking in the codebase? > >> > >> To make sure people understand what I am interested in, here is a simple > >> example of the ability I would like to extract: > >> >>>eq1 = p*V==n*R*T > >> >>>eq1 > >> p*V=n*R*T > >> >>>eq2=eq1/V > >> >>>eq2 > >> p=n*R*T/V > >> > >> Thanks, > >> Jonathan > >> > > > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-devel/f8fcb045-450d-49fa-b05f-501407083544%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/20200523001452.GA3765%40hilbert.lan. signature.asc Description: PGP signature