Symbolic manipulations with Julia

Hi,

I’m looking for a symbolic manipulations library to do different sorts of analysis on a model. I’ve tried python SymPy but couldn’t get it to work; following a recent tweet by @cscherrer, I was wondering whether I can use Julia’s SymPy/SymEngine for this. In short, the expression I’m interested in is an exponential distribution of the form:
P(x,y|W)=\frac{1}{Z}\exp\left(-xWy\right)
such that x,y\in\{0,1\}^N are boolean vectors of size N, W is an NxN matrix and Z is a normalising constant (or partition function):
Z=\sum_{x,y}\exp\left(-xWy\right)
I’m interested in various quantities of this expression, such as \frac{dP}{dw_{ij}}, KL\left( P(x,y|W) ; P(x,y|W')\right), and others, as well as approximations for the w_{ij}\ll1 regime (which helps with the exponent). Is this reasonable/doable in Julia?

Disclaimer - I have absolutely no Julia experience; I’ve been wanting to try it for a long time, and I’m hoping this will be my excuse. :slight_smile:

3 Likes

Welcome, @Adam_Haber!

Sounds definitely doable, and the kind of thing that drew lots of us to Julia in the first place. I need to get ready for work, but I think you’ve come to the right place.

You can do a lot of this already with ModelingToolkit, but it needs better docs. I’m writing it up more this week now that there seems to be a lot of interest.

5 Likes

Have you looked at Reduce.jl?

1 Like

I just went over their docs and it certainly looks relevant. My main concern is how to express (symbolically) the partition function, which quickly becomes an intractable sum over the binary sample space. Is this doable with Reduce.jl? If there’s any example/tutorial relevant to this problem, that’d be great!

Julia’s SymPy package calls the python sympy library, of course. So whether the Julia package helps depends on what you mean by “couldn’t get it to work”. If you do get Julia’s SymPy installed and working, you will have a working python sympy as well. If python sympy somehow lacks functionality you want, it’s unlikely that Julia SymPy will have it.

ModelingToolkit.jl does not appear to depend on SymPy. Reduce.jl does not depend on SymPy. So, there is a chance they will have what you need.

If you want to integrate the symbolic work with some numeric work, then doing everything in Julia may be a good choice.

I’m the developer of Reduce.jl but am only on my phone internet for now and don’t have much time to look into this problem right now. If you do try something, let us know and I might be able to help, but I don’t have time to really work on problems at the moment.

The package does have features for declaring a symbolic variable as linear operators and matrix / vectors.

You can also reach out to the sourceforge community for the upstream REDUCE, they are also helpful there.

Another thing that @cscherrer and I were discussing is to use my Grassmann.jl mathematical package to work with higher dimensional dsitributions with multivectors instead of matrices (like using complex numbers but higher dimensions). With booleans, this is quite similar to quantum computing also. Theoretically perhaps also possible (maybe that’s unrelated but I recall discussing this with him also), but requires learning a lot of math and either way I’m currently not fully available to answer these questions, but that’s another pathway to look at.