grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
126 stars 24 forks source link

Calling from Julia #319

Closed githubtomtom closed 4 years ago

githubtomtom commented 4 years ago

I would like to implement a Julia package that transforms Julia’s symbols and expressions into corresponding Yacas’ things. Is there any advise for a head start? e.g. how to communicate with a Yacas process without using the interactive environment? Thanks

grzegorzmazur commented 4 years ago

Hi,

First of all, yacas is just a library which can be linked to any program, and the symbolic transformations then can be just called from the program. The yacas console is a small application which handles entering expressions from terminal and calls the library to produce results. You may want to have a look at how Ryacas is implemented, probably what you are after is quite similar. So probably https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/ is a good place to start. Then you may want to look at cyacas\yacas\src\js_interface.cpp to see how the library can be called from plain C code.

Another thing is adding some yacas code so that the transformed expressions are returned directly in the language you want - there are already implementations for C, latex and R.

Cheers, Grzesiek

githubtomtom commented 4 years ago

...calling in the library level is nice, yet it may be too hard for me initially.... Is there a “command line” version of Yacas such that I could do like:

prompt> yacas “some commands”

? Thanks

grzegorzmazur commented 4 years ago

of course there is :)

mazur@murkwia:~$ yacas -c -i "[a:=2; Echo(D(x)Sin(a*x));]"
2*Cos(2*x)
githubtomtom commented 4 years ago

Yeah thanks!

githubtomtom commented 4 years ago

a few more questions:

  1. the following command-line Yacas seems have no memory:

    Thomass-iMac:bin Thomas$ yacas -c -i "[a:=2; Echo(D(x)Sin(a*x));]"
    2*Cos(2*x) 
    Thomass-iMac:bin Thomas$ yacas -c -i "[Echo(a + 1);]"
    a+1 
    Thomass-iMac:bin Thomas$ yacas -c -i "[a:=2; Echo(D(x)Sin(a*x)); Echo(a + 1);]"
    2*Cos(2*x) 
    3 

    how could I keep the "internal states" between each calls of yacas -c -i ?

  2. where/how could I find the documents of the command line parameters (i.e. those -i, -c)?

  3. Mac binary only available up to version 1.6.1? I tried the sudo for 1.9.1. but it shows:

    Thomass-iMac:~ Thomas$ sudo add-apt-repository ppa:teoretyk/yacas
    sudo: add-apt-repository: command not found

thanks!

grzegorzmazur commented 4 years ago

Hi,

  1. Unfortunately this is so because you start an application, pass it some instructions to execute, yacas executes them, returns the results and quits; to keep the state of calculations you'd have to keep yacas in memory, eg linking the library and keeping the intepreter alive between subsequent calls to perform calculations.
  2. https://github.com/grzegorzmazur/yacas/blob/master/man/yacas.1.rst
  3. This is highly unfortunate, but I haven't got access to any mac since some time, so I can't even build yacas not to mention packaging it. The instructions with add-apt-repository are ubuntu linux specific, they will not work on mac. From what I can see, binary build for yacas are provided by homebrew.

Actually, it'd be awesome if you built native yacas binary on mac and package it - I can try to help with it.

githubtomtom commented 4 years ago

thanks