[ANN] Giac.jl - Julia interface to the Giac computer algebra system

Hello everyone,

I’m happy to announce Giac.jl (v0.11.0), now registered in the General registry and installable with Pkg.add("Giac").

Giac.jl provides a Julia interface to the Giac computer algebra system, giving you access to 2200+ CAS commands directly from Julia.

Documentation

What is Giac?

Giac is a mature, general-purpose C++ computer algebra system developed by Bernard Parisse at Université Grenoble Alpes since 2000. It powers GeoGebra (since 2013) and the HP Prime calculator, and is available as an engine in SageMath. Giac provides robust algorithms for polynomial arithmetic, symbolic integration, limits, series, Gröbner bases, differential equation solving, and much more.

Why Giac.jl?

Julia already has great symbolic tooling with Symbolics.jl (native Julia CAS) and SymPy.jl (Python bridge). Giac.jl complements these by providing direct access to Giac’s battle-tested C++ engine via CxxWrap.jl — no Python layer, no manual compilation. The Giac library and its C++ wrapper are shipped automatically via JLL packages.

Installation

using Pkg
Pkg.add("Giac")

That’s it — the Giac C++ library is provided automatically via GIAC_jll and libgiac_julia_jll. No manual compilation or environment variables needed. Requires Julia 1.11+.

Quick Start

using Giac
using Giac.Commands: factor, expand, diff, integrate, limit, simplify, solve

# Create symbolic variables
@giac_var x y

