Giac.jl
A Julia wrapper for the GIAC computer algebra system.
Features
- Dynamic Command Invocation: Access all 2200+ GIAC commands via
invoke_cmd(:cmd, args...) - Commands Submodule: All ~2000+ commands available via
Giac.Commandsfor clean namespace - Expression Evaluation: Parse and evaluate mathematical expressions
- Command Discovery: Search commands, browse by category, built-in help via
?cmd - Arithmetic Operations: +, -, *, /, ^, unary negation, equality
- Algebra: Factorization, expansion, simplification, equation solving and GCD
- Calculus: Differentiation, integration, limits, and series expansion
- Infinity Support: Use Julia's
Infand-Infdirectly in limits and improper integrals - Linear Algebra: Symbolic matrices with determinant, inverse, trace, transpose operations
- Base Extensions: Use
sin(expr),cos(expr),exp(expr)with GiacExpr - Method Syntax: Call commands as methods:
expr.factor(),expr.diff(x) - Variable Substitution: Symbolics.jl-compatible
substitute(expr, Dict(var => value))interface - Laplace Transform:
laplaceandilaplacecommands for continuous-time signal processing - Z-Transform:
ztransandinvztranscommands for discrete-time signal processing - Type Conversion: Convert results to Julia native types (Int64, Float64, Rational)
- Symbolics.jl Integration: Bidirectional conversion with Symbolics.jl
- Tables.jl Compatibility: Convert GiacMatrix and command help to DataFrames, CSV export
- LaTeX Support: Automatic LaTeX rendering in Pluto notebooks
- TempApi Submodule: Simplified function names (
diff,factor, etc.) viaGiac.TempApi
Installation
using Pkg
Pkg.add("Giac") # when registered to Julia General RegistryFor full GIAC integration with C++ library, see the Installation Guide.
Command Access
GIAC commands are available through multiple access patterns:
1. Selective Import from Commands Submodule (Recommended)
using Giac
using Giac.Commands: factor, expand, ifactor
@giac_var x
factor(x^2 - 1)2. Full Import (Interactive Use)
using Giac
using Giac.Commands
@giac_var x
factor(x^2 - 1)
ifactor(120) # All ~2000+ commands available3. Universal Command Invocation
using Giac
# Works for ALL commands, including those conflicting with Julia
invoke_cmd(:factor, giac_eval("x^2-1"))
invoke_cmd(:sin, giac_eval("pi/6"))Type Conversion and Introspection
Convert GIAC results to native Julia types:
using Giac
# Boolean conversion
to_julia(giac_eval("true")) # true::Bool
to_julia(giac_eval("1==1")) # true::Bool (comparison result)
to_julia(giac_eval("1")) # 1::Int64 (integer, not boolean)
# Use in control flow
if to_julia(giac_eval("2 > 1"))
println("Works!")
end
# Automatic type conversion
g = giac_eval("[1, 2, 3]")
result = to_julia(g) # Vector{Int64}
# Boolean detection
is_boolean(giac_eval("true")) # true
is_boolean(giac_eval("1")) # false
# Type introspection
using Giac.GenTypes: VECT
giac_type(g) == VECT # true
is_vector(g) # true
# Fraction components
frac = giac_eval("3/4")
numer(frac) # 3
denom(frac) # 4
# Complex components
z = giac_eval("3+4*i")
real_part(z) # 3
imag_part(z) # 4
# Matrix conversion
m = GiacMatrix(giac_eval("[[1, 2], [3, 4]]"))
to_julia(m) # 2×2 Matrix{Int64}Vector Indexing and Iteration
Access GIAC vectors with Julia's native indexing:
using Giac
g = giac_eval("[10, 20, 30]")
g[1] # GiacExpr(10)
g[2] # GiacExpr(20)
# Iterate over elements
for elem in g
println(to_julia(elem))
end
# Collect to Julia vector
to_julia(g) # [10, 20, 30]::Vector{Int64}Infinity Support
Use Julia's native Inf and -Inf in limits and improper integrals:
using Giac
using Giac.Commands: limit, integrate
@giac_var x
# Limits at infinity
limit(1/x, x, Inf) # 0
limit(1/x, x, -Inf) # 0
limit(x^2, x, Inf) # +infinity
# Improper integrals
integrate(exp(-x), x, 0, Inf) # 1
integrate(1/x^2, x, 1, Inf) # 1
integrate(exp(x), x, -Inf, 0) # 1Modules
- Core API: Types, evaluation, and main functions
- Commands: All GIAC commands as functions
- Constants: Symbolic mathematical constants (pi, e, i)
- TempApi: Convenience functions with simple names
Documentation
Getting Started
Mathematics
- Algebra - Factorization, expansion, simplification, solving
- Calculus - Differentiation, integration, limits, series
- Linear Algebra - Matrices, determinants, eigenvalues
- Differential Equations - ODE solving with D operator
- Trigonometry - Identities, simplification, equations
Physics
- Mechanics - Kinematics, dynamics, oscillations, energy
- Electromagnetism - Circuits, fields, waves
API Reference
- Core API - Types, evaluation, and main functions
- Commands Submodule - All GIAC commands as functions
- TempApi - Convenience functions with simple names
Related Projects
- GIAC - The underlying computer algebra system
- libgiac-julia-wrapper - CxxWrap bindings for GIAC
- CxxWrap.jl - C++ wrapper generator for Julia