# Interoperability between Symbolics.jl and MathLink.jl

**URL:** <https://discourse.julialang.org/t/interoperability-between-symbolics-jl-and-mathlink-jl/128596>\
**Category:** General Usage\
**Tags:** symbolics, mathematica\
**Created:** [May 1, 2025, 2:34pm UTC](https://discourse.julialang.org/t/interoperability-between-symbolics-jl-and-mathlink-jl/128596 "2025-05-01T14:34:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [May 1, 2025, 2:34pm UTC](https://discourse.julialang.org/t/interoperability-between-symbolics-jl-and-mathlink-jl/128596/1 "2025-05-01T14:34:46Z")

</div>

Dear All,

Is interoperability possible between Symbolics.jl and MathLink.jl? I would like to create a symbolic object in Julia, do part of the calculation using Symbolics.jl and then pass some intermediate symbolic object to Mathematica or Wolfram Engine via MathLink.jl for further manipulation, and then convert it back to Symbolics variables.

For example, consider the following example, where I multiply two matrices in Symbolics.jl and then compute the eigenvalues of the new matrix in MathLink.jl.

```julia
using Symbolics, MathLink

@variables α β
a = Symbolics.variables(:a, 1:2, 1:2) 
a[1,2] = a[2,1] 
# will create 
# 2×2 Matrix{Num}:
# a₁ˏ₁ a₂ˏ₁
# a₂ˏ₁ a₂ˏ₂

b = Symbolics.variables(:b, 1:2, 1:2)
b[1,1] = α
b[2, 2] = β
b[2, 1] = 0
b[1, 2] = 0

# at this stage b is
# 2×2 Matrix{Num}:
# α 0
# 0 β

c = a*b 
# c is equal to 
# 2×2 Matrix{Any}:
# a₁ˏ₁*α a₂ˏ₁*β
# a₂ˏ₁*α a₂ˏ₂*β

```

To compute the eigenvalues of `c` in Mathematica, I convert `c` into a MathLink.WExpr object manually and call the Wolfram function `Eigenvalues` via `weval` as follows:

```julia
weval(W`
Eigenvalues[{{a₁ˏ₁*\[Alpha], a₂ˏ₁*\[Beta]}, {a₂ˏ₁*\[Alpha], a₂ˏ₂*\[Beta]}}]
`)     

```

which gives the correct eigenvalues, but now I have to painstackingly bring back the `MathLink.WExpr` into Symbolics variables. I have to do these steps manually, and I was wondering if there is any way of automating the process? I found the Julia package `https://github.com/eswagel/SymbolicsMathLink.jl` which I believe has similar use cases, unfortunately it does not work even for simplest of examples and seem to have many bugs.

Any tips or suggestions regarding how to automate this conversion process between Symbolics.jl and MathLink.jl will be much appreciated.

(Of course, I am talking about this specific example just to illustrate what my intention is. My actual use case is somewhat involved and requires to use some special functions in Mathematica that is not currently possible in Symbolics.jl.)

---

<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:** [May 1, 2025, 3:28pm UTC](https://discourse.julialang.org/t/interoperability-between-symbolics-jl-and-mathlink-jl/128596/2 "2025-05-01T15:28:10Z")

</div>

There’s nothing fundamental that stops it, but I don’t think any link has gotten serious attention. It’s worth opening an issue on Symbolics.jl, though it may not get attention for a while.

---

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [May 1, 2025, 3:30pm UTC](https://discourse.julialang.org/t/interoperability-between-symbolics-jl-and-mathlink-jl/128596/3 "2025-05-01T15:30:23Z")

</div>

Thanks for your response @ChrisRackauckas , I will open an issue on Symbolics.jl !
