Porting a CAS to Julia

(Replying to myself)

I repost there a comment i made on the page Rock–paper–scissors game in less than 10 lines of code

It seems to me that Julia type system built around algebraic data type and multidispatch can be well described using computational topology principle in particular cochain complexes, cech cohomology, may be topological data analysis

I particulary like the work of Robert Ghrist and his recent book Ghrist; 2014; Elementary Applied Topology
that i am still studying. Here is an excerpt (p117)

0bdf4006cf31a753cf5169040609ceeb7d5c75afacf98bcde1fa68b525fd688c

IMHO, that’s why OOP fails so often: jailing every method in one class and trying to serve everyone at 360 degrees. Served with pointing, pivoting, nesting again and again. Epic failure about to happen.

That would be nice if this could be better explained and may be even represented and included into a Julia CAS (which will lead to a kind of self-hosting computational and mathematical language)

2 Likes

On the current master branch of Reduce along with the unregistered package ReduceLinAlg, which provides the hessian constructor, you can now do something like this along with other things.

julia> using Reduce, ReduceLinAlg
Reduce (Free PSL version, revision 4068), 16-Jun-2017 ...

julia> v = [:w, :x, :y, :z]
4-element Array{Symbol,1}:
 :w
 :x
 :y
 :z

julia> A = hessian(:x * :y * :z + :x ^ 2, v) |> mat
4×4 Array{Any,2}:
 0  0    0    0  
 0  2     :z   :y
 0   :z  0     :x
 0   :y   :x  0  

julia> transpose(v) * A * v / 2
:((x + 3 * y * z) * x)

However, note that if you use the v' operation for transpose, the conjuage is used, so

julia> v*v'
4×4 Array{Expr,2}:
 :((repart(w) - impart(w) * im) * w)  …  :((repart(z) - impart(z) * im) * w)
 :((repart(w) - impart(w) * im) * x)     :((repart(z) - impart(z) * im) * x)
 :((repart(w) - impart(w) * im) * y)     :((repart(z) - impart(z) * im) * y)
 :((repart(w) - impart(w) * im) * z)     :((repart(z) - impart(z) * im) * z)

Additionally, there are many other built-in functions that can work with symbolic AST expressions

julia> det(A+7*I)
:(-7 * (7 * ((z ^ 2 - 63) + y ^ 2) + (9x - 2 * y * z) * x))

The core features of those have been implemented, although there still may be some edge cases where it doesn’t work properly. The following is the new ReduceLinAlg package, which gives an initial external demonstration of how the parser generator can be used to extend the Julia language:

Other developers can certainly try to add more functions to the ReduceLinAlg repository by using the parsegen function provided by Reduce.jl and by studying the upstream docs. More explanatations will be laid out on the documentation in the near future, to help developers understand the process of extending Julia using the Reduce parser.

1 Like