# Symbolic computation in Julia with lisp/reduce; and calling Julia from LaTeX

**URL:** <https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944>\
**Category:** Internals & Design\
**Tags:** package, proposal\
**Created:** [March 29, 2017, 12:42am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944 "2017-03-29T00:42:17Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 19, 2018, 12:13am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/21 "2018-04-19T00:13:12Z")

</div>

Thanks! Looks nice. I am interested to see where this goes.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 7, 2018, 10:13pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/22 "2018-11-07T22:13:10Z")

</div>

**Computer algebra systems & Julia…**

# 

I’m curious about the status. I tested Macsyma ca. 1987, used Mathematica ca. 1988-1992, then Maple ca. 1992-1995, then MuPad a little around 2005, and SymPy occationally. I’ve been aware of Reduce, Derive, Gauss, Maxima, etc.

I liked Mathematica for its systematic naming convention and good graphics tools, but found Mathematica expensive, the multiple programming paradigms confusing. Big plus for physics approach and well written literature. I liked Maple for its simple programming paradigm, and it was reasonably priced. Way back, Maple had simple graphics. Maple intro literature was oriented towards mathematicians, starting with examples using algebra over fields, etc. – which I found terse. MuPad was a modernized version, somewhat similar to Maple – but less well developed then (now owned by MathWorks). Was it Derive or Reduce that was used by HP in their CAS tools (calculators, etc.)? Gauss was an IBM product, I think.

# 

My main interests in CAS as part of Julia?

- Basic operation on symbolic expressions (simplify, collect, expand, etc.)
- Calculus: Differentiation, Taylor series, Jacobians, etc., Integration. Differentiation of functions.
- Solving sets of algebraic equations. Substitution, etc. Linear algebra.
- Groebner basis computations – could perhaps just as well be done directly in Julia.
- Smith form of rectangular systems (Maple can; last time I checked, MuPad/MATLAB could only do square systems ☹ ) – could perhaps just as well be done directly in Julia.

# 

User interface?

- SymPy… somewhat difficult to find indexed documentation (is there rectangular Smith form? Groebner basis?). “Complex” user interface?
- Symata… I like the idea that one switches prompt (switching between `julia>` and `symata>`). This removes the complexity of defining variables in Julia; in the `symata>` environment, this is handled in a natural way. I like the idea of trying to use Mathematica’s systematic syntax, but it is not 100% compatible, which makes some documentation needed. Important questions: how can symbolic expressions in `symata>` be transferred to `julia>`?

# 

I just dug out a Maple license to compare a model of a simple, mechanical system, described using Lagrangian mechanics and comparing it to that of Hamiltonian mechanics. The equations from Lagrangian mechanics were simple to develop; the Hamiltonians were surprisingly complex to do by hand calculation, so I gave up and used Maple for that.

It would have been useful if I could specify the Lagrangian in a Julia CAS, automatically generate optimized Euler-Lagrange equations or Hamiltonian equations in the CAS, and export the equations from the Julia CAS (SymPy, Symata, Reduce, etc.) back into a Julia function for use in a DifferentialEquations package or as LaTeX code…

Anyway, this is an interesting subtopic for Julia, in my view.

---

<div class="post-metadata">

**Author:** ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)\
**Post date:** [November 8, 2018, 8:43am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/23 "2018-11-08T08:43:25Z")

</div>

If you are interested, you are very welcome to help with [https://github.com/dalum/Sylvia.jl](https://github.com/dalum/Sylvia.jl) 😄 The hope is to make a package that is light–weight with no binary dependencies, lives inside the Julia ecosystem, rather than try to be a full–blown CAS in itself, and easily translates expressions into Julia code. It is **very** poorly documented at the moment, but I hope to fix that over the next weeks.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 8, 2018, 1:00pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/24 "2018-11-08T13:00:06Z")

</div>

Try out Reduce.jl and see if it does what you need… it does most of what you described and is a lot further along now than when this thread originally was started.

> **[GitHub - chakravala/Reduce.jl: Symbolic parser for Julia language term...](https://github.com/chakravala/Reduce.jl)**
>
> Symbolic parser for Julia language term rewriting using REDUCE algebra - GitHub - chakravala/Reduce.jl: Symbolic parser for Julia language term rewriting using REDUCE algebra

REDUCE itself is implemented in its own programming language called RLisp… one of my other plans is to implement the parser for it, implementing the reduce langauage directly into Julia. I think Julia is very well suited for natively doing symbolic CAS, but it will take effort to have all these kind of features. One way is to parse the RLisp language and interpret the hundreds of thousands of lines of REDUCE source into Julia directly, instead of using the binaries directly.

Sylvia looks very promising too, I have been keeping an eye on it, along with some other similar projects.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 8, 2018, 3:58pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/25 "2018-11-08T15:58:01Z")

</div>

I’m not really a developer; I haven’t had time to start using “Git” yet 😊 – if I do some development, it would probably rather be in application/control, etc.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 8, 2018, 4:07pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/26 "2018-11-08T16:07:07Z")

</div>

Hi Chakravala: Is there a recent manual for Reduce? I found one in PDF format from 2004 – is that the latest one? (I actually prefer PDF format; I’m so old that I prefer to print material for reading in a cafe…). According to the manual, there is a Reduce package NORMFORM that does Smith normal form for rectangular matrices/pencils. There is also a Groebner package.

