# 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:** 20\
**Page:** 1

<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:** [March 29, 2017, 12:42am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/1 "2017-03-29T00:42:17Z")

</div>

> NOTE: the [Reduce.jl](https://github.com/chakravala/Reduce.jl) package has been created since this discussion started

Using Julia is a really great experience, thanks to all of you!

Since Julia is so inspired by the lisp language, is it feasible to combine the functionality of the Lisp-based computer algebra system known as [Reduce Algebra](http://www.reduce-algebra.com/index.htm) (which is known to be the fastest of its genre) with the Julia language? Having high performance numerical computing in Julia is very great, can high performance symbolic computation also be emphasized? With SymPy and Symata and the Julia syntax, I see a promising future; but it needs to include Reduce algebra in its vision too, I believe. Reduce algebra does symbolic computation very efficiently and has many decades of experience and is available as open source. At the very least, there is probably something Julia could learn from it. Would be great if Reduce Algebra was added to the list of languages that helped inspire the future of Julia.

In the recently published paper in SIAM Review, there were some embedded examples of Jupyter REPL input and output. Is there a specific LaTeX package that was used to achieve this? Recently I discovered the [SageTeX](https://github.com/dandrake/sagetex) package, which is wonderful because it makes embedding and executing Sage code in a compiled LaTeX document a breeze. Will there be tools to make embedding Julia computations, code, and results into LaTeX documents easy and efficient in the future? If Julia was very easily callable from LaTeX, also for inserting graphics; that would be great.

These 2 topics are important for the future of the Julia language, I believe.

My point is only to raise these 2 topics to attention for further discussion,

---

<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:** [March 29, 2017, 3:27am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/2 "2017-03-29T03:27:08Z")

</div>

> [@chakravala](#):
>
> Having high performance numerical computing in Julia is very great, can high performance symbolic computation also be emphasized? With SymPy and Symata

You’re missing SymEngine, which is probably your best bet here. SymEngine is a re-write of the core SymPy engine to C++. However, it works well with Julia because its basic type has a lot of dispatches (+,-,exp, …), and so things like Julia’s Base library (`inv`) just “complete the functionality of it”. The only thing that it really needs it an equation solver and some Groebner Basis methods, though some of this could probably be implemented in Julia directly using the dispatches. Since the dispatches are just calling the C++ functions, it ends up being really speedy and easy to extend.

> [@chakravala](#):
>
> Will there be tools to make embedding Julia computations, code, and results into LaTeX documents easy and efficient in the future? If Julia was very easily callable from LaTeX, also for inserting graphics; that would be great.

I think Weave.jl is a good way to do this.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 29, 2017, 5:49am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/3 "2017-03-29T05:49:59Z")

</div>

> [@chakravala](#):
>
> My point is only to raise these 2 topics to attention for further discussion,

If you are interested, you should start by writing a package for interfacing with Reduce. Similarly, if you think that ideas from Reduce could improve Julia, contribute them. Discussion is interesting, but it is unlikely to inspire someone without an interest to put in the work.

---

<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:** [March 29, 2017, 6:48am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/4 "2017-03-29T06:48:21Z")

</div>

There’s also Nemo.jl

[http://nemocas.github.io/Nemo.jl/latest/](http://nemocas.github.io/Nemo.jl/latest/)

---

<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:** [March 29, 2017, 1:55pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/5 "2017-03-29T13:55:09Z")

</div>

Thanks for the responses. I’d like to help contribute to a package for interfacing Reduce, but I don’t claim to have the right kind of background knowledge to know how to start. Are there any suggestions for how to go about it?

---

<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:** [March 29, 2017, 2:34pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/6 "2017-03-29T14:34:12Z")

</div>

Just start using Julia! Writing scripts and such. We have a chatroom that is pretty helpful for getting new users up to speed:

[https://gitter.im/JuliaLang/julia](https://gitter.im/JuliaLang/julia)

But I don’t think there is a set of background knowledge to make a package other than… make a package. It’s tough the first time, but with some help it works out.

---

<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:** [April 30, 2017, 2:09am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/7 "2017-04-30T02:09:37Z")

</div>

Well, I have now [created my first Julia package](https://github.com/chakravala/GroveAlg.jl) and I really enjoyed the experience so far.

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 1, 2017, 12:58pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/8 "2017-05-01T12:58:47Z")

</div>

Hey @chakravala,

Combining julia with an interactive lisp program like this is actually not too difficult. [Maxima.jl](https://github.com/nsmith5/Maxima.jl) is an example of exactly that. The basic idea is to spawn a session with interpretor you care about and reading and writing to a `Pipe` to make your calls and read the results.

```julia
input = Pipe()
output = Pipe()
proc = spawn(`reduce`, (input, output, STDERR))

write(input, "(x + y + z)^2;") # submit input to REDUCE
answer = String(readavailable(output)) # read out response

```

Hope that helps! Feel free to reach out if you find any problems trying to get REDUCE and Julia to talk to each other.

---

<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:** [May 1, 2017, 1:31pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/9 "2017-05-01T13:31:58Z")

</div>

Thanks for that information, it will help. I wouldn’t know exactly where to start with the REDUCE thing, but investigating at the Maxima package sounds like the right place to look. I have the latest verion of Reduce and Maxima compiled, so I will be able to give a shot at it.

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 1, 2017, 3:13pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/10 "2017-05-01T15:13:03Z")

</div>

Yeah take a look in [src/server.jl](https://github.com/nsmith5/Maxima.jl/blob/master/src/server.jl) (a bit of a misnomer, related to a previous TCP server-client implementation) for the implementation of the `MaximaSession` and in [src/mexpr.jl](https://github.com/nsmith5/Maxima.jl/blob/master/src/mexpr.jl) for the details of making calls to with `mcall`.

---

<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:** [May 5, 2017, 10:21pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/11 "2017-05-05T22:21:22Z")

</div>

[Reduce.jl](https://github.com/chakravala/Reduce.jl) is now a thing, I’ve got the base functionality working, provided that you have `redpsl` in your path.

```nohighlight
julia> using Reduce
Reduce (Free PSL version, revision 4015), 5-May-2017 ...

```

Similar to Maxima.jl package, you can use `rcall` to evaluate Julia expressions or reduce string using reduce.

```nohighlight
julia> rcall(:((1+π)^2))
:(π ^ 2 + 2π + 1)

```

From here, the REPL and additional Julia integration can be done.

However, I am not sure yet how to wait to read the input from the reduce pipe, sometimes the computation can take longer, so the read operation would have to wait for it to finish.

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 6, 2017, 3:18am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/12 "2017-05-06T03:18:13Z")

</div>

In [Maxima.jl](https://github.com/nsmith5/Maxima.jl), I make maxima write the ASCII End of Transmission (EOT) character to the terminal and then the pipe reads until it hits the EOT character. In maxima this is pretty easy with the `print(ascii(4))` command but I’m sure you can find the REDUCE equivalent.

---

<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:** [May 6, 2017, 4:02am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/13 "2017-05-06T04:02:53Z")

</div>

Gotcha, will need to experiment with the best solution for that. You might also want to look at some of the things I did in Reduce.jl, for example

```nohighlight
function parse(r::RExpr)
  str = r.str
  for key in keys(r_to_jl)
    str = _subst(r_to_jl[key], key, str); end
  for key in keys(r_to_jl_utf)
    str = replace(str,key,r_to_jl_utf[key]); end
parse(str); end

```

In this function I have added a second loop that iterates over an extra dictionary of symbols. This is because reduce and maxima cannot handle the expanded characters like π (for example), so in the `_subst` iteration only replace the ASCII characters and then afterwards use Julia string `replace` function to splice the greek symbols back in.

Similarly for the conversion in the opposite direction. I also implemented some error handling in `show` that you had on your TODO list, but it is based on the way REDUCE produces error messages, but maybe you can use something similar there.

---

<div class="post-metadata">

**Author:** ![nsmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsmith/32/979_2.png) [@nsmith](https://discourse.julialang.org/u/nsmith)\
**Post date:** [May 6, 2017, 4:11am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/14 "2017-05-06T04:11:24Z")

</div>

Actually, Maxima can handle UTF8. The only caveat being that Maxima has to be compiled with a common lisp that supports UTF8. Maxima compiled against [sbcl](http://www.sbcl.org/) works fine.

---

<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:** [May 6, 2017, 5:37am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/15 "2017-05-06T05:37:41Z")

</div>

Having 2 loops like this could make Maxima.jl more compatible for a wider range of maxima installations. I get an error since I don’t have sbcl version set up.

Thanks for all the input, I’ve solved the end of transmission delimiter issue now.

---

<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:** [June 3, 2017, 3:28am UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/16 "2017-06-03T03:28:33Z")

</div>

Alright, so the [Reduce](https://github.com/chakravala/Reduce.jl) build for Gnu/Linux/OSX/Unix is working, but not on Windows yet.

Does anybody know how to test the [REPL](https://github.com/chakravala/Reduce.jl/blob/master/src/repl.jl) for 100% codecov?

---

<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 18, 2018, 7:33pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/17 "2018-04-18T19:33:38Z")

</div>

> [@chakravala](#):
>
> computer algebra system known as Reduce Algebra (which is known to be the fastest of its genre)

Source?

> [@chakravala](#):
>
> Alright, so the Reduce build for Gnu/Linux/OSX/Unix is working, but not on Windows yet.

When do you think that will come?

---

<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:** [April 18, 2018, 7:57pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/18 "2018-04-18T19:57:14Z")

</div>

Hi, I have communicated with the upstream developers about updating their build system in order to make additional binaries available for Windows users that make it easier to do the automated build tests on appveyor. This was in late 2017. They were interested in it, but it is not one of their main priorities right now.

Since I don’t have direct access to a typical Windows computer right now, I can’t really make a lot of progress on it myself.

The build script can download the Reduce installer for windows perfectly fine, the only issue currently is that the binary they provide requires an administrator priviledge on Windows to execute, which I’m not sure how can be circumvented on appveyor. My idea was to try making a `cab` file that can be extracted from the command line, which I think they could incorporate into their build system. However, nobody has really had the time or Windows computers available to properly set it up.

So you can use it on windows, the only issue is making it work on appveyor.

Maybe Julia could ship it with JuliaPro for windows users or something like that?

As far as it being fast, you can test it out yourself. You will find it is indeed very quick. In Julia, it will seem slower, due to the 2-way parsing that has to be done. There are some sources online, where you can read about why people prefer Reduce over, say Mathematica, since it is open source for example, and can also solve some problems faster than it. My goal isnt to try to convince you it is the fastest, but it is very quick and efficient and has been documented to be so in various posts and discussions online. I am still working on making the Julia interface more quick and efficient.

---

<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 18, 2018, 8:22pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/19 "2018-04-18T20:22:01Z")

</div>

> [@chakravala](#):
>
> As far as it being fast, you can test it out yourself. You will find it is indeed very quick. In Julia, it will seem slower, due to the 2-way parsing that has to be done. There are some sources online, where you can read about why people prefer Reduce over, say Mathematica, since it is open source for example, and can also solve some problems faster than it. My goal isnt to try to convince you it is the fastest, but it is very quick and efficient and has been documented to be so in various posts and discussions online. I am still working on making the Julia interface more quick and efficient.

I am just curious to see those sources. Searching for “Reduce” in Google brings up a lot of false hits, and I never heard of it before the Julia package so I’m curious to find some real benchmarks to know what to expect.

As for AppVeyor, I mostly ask because I won’t be checking it out until that holds. I kind of need it for package development 😉.

---

<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:** [April 18, 2018, 8:36pm UTC](https://discourse.julialang.org/t/symbolic-computation-in-julia-with-lisp-reduce-and-calling-julia-from-latex/2944/20 "2018-04-18T20:36:35Z")

</div>

Yes, I understand your concern. I want it to work on Windows as well, and I understand that is holding people like yourself back.

Hopefully, this issue will get resolved over the summer. There are still some improvements and changes that will happen to the package, so my hope is that in the summer when julia 1.0 is released, that also Reduce.jl 1.0 can be released with the appveyor build support. Then I will be making an official announcement for the package, once that is in place.

As for sources, here is an example of a user who benchmarked a Ginzburg Landau problem with Reduce and Mathematica:

[https://sourceforge.net/p/reduce-algebra/mailman/message/31083460/](https://sourceforge.net/p/reduce-algebra/mailman/message/31083460/)

The developers of reduce acknowledge that they would like more testing to be done, so that the current performance can be better understood. But I dont believe that a precise study has been done recently. However, you can find on the order of 1,000 references on their website to find research that used their software.

> **[REDUCE Bibliography](http://www.reduce-algebra.com/bibliography.php)**
>
> The REDUCE Computer Algebra System

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