Core API
The main Giac module provides core types and functions for symbolic computation.
Giac — Module
GiacA Julia wrapper for the GIAC computer algebra system.
Provides symbolic expression evaluation, calculus operations, polynomial manipulation, and linear algebra with a Julia-native API.
Core Exports
GiacExpr: Symbolic expression typeGiacContext: Evaluation contextGiacMatrix: Symbolic matrix typeGiacError: Exception type for GIAC errorsgiac_eval: Evaluate expression strings@giac_var: Create symbolic variables from Julia symbolsto_julia: Convert GiacExpr to Julia typesinvoke_cmd: Universal command invocation (works for ALL commands)
Command Access
GIAC commands are available through the Giac.Commands submodule:
using Giac
# Use invoke_cmd for any command (always available)
invoke_cmd(:factor, giac_eval("x^2-1"))
invoke_cmd(:sin, giac_eval("pi/6")) # Works for conflicting commands too
# Import commands selectively (recommended)
using Giac.Commands: factor, expand, diff
factor(giac_eval("x^2-1"))
# Or import all ~2000+ commands
using Giac.Commands
factor(giac_eval("x^2-1"))
ifactor(giac_eval("120"))Quick Start
using Giac
# Declare symbolic variables with @giac_var macro
@giac_var x y
# Build and manipulate expressions using Giac.Commands
using Giac.Commands: factor, expand, diff
expr = giac_eval("x^2 + 2*x*y + y^2")
result = factor(expr) # (x+y)^2
# Or use string-based evaluation directly
result = giac_eval("factor(x^2 - 1)")
println(result) # (x-1)*(x+1)See also
Giac.Commands: Submodule with all exportable commandsinvoke_cmd: Universal command invocation
Types
Giac.GiacExpr — Type
GiacExprRepresents a symbolic mathematical expression from GIAC.
Wraps a pointer to a C++ giac::gen object. Memory is managed automatically via Julia's garbage collector and finalizers.
Example
expr = giac_eval("x^2 + 1")
println(expr) # x^2+1Giac.GiacContext — Type
GiacContextRepresents a GIAC evaluation context.
Manages configuration settings, variable bindings, and computation state. Thread-safe via internal locking.
Example
ctx = GiacContext()
result = giac_eval("x + 1", ctx)Giac.GiacMatrix — Type
GiacMatrixRepresents a symbolic matrix with GiacExpr elements.
Fields
ptr::Ptr{Cvoid}: Pointer to GIAC matrix objectrows::Int: Number of rowscols::Int: Number of columns
Example
A = GiacMatrix([[a, b], [c, d]])
det(A) # a*d - b*cGiac.GiacError — Type
GiacError <: ExceptionException type for errors from the GIAC library.
Fields
msg::String: Error messagecategory::Symbol: Error category (:parse,:eval,:type,:memory)
Example
throw(GiacError("Failed to parse expression", :parse))Giac.HelpResult — Type
HelpResultA structured representation of parsed GIAC command help information.
Fields
command::String: The command name being documenteddescription::String: Description text from GIAC helprelated::Vector{String}: List of related command namesexamples::Vector{String}: List of individual example expressions
Example
# Use Julia's help system for interactive help:
# ?factor (after using Giac.Commands: factor)
# For programmatic access, use Giac.help (internal) or giac_help:
result = Giac.help(:factor)
result.command # "factor"
result.description # "Factorizes a polynomial."
result.related # ["ifactor", "partfrac", "normal"]
result.examples # ["factor(x^4-1)", "factor(x^4-4,sqrt(2))", ...]See also
giac_help: Get raw help string
Giac.GiacCommand — Type
GiacCommandA callable wrapper for GIAC commands.
This type stores a command name and can be called with arguments to execute the underlying GIAC command. It provides a structured way to represent commands that can be passed around and invoked.
Fields
name::Symbol: The GIAC command name (e.g.,:factor,:diff)
Example
# Create a command and call it
factor_cmd = GiacCommand(:factor)
expr = giac_eval("x^2 - 1")
result = factor_cmd(expr) # Returns (x-1)*(x+1)
# Equivalent to:
result = giac_cmd(:factor, expr)See also
invoke_cmd: Direct command invocation
Giac.GiacInput — Type
GiacInputUnion type representing all valid input types for GIAC command functions.
This type alias enables generated GIAC command functions to accept native Julia types in addition to GiacExpr, providing a more ergonomic API.
Supported Types
GiacExpr: Native GIAC expressionsNumber: All Julia numeric types (Integer, AbstractFloat, Rational, Complex, etc.)String: String representations of GIAC expressionsSymbol: Variable names (e.g.,:x,:y)AbstractVector: Julia vectors/arrays (converted to GIAC list syntax)
Examples
using Giac
using Giac.Commands
# All of these work:
ifactor(1000) # Integer
ifactor(giac_eval("1000")) # GiacExpr
simplify("x^2 - 1") # String
# Vectors work directly (032-vector-input-solve):
@giac x y
solve([x+y~0, x-y~2], [x,y]) # System of equations
det([[1,2],[3,4]]) # Nested vectors for matricesSee also
GiacExpr: The primary GIAC expression typeinvoke_cmd: Universal command invocation
Expression Evaluation
Giac.giac_eval — Function
giac_eval(expr::String, ctx::GiacContext=DEFAULT_CONTEXT[])Evaluate a GIAC expression string and return a GiacExpr.
Arguments
expr::String: A string containing a valid GIAC expressionctx::GiacContext: Optional evaluation context (uses DEFAULT_CONTEXT if not provided)
Returns
GiacExpr: The evaluated expression
Throws
GiacError(:parse): If the expression cannot be parsedGiacError(:eval): If evaluation fails
Example
result = giac_eval("2 + 3")
println(result) # 5
# Symbolic computation
expr = giac_eval("diff(x^2, x)")
println(expr) # 2*xgiac_eval(expr::GiacExpr, ctx::GiacContext=DEFAULT_CONTEXT[])Re-evaluate an existing GiacExpr in a context (useful after variable assignments).
Symbolic Variables
Giac.@giac_var — Macro
@giac_var sym...
@giac_var func(args...)Create symbolic variables or function expressions from Julia symbols.
Creates GiacExpr variables in the calling scope by internally calling giac_eval with the stringified expression. This provides a cleaner syntax for variable declaration similar to @variables in Symbolics.jl.
Arguments
sym...: Symbol names to create as simple variablesfunc(args...): Function syntax to create function expressions
Examples
Single variable:
@giac_var x # Creates x as a GiacExpr
string(x) # "x"
x isa GiacExpr # trueMultiple variables:
@giac_var x y z # Creates x, y, z as GiacExpr variablesSingle-variable function (NEW):
@giac_var u(t) # Creates u as GiacExpr representing "u(t)"
string(u) # "u(t)"
# Use with differentiation
@giac_var t
diff(u, t) # Returns diff(u(t),t)Multi-variable function (NEW):
@giac_var f(x, y) # Creates f as GiacExpr representing "f(x,y)"
string(f) # "f(x,y)"Mixed declarations (NEW):
@giac_var t x y u(t) f(x, y)
# Creates: t, x, y as simple variables
# u as "u(t)", f as "f(x,y)"Usage
using Giac
@giac_var x y
expr = giac_eval("x^2 + y^2")
result = giac_diff(expr, x) # 2*x
# For ODEs
@giac_var t u(t)
# u''(t) + u(t) = 0
# Callable syntax for initial conditions (034-callable-giacexpr)
@giac_var t u(t) tau U0
u(0) # Returns GiacExpr: "u(0)"
u(0) ~ 1 # Initial condition: u(0) = 1
diff(u, t)(0) ~ 0 # Derivative condition: u'(0) = 0
desolve([tau * diff(u, t) + u ~ U0, u(0) ~ 1], u)See also
giac_eval: For evaluating string expressions
Giac.@giac_several_vars — Macro
@giac_several_vars base dims...Create multiple indexed symbolic variables for N-dimensional tensors.
This macro generates multiple GiacExpr variables in the calling scope with names formed from a base name and indices. It supports any number of dimensions and returns a tuple of all created variables.
Arguments
base: Symbol - The base name for variables (e.g.,a,coeff,α)dims...: Integer literals or range expressions - Dimensions of the tensor (1 or more)- Integer
n: Creates indices 1:n (backward compatible) - UnitRange
a:b: Creates indices from a to b - StepRange
a:s:b: Creates indices from a to b with step s
- Integer
Returns
Tuple{GiacExpr...}: A tuple containing all created variables in lexicographic order
Naming Convention
- If all indices are in 0-9: indices are concatenated directly (e.g.,
a123) - If any index > 9: underscore separators are used (e.g.,
a_1_10) - Negative indices:
mprefix for minus (e.g., -1 →m1, soc_m1)
Examples
1D vector:
@giac_several_vars a 3
# Creates: a1, a2, a3 and returns (a1, a2, a3)
a1 + a2 + a3 # Symbolic sum
# Capture return value
vars = @giac_several_vars c 4
length(vars) # 42D matrix:
result = @giac_several_vars m 2 3
# Creates: m11, m12, m13, m21, m22, m23
# Returns: (m11, m12, m13, m21, m22, m23)
length(result) # 63D tensor:
@giac_several_vars t 2 2 2
# Creates: t111, t112, t121, t122, t211, t212, t221, t222
# Returns tuple of 8 variablesLarge dimensions (separator used):
@giac_several_vars b 2 10 3
# Creates: b_1_1_1, b_1_1_2, ..., b_2_10_3Unicode base names:
@giac_several_vars α 2
# Creates: α1, α20-based indexing with UnitRange:
@giac_several_vars psi 0:2
# Creates: psi0, psi1, psi2 and returns (psi0, psi1, psi2)2D with custom ranges:
@giac_several_vars T 0:1 0:2
# Creates: T00, T01, T02, T10, T11, T12Negative indices:
@giac_several_vars c -1:1
# Creates: c_m1, c_0, c_1 (m = minus, to avoid GIAC parsing issues)StepRange:
@giac_several_vars q 0:2:4
# Creates: q0, q2, q4Mixed arguments (integer and range):
@giac_several_vars mixed 2 0:1
# First dim: 1:2, second dim: 0:1
# Creates: mixed10, mixed11, mixed20, mixed21Edge cases:
@giac_several_vars x 0 # Returns empty tuple ()
@giac_several_vars y 1 # Creates y1, returns (y1,)
@giac_several_vars z 2 0 # Returns empty tuple (0 in any dim)
@giac_several_vars e 5:4 # Returns empty tuple (empty range)See also
Function Syntax for @giac_var
The @giac_var macro supports function notation for defining symbolic functions that depend on other variables. This is useful for differential equations and calculus with unknown functions.
Single-variable functions:
@giac_var u(t) # u is a GiacExpr representing "u(t)"
@giac_var t # t is the independent variable
diff(u, t) # Symbolic derivative of u with respect to tMulti-variable functions:
@giac_var f(x, y) # f represents "f(x,y)"
@giac_var x y
diff(f, x) # Partial derivative ∂f/∂x
diff(f, y) # Partial derivative ∂f/∂yMixed declarations:
@giac_var t x y u(t) f(x, y)
# Creates: t, x, y as simple variables
# u as "u(t)", f as "f(x,y)"Common use case - ODEs:
@giac_var t u(t)
# Express ODE: u''(t) + u(t) = 0Common use case - PDEs:
@giac_var x y u(x, y)
# Laplacian: ∂²u/∂x² + ∂²u/∂y²
laplacian = diff(diff(u, x), x) + diff(diff(u, y), y)Callable GiacExpr (Function Evaluation)
GiacExpr objects are callable, allowing natural function evaluation syntax like u(0). This is essential for specifying ODE initial conditions.
Basic function evaluation:
@giac_var u(t)
u(0) # Returns GiacExpr: "u(0)"
u(1) # Returns GiacExpr: "u(1)"ODE initial conditions:
using Giac.Commands: diff, desolve
@giac_var t u(t) tau U0
# ODE: τu' + u = U₀ with u(0) = 1
ode = tau * diff(u, t) + u ~ U0
initial = u(0) ~ 1
desolve([ode, initial], u)Derivative initial conditions (using D operator):
using Giac.Commands: desolve
@giac_var t u(t)
# First derivative at t=0: u'(0) = 1
D(u)(0) ~ 1
# Second derivative at t=0: u''(0) = 0
D(u, 2)(0) ~ 0
# Full example: solve u'' + u = 0 with u(0)=1, u'(0)=0
ode = D(D(u)) + u ~ 0
u0 = u(0) ~ 1
du0 = D(u)(0) ~ 0
desolve([ode, u0, du0], t, :u) # Returns: cos(t)D Operator (Derivative Operator)
The D operator follows SciML/ModelingToolkit conventions for expressing derivatives:
@giac_var t u(t)
# Create derivative expressions
D(u) # First derivative u'
D(D(u)) # Second derivative u'' (chained)
D(u, 2) # Second derivative u'' (direct)
D(u, 3) # Third derivative u'''
# Use in ODE equations
ode = D(D(u)) + u ~ 0 # u'' + u = 0
# Use in initial conditions (produces prime notation for GIAC)
D(u)(0) ~ 1 # u'(0) = 1
D(u, 2)(0) ~ 0 # u''(0) = 0Complete ODE examples:
using Giac
using Giac.Commands: desolve
# 2nd order: u'' + u = 0, u(0)=1, u'(0)=0
@giac_var t u(t)
result = desolve([D(D(u)) + u ~ 0, u(0) ~ 1, D(u)(0) ~ 0], t, :u)
# Returns: cos(t)
# 3rd order: y''' - y = 0, y(0)=1, y'(0)=1, y''(0)=1
@giac_var t y(t)
result = desolve([D(y,3) - y ~ 0, y(0) ~ 1, D(y)(0) ~ 1, D(y,2)(0) ~ 1], t, :y)
# Returns: exp(t)When calling desolve, pass the function name as a Symbol (:u, :y) rather than the function expression (u, y), since GIAC expects just the name, not u(t).
Multi-variable function evaluation:
@giac_var f(x, y) a b
f(0, 0) # Returns "f(0,0)"
f(a, b) # Returns "f(a,b)"
f(1, 2) # Returns "f(1,2)"Calculus Operations
Calculus functions are available via Giac.Commands or invoke_cmd:
using Giac
using Giac.Commands: diff, integrate, limit, series
# Or use invoke_cmd
invoke_cmd(:diff, expr, x)
invoke_cmd(:integrate, expr, x)
invoke_cmd(:limit, expr, x, point)
invoke_cmd(:series, expr, x, point, order)Algebraic Operations
Algebra functions are available via Giac.Commands or invoke_cmd:
using Giac
using Giac.Commands: factor, expand, simplify, solve, gcd
# Or use invoke_cmd
invoke_cmd(:factor, expr)
invoke_cmd(:expand, expr)
invoke_cmd(:simplify, expr)
invoke_cmd(:solve, expr, x)
invoke_cmd(:gcd, a, b)Vector Input Support
GIAC commands accept Julia vectors directly, enabling natural syntax for systems of equations and matrix operations:
using Giac
using Giac.Commands: solve, det_minor, inverse
@giac_var x y z
# Solve systems of equations with vector syntax
solve([x + y ~ 1, x - y ~ 0], [x, y]) # Returns [[1/2, 1/2]]
# Three-variable system
solve([x + y + z ~ 6, x - y ~ 0, y + z ~ 4], [x, y, z])
# Matrix operations with nested vectors
det_minor([[1, 2], [3, 4]]) # Returns -2
inverse([[1, 2], [3, 4]]) # Returns inverse matrixSee GiacInput for the full list of supported input types.
GiacMatrix Command Support
GiacMatrix objects can be passed directly to GIAC commands, both via invoke_cmd and generated command functions:
using Giac
using Giac.Commands: eigenvals, trace
M = GiacMatrix([[1, 2], [3, 4]])
# Direct command calls
eigenvals(M) # Returns eigenvalues
trace(M) # Returns 5
# Via invoke_cmd (works for all commands including Base-conflicting ones)
invoke_cmd(:det, M) # Returns -2
invoke_cmd(:transpose, M) # Returns transposed matrix
invoke_cmd(:eigenvals, M) # Returns eigenvaluesCommand Discovery
Giac.list_commands — Function
list_commands()Return a vector of all available GIAC command names.
Example
cmds = list_commands()
println("Number of commands: ", length(cmds))
println("First 10: ", cmds[1:10])Giac.help_count — Function
help_count()Return the number of commands in the GIAC help database.
Giac.search_commands — Function
search_commands(pattern::String) -> Vector{Symbol}Search for commands matching a string prefix.
Arguments
pattern::String: Prefix to match
Returns
Vector{Symbol}: List of matching command names (as Symbols), sorted alphabetically
Example
search_commands("sin") # Returns [:sin, :sinc, :sincos, :sinh, ...]search_commands(pattern::Regex) -> Vector{Symbol}Search for commands matching a regular expression.
Arguments
pattern::Regex: Regular expression to match
Returns
Vector{Symbol}: List of matching command names (as Symbols), sorted alphabetically
Example
search_commands(r"^a.*n$") # Returns commands starting with 'a' and ending with 'n'Giac.commands_in_category — Function
commands_in_category(category::Symbol) -> Vector{Symbol}Get all commands in a specific category.
Arguments
category::Symbol: Category name (e.g.,:trigonometry,:algebra)
Returns
Vector{Symbol}: List of command names (as Symbols) in the category, sorted alphabetically
Throws
ArgumentError: If the category does not exist
Example
trig = commands_in_category(:trigonometry)
# [:acos, :asin, :atan, :cos, :sin, :tan, ...]Giac.command_info — Function
command_info(cmd::Symbol) -> Union{CommandInfo, Nothing}Get metadata about a specific command.
Arguments
cmd::Symbol: Command name
Returns
CommandInfo: Metadata about the commandnothing: If the command is not found
Example
info = command_info(:factor)
if info !== nothing
println(info.name) # "factor"
println(info.category) # :algebra
endGiac.list_categories — Function
list_categories() -> Vector{Symbol}List all available command categories.
Returns
Vector{Symbol}: Category names, sorted alphabetically
Example
cats = list_categories()
# [:algebra, :calculus, :combinatorics, :geometry, ...]Giac.giac_help — Function
giac_help(cmd::Union{Symbol, String}) -> StringGet GIAC help text for a command.
Arguments
cmd: Command name as Symbol or String
Returns
String: Help text from GIAC, or empty string if not found
Example
help = giac_help(:factor)
println(help) # "factor(Expr) - Factor a polynomial..."Use Julia's native help system after importing commands:
using Giac.Commands: factor
?factor # Shows GIAC documentationCommand Suggestions
Giac.suggest_commands — Function
suggest_commands(input::Union{Symbol, String}; n::Int=get_suggestion_count()) -> Vector{Symbol}Find commands similar to the given input using edit distance.
This function helps users recover from typos by suggesting valid GIAC commands that are similar to the input.
Arguments
input: The mistyped command name (Symbol or String)n: Maximum number of suggestions to return (default:get_suggestion_count())
Returns
Vector{Symbol}: Similar command names, sorted by edit distance (ascending), then alphabetically. Returns empty vector if no similar commands found.
Example
suggest_commands(:factr)
# [:factor, :cfactor, :ifactor, ...]
suggest_commands("integrat", n=2)
# [:integrate, ...]
suggest_commands(:factor) # Exact match
# [] (empty, no suggestions needed)See also
suggest_commands_with_distances: Also returns edit distances (internal function)set_suggestion_count: Configure default suggestion count
Giac.set_suggestion_count — Function
set_suggestion_count(n::Int) -> NothingSet the default number of command suggestions.
Arguments
n: Number of suggestions (must be > 0, otherwise resets to default 4)
Example
set_suggestion_count(6)
get_suggestion_count() # 6
set_suggestion_count(-1) # Invalid, resets to default
get_suggestion_count() # 4See also
get_suggestion_count: Get the current count
Giac.get_suggestion_count — Function
get_suggestion_count() -> IntGet the current default number of command suggestions.
Returns
Int: Current suggestion count (default: 4)
Example
get_suggestion_count() # 4 (default)See also
set_suggestion_count: Set the suggestion count
Giac.search_commands_by_description — Function
search_commands_by_description(query; n=20) -> Vector{Symbol}Search for GIAC commands whose help text contains the given keyword.
Unlike search_commands which matches command names, this function searches the description and example text of each command's help documentation.
Arguments
query::Union{String, Symbol}: Search term to find in help textn::Int=20: Maximum number of results to return
Returns
Vector{Symbol}: Matching command names (as Symbols), sorted by relevance
Example
# Find commands related to factorization
search_commands_by_description("factor")
# Returns: [:factor, :ifactor, :cfactor, ...]
# Search for matrix operations
search_commands_by_description("matrix", n=10)See also
search_commands: Search by command name patterngiac_help: Get raw help for a specific command
Namespace Management
Giac.JULIA_CONFLICTS — Constant
JULIA_CONFLICTSSet of GIAC command names (as Symbols) that conflict with Julia keywords, builtins, or standard library functions. These commands cannot be safely exported as top-level functions but remain accessible via invoke_cmd(:name, args...).
Conflict Categories
- Julia keywords:
if,for,while,end,in,or,and, etc. - Base builtins:
eval,float,sum,prod,div,mod,abs, etc. - Base math functions:
sin,cos,tan,exp,log,sqrt, etc. - LinearAlgebra:
det,inv,trace,rank,transpose, etc.
Example
:eval in JULIA_CONFLICTS # true
:factor in JULIA_CONFLICTS # false
# Conflicting commands still work via invoke_cmd
invoke_cmd(:eval, giac_eval("2+3")) # Returns 5See also
exportable_commands: Commands safe to exportconflict_reason: Get the conflict category for a command
Giac.exportable_commands — Function
exportable_commands() -> Vector{Symbol}Get a list of GIAC commands that can be safely exported without conflicting with Julia keywords, builtins, or standard library functions.
This function filters the complete command list to include only commands that:
- Start with an ASCII letter (a-z, A-Z)
- Do not conflict with Julia (not in
JULIA_CONFLICTS)
Returns
Vector{Symbol}: Sorted list of exportable command names (as Symbols)
Example
cmds = exportable_commands()
length(cmds) # ~2000+
:factor in cmds # true
:eval in cmds # false (conflicts with Julia)
:sin in cmds # false (conflicts with Base.sin)
issorted(cmds, by=string) # trueSee also
available_commands: All commands starting with ASCII lettersJULIA_CONFLICTS: Commands that conflict with Julia
Giac.is_valid_command — Function
is_valid_command(name::Union{Symbol, String}) -> BoolCheck if a command name is a valid GIAC command.
Arguments
name: Command name as Symbol or String
Returns
trueif the command exists in GIAC's command listfalseotherwise
Example
is_valid_command(:factor) # true
is_valid_command("integrate") # true
is_valid_command(:notacommand) # falseSee also
list_commands: Get all command namessuggest_commands: Get suggestions for misspelled commands
Giac.conflict_reason — Function
conflict_reason(cmd::Union{Symbol, String}) -> Union{Symbol, Nothing}Get the reason why a GIAC command conflicts with Julia.
Arguments
cmd: Command name as Symbol or String
Returns
:keyword- Conflicts with Julia keyword (if, for, while, etc.):builtin- Conflicts with Julia builtin function (eval, float, etc.):base_math- Conflicts with Base math function (sin, cos, exp, etc.):linear_algebra- Conflicts with LinearAlgebra (det, inv, trace, etc.):statistics- Conflicts with Statistics (mean, median, var, etc.)nothing- No conflict
Example
conflict_reason(:eval) # :builtin
conflict_reason(:sin) # :base_math
conflict_reason(:det) # :linear_algebra
conflict_reason(:for) # :keyword
conflict_reason(:factor) # nothingSee also
JULIA_CONFLICTS: Set of all conflicting commandsexportable_commands: Commands safe to export
Giac.available_commands — Function
available_commands()Return a sorted vector of all available GIAC command names that start with an ASCII letter (a-z, A-Z).
This function provides programmatic discovery of available commands. It filters out operators, keywords, and commands starting with non-ASCII characters.
Returns
Vector{String}: Sorted list of command names starting with ASCII letters
Example
# List all available commands
cmds = available_commands()
println("Found $(length(cmds)) commands") # ~2100+
# Check if a command exists
"factor" in cmds # true
"+" in cmds # false (operator)
# Compare with exportable commands
exportable = exportable_commands()
length(exportable) # ~2000+ (excludes Julia conflicts)Accessing Commands
invoke_cmd (all commands): Universal access, always available
invoke_cmd(:eval, expr) # Works for conflicting commands too invoke_cmd(:factor, expr)Selective import: Import specific commands from Giac.Commands
using Giac.Commands: factor, expand factor(expr) # Works directlyFull import: Import all ~2000+ commands
using Giac.Commands factor(expr) # Works directly ifactor(expr) # All commands available
See also
exportable_commands: Commands safe to export (no Julia conflicts)invoke_cmd: Universal command invocationGiac.Commands: Submodule with all exportable commands
Giac.reset_conflict_warnings! — Function
reset_conflict_warnings!()Reset the conflict warning tracker, allowing warnings to be shown again.
This is primarily useful for testing.
Example
giac_cmd(:eval, expr) # Shows warning
giac_cmd(:eval, expr) # No warning (already shown)
reset_conflict_warnings!()
giac_cmd(:eval, expr) # Shows warning againSubstitution
See Variable Substitution for the substitute function documentation.
Type Introspection
Functions for querying the type of GIAC expressions:
Giac.giac_type — Function
giac_type(g::GiacExpr) -> TReturn the GIAC type enum value for the expression.
Returns one of the T enum values from Giac.GenTypes: INT, DOUBLE, ZINT, REAL, CPLX, VECT, SYMB, IDNT, STRNG, FRAC, FUNC, etc.
Example
using Giac.GenTypes: T, INT, VECT
g = giac_eval("42")
giac_type(g) == INT # true
g = giac_eval("[1, 2, 3]")
giac_type(g) == VECT # trueSee also: Giac.GenTypes module for type enum values
Giac.subtype — Function
subtype(g::GiacExpr) -> Int32Return the subtype for vector expressions.
For vectors, returns 1 (sequence), 2 (set), 3 (list), or 0 for standard vectors.
Example
g = giac_eval("{1, 2, 3}") # set
subtype(g) == 2 # true (set subtype)Giac.is_integer — Function
is_integer(g::GiacExpr) -> BoolReturn true if the expression is an integer (INT or ZINT).
Example
is_integer(giac_eval("42")) # true
is_integer(giac_eval("3.14")) # false
is_integer(giac_eval("x")) # falseGiac.is_numeric — Function
is_numeric(g::GiacExpr) -> BoolReturn true if the expression is a numeric value (INT, DOUBLE, ZINT, or REAL).
Example
is_numeric(giac_eval("42")) # true
is_numeric(giac_eval("3.14")) # true
is_numeric(giac_eval("x")) # falseGiac.is_vector — Function
is_vector(g::GiacExpr) -> BoolReturn true if the expression is a vector/list/sequence (VECT).
Example
is_vector(giac_eval("[1, 2, 3]")) # true
is_vector(giac_eval("42")) # falseGiac.is_symbolic — Function
is_symbolic(g::GiacExpr) -> BoolReturn true if the expression is symbolic (SYMB).
Example
is_symbolic(giac_eval("sin(x)")) # true
is_symbolic(giac_eval("x + 1")) # true
is_symbolic(giac_eval("42")) # falseGiac.is_identifier — Function
is_identifier(g::GiacExpr) -> BoolReturn true if the expression is an identifier/variable (IDNT).
Example
is_identifier(giac_eval("x")) # true
is_identifier(giac_eval("x + 1")) # falseGiac.is_fraction — Function
is_fraction(g::GiacExpr) -> BoolReturn true if the expression is a rational fraction (FRAC).
Example
is_fraction(giac_eval("3/4")) # true
is_fraction(giac_eval("42")) # falseGiac.is_complex — Function
is_complex(g::GiacExpr) -> BoolReturn true if the expression is a complex number (CPLX).
Example
is_complex(giac_eval("3+4*i")) # true
is_complex(giac_eval("42")) # falseGiac.is_string — Function
is_string(g::GiacExpr) -> BoolReturn true if the expression is a string (STRNG).
Example
is_string(giac_eval(""hello"")) # true
is_string(giac_eval("42")) # falseGiac.is_boolean — Function
is_boolean(g::GiacExpr) -> BoolReturn true if the expression represents a boolean value (true or false).
Note: GIAC represents booleans as integers internally (type INT), but displays them as "true" or "false". This function detects boolean values by checking the string representation.
Example
is_boolean(giac_eval("true")) # true
is_boolean(giac_eval("false")) # true
is_boolean(giac_eval("1==1")) # true (comparison returns boolean)
is_boolean(giac_eval("1")) # false (integer, not boolean)
is_boolean(giac_eval("0")) # false (integer, not boolean)See also
Type Enum (GenTypes)
GIAC expression types are available via the Giac.GenTypes module with the T enum:
using Giac.GenTypes: T, INT, DOUBLE, VECT, SYMB
giac_type(expr) == INT # Check if expression is an integer
giac_type(expr) == VECT # Check if expression is a vector| Enum Value | Int | Description |
|---|---|---|
INT | 0 | Machine integer (Int64) |
DOUBLE | 1 | Double-precision float (Float64) |
ZINT | 2 | Arbitrary-precision integer (BigInt) |
REAL | 3 | Extended precision real |
CPLX | 4 | Complex number |
POLY | 5 | Polynomial |
IDNT | 6 | Identifier/variable |
VECT | 7 | Vector/list/sequence |
SYMB | 8 | Symbolic expression |
SPOL1 | 9 | Sparse polynomial |
FRAC | 10 | Rational fraction |
EXT | 11 | Algebraic extension |
STRNG | 12 | String value |
FUNC | 13 | Function reference |
ROOT | 14 | Polynomial root |
MOD | 15 | Modular arithmetic |
USER | 16 | User-defined type |
MAP | 17 | Map/dictionary |
EQW | 18 | Equation writer data |
GROB | 19 | Graphic object |
POINTER | 20 | Raw pointer |
FLOAT | 21 | Float value |
Giac.GenTypes — Module
GenTypesA submodule containing the T enum for GIAC expression type constants.
This module provides type-safe, scoped access to GIAC's internal type system, matching the C++ gen_unary_types enum exactly.
Usage
using Giac.GenTypes: T, INT, VECT, SYMB
# Access type constants as module values
INT # Machine integer (0)
DOUBLE # Double-precision float (1)
VECT # Vector/list/sequence (7)
SYMB # Symbolic expression (8)
# Or use the T type for construction from integers
T(0) # INT
T(7) # VECT
# Use with giac_type()
expr = giac_eval("42")
giac_type(expr) == INT # true
# Convert to integer
Int(VECT) # 7Type Values
The enum values match the C++ gen_unary_types enum:
- Types 0-1 and 20-21 are "immediate" (no memory allocation)
- Types 2-19 are "pointer" types (require memory allocation)
See also: Giac.giac_type
Giac.GenTypes.T — Type
TEnum representing GIAC expression types, matching C++ gen_unary_types.
Values
| Value | Int | C++ Name | Description |
|---|---|---|---|
T.INT | 0 | _INT_ | Machine integer |
T.DOUBLE | 1 | _DOUBLE_ | Double-precision float |
T.ZINT | 2 | _ZINT | Arbitrary precision integer |
T.REAL | 3 | _REAL | Extended precision real |
T.CPLX | 4 | _CPLX | Complex number |
T.POLY | 5 | _POLY | Polynomial |
T.IDNT | 6 | _IDNT | Identifier/variable |
T.VECT | 7 | _VECT | Vector/list/sequence |
T.SYMB | 8 | _SYMB | Symbolic expression |
T.SPOL1 | 9 | _SPOL1 | Sparse polynomial |
T.FRAC | 10 | _FRAC | Rational fraction |
T.EXT | 11 | _EXT | Algebraic extension |
T.STRNG | 12 | _STRNG | String |
T.FUNC | 13 | _FUNC | Function reference |
T.ROOT | 14 | _ROOT | Root of polynomial |
T.MOD | 15 | _MOD | Modular arithmetic |
T.USER | 16 | _USER | User-defined type |
T.MAP | 17 | _MAP | Map/dictionary |
T.EQW | 18 | _EQW | Equation writer data |
T.GROB | 19 | _GROB | Graphic object |
T.POINTER | 20 | _POINTER_ | Raw pointer |
T.FLOAT | 21 | _FLOAT_ | Float (immediate) |
Examples
using Giac.GenTypes: T, INT, VECT, FLOAT
# Check integer value
Int(INT) == 0 # true
Int(VECT) == 7 # true
Int(FLOAT) == 21 # true
# Create from integer
T(0) == INT # true
T(7) == VECT # trueComponent Access
Functions for accessing components of compound types:
Giac.numer — Function
numer(g::GiacExpr) -> GiacExprReturn the numerator of a fraction, or the value itself for integers.
Example
numer(giac_eval("3/4")) # GiacExpr representing 3
numer(giac_eval("5")) # GiacExpr representing 5Giac.denom — Function
denom(g::GiacExpr) -> GiacExprReturn the denominator of a fraction, or 1 for integers.
Example
denom(giac_eval("3/4")) # GiacExpr representing 4
denom(giac_eval("5")) # GiacExpr representing 1Giac.real_part — Function
real_part(g::GiacExpr) -> GiacExprReturn the real part of a complex number, or the value itself for non-complex.
Example
real_part(giac_eval("3+4*i")) # GiacExpr representing 3
real_part(giac_eval("5")) # GiacExpr representing 5Giac.imag_part — Function
imag_part(g::GiacExpr) -> GiacExprReturn the imaginary part of a complex number, or 0 for non-complex.
Example
imag_part(giac_eval("3+4*i")) # GiacExpr representing 4
imag_part(giac_eval("5")) # GiacExpr representing 0Giac.symb_funcname — Function
symb_funcname(g::GiacExpr) -> StringReturn the function name of a symbolic expression.
Example
symb_funcname(giac_eval("sin(x)")) # "sin"Giac.symb_argument — Function
symb_argument(g::GiacExpr) -> GiacExprReturn the argument (operand) of a symbolic expression.
Example
arg = symb_argument(giac_eval("sin(x)")) # GiacExpr representing xJulia Standard Interface
Base.numerator and Base.denominator are also extended for GiacExpr, delegating to GIAC's numer/denom commands. These handle both numeric and symbolic fractions:
numerator(giac_eval("25/15")) # 5
denominator(giac_eval("25/15")) # 3
@giac_var x
numerator((x^3 - 1) / (x^2 - 1)) # x^2+x+1
denominator((x^3 - 1) / (x^2 - 1)) # x+1Conversion Functions
Giac.to_julia — Function
to_julia(m::GiacMatrix) -> MatrixConvert a GiacMatrix to a Julia Matrix with appropriate element type narrowing.
Boolean elements are converted to Bool, integers to Int64, etc. The resulting matrix type is narrowed to the most specific common type.
Example
# Integer matrix
g = giac_eval("[[1, 2], [3, 4]]")
m = GiacMatrix(g)
to_julia(m) # 2×2 Matrix{Int64}
# Boolean matrix
g = giac_eval("[[true, false], [false, true]]")
m = GiacMatrix(g)
to_julia(m) # 2×2 Matrix{Bool}See also
to_julia(g::GiacExpr) -> Union{Bool, Int64, BigInt, Float64, Rational, Complex, Vector, String, GiacExpr}Recursively convert a GIAC expression to native Julia types.
Conversion Rules
| GIAC Type | Julia Return Type |
|---|---|
Boolean (true/false) | Bool |
INT | Int64 |
ZINT | BigInt |
DOUBLE, REAL | Float64 |
FRAC | Rational{Int64} or Rational{BigInt} |
CPLX | Complex{T} (T promoted from parts) |
VECT | Vector{T} (T narrowed from elements) |
STRNG | String |
SYMB, IDNT, FUNC | GiacExpr (unchanged) |
Note: GIAC represents booleans as integers internally, but to_julia detects them via their string representation ("true"/"false") and returns Julia Bool values.
Examples
# Boolean conversion
to_julia(giac_eval("true")) # true::Bool
to_julia(giac_eval("false")) # false::Bool
to_julia(giac_eval("1==1")) # true::Bool (comparison result)
# Integer conversion (distinct from booleans)
to_julia(giac_eval("1")) # Int64(1)
to_julia(giac_eval("0")) # Int64(0)
to_julia(giac_eval("42")) # Int64(42)
# Float conversion
to_julia(giac_eval("3.14")) # Float64(3.14)
# Rational conversion
to_julia(giac_eval("3/4")) # 3//4
# Complex conversion
to_julia(giac_eval("3+4*i")) # 3.0 + 4.0im
# Vector conversion with type narrowing
to_julia(giac_eval("[1, 2, 3]")) # [1, 2, 3]::Vector{Int64}
# Symbolic expressions are unchanged
to_julia(giac_eval("x + 1")) # GiacExpr (unchanged)See also
Giac.to_giac — Function
to_giac(expr)Convert an expression to GiacExpr. Extended by GiacSymbolicsExt for Symbolics.Num types and by GiacMathJSONExt for MathJSON.AbstractMathJSONExpr types.
Giac.to_symbolics — Function
to_symbolics(expr::GiacExpr)Convert a GiacExpr to a Symbolics.jl expression. Extended by GiacSymbolicsExt.
Utility Functions
Giac.is_stub_mode — Function
is_stub_mode()Check if the wrapper is running in stub mode (without the actual library).
Core Functions
| Function | Description |
|---|---|
giac_eval(expr) | Evaluate a GIAC expression string |
invoke_cmd(cmd, args...) | Invoke any GIAC command dynamically |
is_stub_mode() | Check if running without GIAC library |
to_julia(expr) | Convert GiacExpr to Julia type |