It would be useful if your documentation for Reduce.jl includes references to the latest available Reduce material, and say a few words about whether additional packages (??) such as NORMFORM and Groebner works with your system – and if so, if anything extra has to be done to make it work…

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [November 8, 2018, 4:58pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/27 "2018-11-08T16:58:40Z")

</div>

- Here is a notebook with examples of the [Julia-Symata interfaces](http://nbviewer.jupyter.org/github/jlapeyre/Symata.jl/blob/master/TutorialNotebooks/Interface%20with%20Julia.ipynb) You can also try `? Compile` (The prototype is correct, but the example is out of date). [Here are similar notebooks.](http://nbviewer.jupyter.org/github/jlapeyre/Symata.jl/tree/master/TutorialNotebooks/)

- How closely to follow Mathematica syntax and semantics is an important question. At present, Symata breaks with Mathematica in many respects out of neccessity. Following SymPy is much less labor intesive.The overall project (like many or most others) is already extremely labor intensive.

- I’m not sure if you are referring to the Smith normal form. Here is a [gist](https://gist.github.com/qnighy/ec08799484080343a2da297657ccba65) that appears to use sympy and rectangular matrices. Maybe this helps. It is the first result returned by googling `smith normal form sympy`.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 8, 2018, 5:14pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/28 "2018-11-08T17:14:42Z")

</div>

Thanks. You are right – I was referring to the Smith normal form (I should have been more precise)… The Smith normal form is used in studies of zeros and poles in MIMO linear control systems, or rather: the Smith-McMillan form, which is simple to implement if one has the Smith algorithm…

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 8, 2018, 5:20pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/29 "2018-11-08T17:20:10Z")

</div>

I guess the “smith.py” is not native in SymPy. Does that mean that for Symata, the same function should be written as a Julia function? Or should it be written as a Python function and placed in some mysterious subdirectory in Julia?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 8, 2018, 7:07pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/30 "2018-11-08T19:07:38Z")

</div>

OK… I found a Reduce user’s guide from 2018… [https://reduce-algebra.sourceforge.io/manual/manual.pdf](https://reduce-algebra.sourceforge.io/manual/manual.pdf)

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 8, 2018, 7:14pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/31 "2018-11-08T19:14:57Z")

</div>

> [@BLI](#):
>
> According to the manual, there is a Reduce package NORMFORM that does Smith normal form for rectangular matrices/pencils.

Yes, indeed you can load it in Julia with `load_package(:normform)` and you can send it Reduce commands. However, I have not implemented any special methods that correctly parse the output of those methods. This wouldn’t be too much extra work to implement, but I don’t know when I have the free time for it.

> [@BLI](#):
>
> There is also a Groebner package.

This is a package that gets automatically loaded and called as needed for functionality, I believe.

> [@BLI](#):
>
> It would be useful if your documentation for Reduce.jl includes references to the latest available Reduce material, and say a few words about whether additional packages (??) such as NORMFORM and Groebner works with your system – and if so, if anything extra has to be done to make it work…

You can find a list of current support for the built-in REDUCE packages on the `ReduceAlgebra.jl` page

> **[GitHub - JuliaReducePkg/ReduceAlgebra.jl: Meta-package for Reduce.jl and...](https://github.com/JuliaReducePkg/ReduceAlgebra.jl)**
>
> Meta-package for Reduce.jl and External Packages. Contribute to JuliaReducePkg/ReduceAlgebra.jl development by creating an account on GitHub.

Technically, you can load all other packages also, but I don’t have specific interfaces implemented for them unless they are currently listed on that page. That page also has links to PDFs and HTML docs.

> [@BLI](#):
>
> I’m not really a developer; I haven’t had time to start using “Git” yet 😊 – if I do some development, it would probably rather be in application/control, etc.

Luckily, it is very easy to contribute extra interfaces for more REDUCE packages (since there is a parser generator and lots of built-in features that help), so this would be a place to start in terms of contributing to a git repository. An example of how to do it is the `ReduceLinAlg` package that I have published as an example [GitHub - JuliaReducePkg/ReduceLinAlg.jl: A selection of functions that are useful in the world of linear algebra](https://github.com/JuliaReducePkg/ReduceLinAlg.jl)

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [November 8, 2018, 8:37pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/32 "2018-11-08T20:37:58Z")

</div>

> [@BLI](#):
>
> I guess the “smith.py” is not native in SymPy. Does that mean that for Symata, the same function should be written as a Julia function? Or should it be written as a Python function and placed in some mysterious subdirectory in Julia?

By “not native” I guess you mean not in the sympy distribution. I don’t know of a turnkey way to include code like this. It’s not clear if there is a universally best way in this case. Translating expressions between Symata and sympy is slow, and is often the bottleneck. So maybe wrapping the python code in the gist is the way to go. I have not written a tutorial on how to do this; in fact, I haven’t tried it, although it’s not difficult. I don’t know how systems are specified for DifferentialEquations, so I don’t know if the existing Julia-Symata interfaces are enough. As you can see, there is a lot of software and a huge number of possibilities for building symbolic tools with it. The only things lacking are the usual in open source; buy-in, organization, long(ish)-term design, and developer-hours.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 12:17am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/33 "2020-10-29T00:17:47Z")

</div>

I saw your implementation of Maxima, but it said something about Windows needing a .bar file, can you go into more detail on that? perhaps I could open a help chat.

[Previous page](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944.md?page=1)
