# How to communicate matrices et al between Julia and Reduce using Reduce.jl

**URL:** https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199
**Category:** New to Julia
**Tags:** reduce
**Created:** [September 8, 2025, 8:49pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199 "2025-09-08T20:49:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![TonyRoberts](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TonyRoberts](https://discourse.julialang.org/u/TonyRoberts)
#### Post date: [September 8, 2025, 8:49pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/1 "2025-09-08T20:49:38Z")

</div>

One way forward for me is to combine the power of Reduce-algebra with Julia numerics. The Reduce.jl package should enable this. A crucial first step is to be able to communicate matrices of numbers between Julia and Reduce: more specifically, Reduce generates a matrix from its algebra, I communicate it to Julia, Julia computes eigenvalues and eigenvectors and a LU decomposition of a borderd-matrix, or QR, and then communicates these matrices back to Reduce-algebra for use in further algebra. But I just cannot see how this communication is actually accomplished. Please advise.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 8, 2025, 8:57pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/2 "2025-09-08T20:57:43Z")

</div>

It would be helpful if you could provide an example script that fails.

---

<div class="post-metadata">

### Author: ![TonyRoberts](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TonyRoberts](https://discourse.julialang.org/u/TonyRoberts)
#### Post date: [September 8, 2025, 9:17pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/3 "2025-09-08T21:17:08Z")

</div>

Unfortunately, I really do not know how to start.  
I can see the examples Reduce,jl, but almost never do the examples make it clear what of the printed information is ‘known’ to Julia and what to Reduce. Effectively I have no idea. ☹

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 8, 2025, 11:51pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/4 "2025-09-08T23:51:39Z")

</div>

Well, we have a REPL. Just try it out. You can also write some pseudo code.

If you create an issue at Reduce.jl you reach the author of the package, but I doubt that he can help you without a more concrete description of what you are trying to achieve.

---

<div class="post-metadata">

### Author: ![TonyRoberts](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TonyRoberts](https://discourse.julialang.org/u/TonyRoberts)
#### Post date: [September 9, 2025, 5:04am UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/5 "2025-09-09T05:04:24Z")

</div>

OK will go to Reduce.jl However, I have figured out how to use function calls to do something—but something appears weird to me. I wonder if it is common to other “call” scenarios so will share here also.

I _successfully_ do the following step-by-step by hand in the CLI (aka REPL I guess).

```julia-auto
using Reduce
@force using Reduce.Algebra
println("starting reduce")
R"in \"randmat.txt\"$" # executes Reduce commands in randa.txt
A = eval(rcall(:(randmat(6))))

```

The dialogue is

```julia-auto
julia> using Reduce
julia> @force using Reduce.Algebra
julia> println("starting reduce")
starting reduce
julia> R"in \"randmat.txt\"$" # executes Reduce commands in randmat.txt
julia> println("starting rcall of the Reduce function")
starting rcall of the Reduce function
julia> A = eval(rcall(:(randmat(6))))
6×6 Matrix{Int64}:
 0 0 0 0 1 6
 2 0 0 1 6 5
 2 0 0 3 7 6
 0 1 1 2 0 7
 3 0 0 6 7 3
 3 2 5 1 3 8
julia> println("finished rcall")
finished rcall
julia> 

```

But when I try to execute it a a sequence of commands in a file, it fails in the eval(rcall(.)) step: execution hangs waiting for something. So I expanded the eval(rcall()) and the problem appears to rcall (which I understand is derived from another “call()” function). Trace printing in the script reports the following, and hangs in the rcall

```julia-auto
julia> include("test.jl")
starting reduce
setting up Reduce function randmat
doing rcall

```

Any suggestions?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 9, 2025, 7:39am UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/6 "2025-09-09T07:39:22Z")

</div>

You did not share the content of the file `randmat.txt`, so I cannot reproduce the issue.

Additional remark: Please read: [GitHub - chakravala/Reduce.jl: Symbolic parser for Julia language term rewriting using REDUCE algebra](https://github.com/chakravala/Reduce.jl?tab=readme-ov-file#loading-packages)

For loading Reduce packages you should use the command:

```julia-auto
load_package(:scope)

```

where `:scope` is the name of the package to load.

Furthermore it is not clear to me why you use `@eval`, that should not be needed.

---

<div class="post-metadata">

### Author: ![TonyRoberts](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TonyRoberts](https://discourse.julialang.org/u/TonyRoberts)
#### Post date: [September 9, 2025, 8:52pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/7 "2025-09-09T20:52:00Z")

</div>

Hi, let me address each comment.  
First, the content source of “randmat.txt” for Reduce is simply

```julia-auto
matrixproc randmat(n); begin
    matrix a(n,n);
    for i:=1:n do for j:=1:n do a(i,j):=random(i+j);
    return a;
end$  
end;

```

Second, on load\_package: why do you consider that loading Reduce packages has anything to do with the problem? load\_package() just extends Reduce’s capabilities, I do not see how it can contribute to how Julia communicates with Reduce. I can see nothing in the Reduce.jl documentation saying there is an accompanying package for Reduce to load.

Third, on using eval. The rcall() returns an object of type Expr. For example “rcall(:(randmat(4)))” returns the answer “:([1 2 1 3; 1 0 3 4; 2 4 1 3; 3 0 5 6])” and then “eval(ans)” gives a Julia matrix, e.g.,

```julia-auto
julia> rcall(:(randmat(4)))
:([1 0 3 1; 1 3 4 3; 0 4 3 6; 0 3 0 4])
julia> eval(ans)
4×4 Matrix{Int64}:
 1 0 3 1
 1 3 4 3
 0 4 3 6
 0 3 0 4

```

So, how can I not need eval()?

---

<div class="post-metadata">

### Author: ![TonyRoberts](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TonyRoberts](https://discourse.julialang.org/u/TonyRoberts)
#### Post date: [September 9, 2025, 8:58pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/8 "2025-09-09T20:58:43Z")

</div>

BTW further information: executing in Mac OSX 15.6 terminal window via the command “julia \< test.jl” works; but executing “julia test.jl” fails due to the rcall() hanging. Completely mysterious to me.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 9, 2025, 9:07pm UTC](https://discourse.julialang.org/t/how-to-communicate-matrices-et-al-between-julia-and-reduce-using-reduce-jl/132199/9 "2025-09-09T21:07:39Z")

</div>

I see, you created an issue: [Reduce.jl/issues/62](https://github.com/chakravala/Reduce.jl/issues/62) . Good.

I will try to reproduce the issue on Linux tomorrow. If I should not be able to reproduce it, it might be a mac specific issue.