# Arithmetic — just works
x + y       # x+y
x ^ 2       # x^2
x - (1//2)  # x-1/2 (Rational)
x + π       # x+pi (Irrational)

# Algebra
factor(x^2 - 1)             # (x-1)*(x+1)
expand((x + y)^2)           # x^2+2*x*y+y^2
simplify((x^2 - 1)/(x - 1))  # x+1

# Equations with ~ operator (Symbolics.jl convention)
solve(x^2 - 4 ~ 0, x)      # list[-2,2]

# Calculus
diff(sin(x^2), x)           # 2*x*cos(x^2)
integrate(x * exp(x), x)    # x*exp(x)-exp(x)
limit(sin(x)/x, x, 0)       # 1

# Convert to Julia types
to_julia(giac_eval("3/4"))  # 3//4::Rational{Int64}

Accessing Commands

All 2200+ Giac commands are available through the Giac.Commands submodule. Three access patterns are supported:

# 1. Selective import (recommended)
using Giac.Commands: factor, expand, diff, integrate

# 2. Full import (interactive use)
using Giac.Commands
ifactor(giac_eval("120"))  # 2^3*3*5

# 3. Universal invocation (works for ALL commands, including Julia conflicts)
invoke_cmd(:factor, x^2 - 1)  # (x-1)*(x+1)
invoke_cmd(:sin, giac_eval("pi/6"))  # 1/2

Differential Equations with the D Operator

Giac.jl includes a D operator for natural ODE syntax:

using Giac
using Giac.Commands: desolve

@giac_var t u(t) tau U0

# First-order ODE: τu' + u = U₀, u(0) = 1
ode = tau * D(u) + u ~ U0
result = desolve([ode, u(0) ~ 0], t, :u)
# Returns: U0-U0*exp(-t/tau)

# Second-order: u'' + u = 0, u(0) = 1, u'(0) = 0
ode2 = D(D(u)) + u ~ 0
result2 = desolve([ode2, u(0) ~ 1, D(u)(0) ~ 0], t, :u)
# Returns: cos(t)

Symbolic Linear Algebra

using Giac, LinearAlgebra

@giac_var a b c d
B = GiacMatrix([[a, b], [c, d]])
det(B)        # a*d-b*c
inv(B)        # symbolic inverse
tr(B)         # a+d

# Large symbolic matrices
M = GiacMatrix(:m, 3, 3)  # 3×3 with entries m11, m12, ...

Signal Processing

Laplace and Z-transforms for continuous- and discrete-time signal analysis:

using Giac
using Giac.Commands: laplace, ilaplace, ztrans, invztrans

@giac_var t s n z

# Laplace transform
laplace(exp(-t), t, s)       # 1/(s+1)
ilaplace(1/(s+1), s, t)     # exp(-t)

# Z-transform
ztrans(giac_eval("1"), n, z)  # z/(z-1)

More Features

  • Symbolics.jl integration: bidirectional conversion with to_giac / to_symbolics
  • MathJSON.jl extension: convert expressions to/from MathJSON tree format
  • Base function extensions: sin(expr), cos(expr), exp(expr) work on GiacExpr
  • Infinity support: use Julia’s Inf and -Inf in limits and improper integrals
  • Variable substitution: substitute(expr, Dict(x => 2)) (Symbolics.jl-compatible)
  • Tables.jl compatibility: convert GiacMatrix and command help to DataFrames
  • LaTeX rendering: automatic LaTeX display in Pluto notebooks
  • Command discovery: search_commands("factor"), giac_help(:factor), and Julia REPL ? integration
  • Indexed variables: @giac_several_vars a 3 3 creates a11, a12, ..., a33

Documentation

Full documentation is available at s-celles.github.io/Giac.jl, covering:

  • Mathematics: algebra, calculus, linear algebra, differential equations, trigonometry
  • Physics: mechanics, electromagnetism
  • Signal processing: Laplace & Z-transforms
  • API reference for all exported types and functions

Prior Art

There have been earlier Julia interfaces to Giac by HaraldHofstaetter and Bernard Parisse himself. This package builds on that legacy with a registered package, JLL-based automatic installation, the Giac.Commands submodule for all 2200+ commands, ODE support with the D operator, and extensions for Symbolics.jl and MathJSON.jl.

Feedback Welcome

I’d love to hear from the community:

  • Use cases: what symbolic computation tasks would you like to tackle with Giac from Julia?
  • API design: suggestions on making the interface more Julian are appreciated
  • Bug reports & contributions: issues and PRs are welcome!

Links:

Edit: now 0.11.1 after New version: Giac v0.11.1 by JuliaRegistrator · Pull Request #152695 · JuliaRegistries/General · GitHub being merged

Congratz on the release! This looks really well implemented, and the API showcased in the examples looks as natural and Julian as I could have wished for. Man, I wish I has this available during my time as a student :see_no_evil_monkey:

Is there a reason you can’t do GiacMatrix([a b; c d]), passing a 2d array to the constructor instead of a vector-of-vectors?

It seems that 2D arrays are also compatible. GIAC seems to use row-major indexing (originally implemented in C++), and Julia is using column-major indexing. I guess some sort of wrapper is used, not too sure though.

I used Mathematica, Maple, sympy in Python and SymPy.jl in Julia. I wonder what the differences are between them. BTW, it’s my first time to hear about Giac.

Looks like a promising package!
Are there functions to convert GiacExpr into julia functions (a bit like lambdify() in sympy) and functions to directly generate julia code (like julia_code() in sympy)?

@TheLateKronos @tduretz thanks for the kind words

@stevengj @lilachint
Yes you can do also

julia> using Giac
[ Info: GIAC wrapper library loaded from ...

julia> @giac_var a b c d
(a, b, c, d)

julia> M = GiacMatrix([a b; c d])
2×2 GiacMatrix:
a  b
c  d

julia> using LinearAlgebra

julia> det(M)
GiacExpr: a*d-b*c

@tduretz You can do

julia> @giac_var x
(x,)

julia> giac_expr = x^2 - 1
GiacExpr: x^2-1

julia> f(_x) = to_julia(substitute(giac_expr , x => _x))
f (generic function with 1 method)

julia> f(0)
-1

julia> f(1)
0

julia> f(-1)
0

See Giac.jl/examples/04_plotting.jl at main · s-celles/Giac.jl · GitHub

See also unwrap_const? · Issue #3 · s-celles/Giac.jl · GitHub about evalf usage

julia> giac_expr = sin(x)
GiacExpr: sin(x)

julia> f(_x) = to_julia(substitute(giac_expr, x => _x))
f (generic function with 1 method)

julia> f(2)
GiacExpr: sin(2)

julia> f(2.0)
0.909297426826

julia> f(_x) = to_julia(Giac.Commands.evalf(substitute(giac_expr, x => _x)))
f (generic function with 1 method)

julia> f(2)
0.909297426826

You can also export to Symbolics.jl

julia> giac_expr = x^2 - 1
GiacExpr: x^2-1

julia> using Symbolics

julia> to_symbolics(giac_expr)
-1 + x^2

julia> typeof(to_symbolics(giac_expr))
Num

@draftman9 maybe price and license?

I haven’t found much public (and up to date) benchmarks of computer algebra systems… except this from Nasser M. Abbasi https://www.12000.org/my_notes/CAS_integration_tests/index.htm
but it focus narrowly on integration… so that’s not a broad-coverage benchmark for CAS.

CAS benchmarks could answer precisely to your question.

For my use case I wanted free and open source software and didn’t want to rely on Python deps.

@tduretz build_function landed yesterday

using Giac
@giac_var x y
expr = sin(x^2 + y^2)

# Giac backend (default) — always available
f = build_function(expr, x, y)
f(1.0, 2.0)

# Symbolics backend — native Julia, autodiff-compatible
using Symbolics
f_fast = build_function(expr, x, y; backend = :symbolics)
f_fast(1.0, 2.0)

More info can be found at Add `lambdify` or `build_function` for converting `GiacExpr` into native Julia callables · Issue #17 · s-celles/Giac.jl · GitHub

A small Giac.jl update since my last post in May.

Giac.jl is now at v0.14.3, and quite a few things have landed since then:

  • MCP support: Giac can now be exposed as an optional MCP server through ModelContextProtocol.jl, with giac_eval for calculations and giac_search for discovering Giac commands. This makes it possible for MCP-compatible LLM clients to use Giac as an actual CAS instead of trying to do symbolic algebra themselves.

  • Faster command invocation: invoke_cmd now has a direct Gen fast path when arguments can be represented directly by Giac, avoiding the Gen -> string -> parse -> Gen round trip.

  • Better TermInterface.jl support: the extension now implements the complete expression traversal interface, including head and children, making GiacExpr easier to consume from packages using the common symbolic term interface.

  • Better rendering and conversions: LaTeX and MathML rendering no longer accidentally re-evaluate expressions before displaying them, and to_julia for Giac strings now returns the actual string contents rather than the quoted Giac literal.

  • Documentation for humans and machines: the documentation now automatically generates llms.txt and llms-full.txt, alongside updated examples and notebooks.

There have also been a number of less visible but important maintenance improvements: CompatHelper, minimum-compatibility CI testing, Dependabot for GitHub Actions, native Apple Silicon CI, and several portability and ABI fixes.

The package is gradually becoming less just a wrapper around Giac and more a bridge between Giac and the wider Julia ecosystem: Symbolics, TermInterface, MathJSON, MCP, etc.

For those who enjoy reading in the language of Molière, there is also a French presentation from the Café Julia / Groupe Calcul CNRS:

It also gives a glimpse behind the scenes at how Giac.jl, the Julia interface, has been developed using AI-assisted, spec-driven development (SDD), including my slightly questionable “cooking recipe” for working with AI on a software project. Yes, sorry about that. :grinning_face_with_smiling_eyes:

Just to avoid any misunderstanding: Giac itself, the C++ computer algebra system developed, was built the hard way, with many years of very human work (not mine).

And on a slightly different note, I am currently in Mainz for JuliaCon 2026. My Giac.jl presentation was not recorded, so you have fortunately been spared my terrible English. :grinning_face_with_smiling_eyes:

The slides, however, cannot escape the Internet: