Core API

The main Giac module provides core types and functions for symbolic computation.

GiacModule
Giac

A 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 type
  • GiacContext: Evaluation context
  • GiacMatrix: Symbolic matrix type
  • GiacError: Exception type for GIAC errors
  • giac_eval: Evaluate expression strings
  • @giac_var: Create symbolic variables from Julia symbols
  • to_julia: Convert GiacExpr to Julia types
  • invoke_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

source

Types

Giac.GiacExprType
GiacExpr

Represents 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+1
source
Giac.GiacContextType
GiacContext

Represents 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)
source
Giac.GiacMatrixType
GiacMatrix

Represents a symbolic matrix with GiacExpr elements.

Fields

  • ptr::Ptr{Cvoid}: Pointer to GIAC matrix object
  • rows::Int: Number of rows
  • cols::Int: Number of columns

Example

A = GiacMatrix([[a, b], [c, d]])
det(A)  # a*d - b*c
source
Giac.GiacErrorType
GiacError <: Exception

Exception type for errors from the GIAC library.

Fields

  • msg::String: Error message
  • category::Symbol: Error category (:parse, :eval, :type, :memory)

Example

throw(GiacError("Failed to parse expression", :parse))
source
Giac.HelpResultType
HelpResult

A structured representation of parsed GIAC command help information.

Fields

  • command::String: The command name being documented
  • description::String: Description text from GIAC help
  • related::Vector{String}: List of related command names
  • examples::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

source
Giac.GiacCommandType
GiacCommand

A 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

source
Giac.GiacInputType
GiacInput

Union 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 expressions
  • Number: All Julia numeric types (Integer, AbstractFloat, Rational, Complex, etc.)
  • String: String representations of GIAC expressions
  • Symbol: 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 matrices

See also

source

Expression Evaluation

Giac.giac_evalFunction
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 expression
  • ctx::GiacContext: Optional evaluation context (uses DEFAULT_CONTEXT if not provided)

Returns

  • GiacExpr: The evaluated expression

Throws

  • GiacError(:parse): If the expression cannot be parsed
  • GiacError(: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*x
source
giac_eval(expr::GiacExpr, ctx::GiacContext=DEFAULT_CONTEXT[])

Re-evaluate an existing GiacExpr in a context (useful after variable assignments).

source

Symbolic Variables

Giac.@giac_varMacro
@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 variables
  • func(args...): Function syntax to create function expressions

Examples

Single variable:

@giac_var x           # Creates x as a GiacExpr
string(x)             # "x"
x isa GiacExpr        # true

Multiple variables:

@giac_var x y z       # Creates x, y, z as GiacExpr variables

Single-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

source
Giac.@giac_several_varsMacro
@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

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: m prefix for minus (e.g., -1 → m1, so c_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)  # 4

2D matrix:

result = @giac_several_vars m 2 3
# Creates: m11, m12, m13, m21, m22, m23
# Returns: (m11, m12, m13, m21, m22, m23)
length(result)  # 6

3D tensor:

@giac_several_vars t 2 2 2
# Creates: t111, t112, t121, t122, t211, t212, t221, t222
# Returns tuple of 8 variables

Large dimensions (separator used):

@giac_several_vars b 2 10 3
# Creates: b_1_1_1, b_1_1_2, ..., b_2_10_3

Unicode base names:

@giac_several_vars α 2
# Creates: α1, α2

0-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, T12

Negative 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, q4

Mixed arguments (integer and range):

@giac_several_vars mixed 2 0:1
# First dim: 1:2, second dim: 0:1
# Creates: mixed10, mixed11, mixed20, mixed21

Edge 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

  • @giac_var: For creating single symbolic variables
  • giac_eval: For evaluating string expressions
source

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 t

Multi-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/∂y

Mixed 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) = 0

Common 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) = 0

Complete 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)
desolve function argument

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 matrix

See 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 eigenvalues

Command Discovery

Giac.list_commandsFunction
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])
source
Giac.search_commandsFunction
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, ...]
source
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'
source
Giac.commands_in_categoryFunction
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, ...]
source
Giac.command_infoFunction
command_info(cmd::Symbol) -> Union{CommandInfo, Nothing}

Get metadata about a specific command.

Arguments

  • cmd::Symbol: Command name

Returns

  • CommandInfo: Metadata about the command
  • nothing: If the command is not found

Example

info = command_info(:factor)
if info !== nothing
    println(info.name)      # "factor"
    println(info.category)  # :algebra
end
source
Giac.list_categoriesFunction
list_categories() -> Vector{Symbol}

List all available command categories.

Returns

  • Vector{Symbol}: Category names, sorted alphabetically

Example

cats = list_categories()
# [:algebra, :calculus, :combinatorics, :geometry, ...]
source
Giac.giac_helpFunction
giac_help(cmd::Union{Symbol, String}) -> String

Get 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..."
source
Getting Help for Commands

Use Julia's native help system after importing commands:

using Giac.Commands: factor
?factor  # Shows GIAC documentation

Command Suggestions

Giac.suggest_commandsFunction
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
source
Giac.set_suggestion_countFunction
set_suggestion_count(n::Int) -> Nothing

Set 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()  # 4

See also

source
Giac.get_suggestion_countFunction
get_suggestion_count() -> Int

Get the current default number of command suggestions.

Returns

  • Int: Current suggestion count (default: 4)

Example

get_suggestion_count()  # 4 (default)

See also

source
Giac.search_commands_by_descriptionFunction
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 text
  • n::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

source

Namespace Management

Giac.JULIA_CONFLICTSConstant
JULIA_CONFLICTS

Set 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 5

See also

source
Giac.exportable_commandsFunction
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:

  1. Start with an ASCII letter (a-z, A-Z)
  2. 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)  # true

See also

source
Giac.is_valid_commandFunction
is_valid_command(name::Union{Symbol, String}) -> Bool

Check if a command name is a valid GIAC command.

Arguments

  • name: Command name as Symbol or String

Returns

  • true if the command exists in GIAC's command list
  • false otherwise

Example

is_valid_command(:factor)      # true
is_valid_command("integrate")  # true
is_valid_command(:notacommand) # false

See also

source
Giac.conflict_reasonFunction
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)  # nothing

See also

source
Giac.available_commandsFunction
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

  1. invoke_cmd (all commands): Universal access, always available

    invoke_cmd(:eval, expr)  # Works for conflicting commands too
    invoke_cmd(:factor, expr)
  2. Selective import: Import specific commands from Giac.Commands

    using Giac.Commands: factor, expand
    factor(expr)  # Works directly
  3. Full import: Import all ~2000+ commands

    using Giac.Commands
    factor(expr)   # Works directly
    ifactor(expr)  # All commands available

See also

source
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 again
source

Substitution

See Variable Substitution for the substitute function documentation.

Type Introspection

Functions for querying the type of GIAC expressions:

Giac.giac_typeFunction
giac_type(g::GiacExpr) -> T

Return 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  # true

See also: Giac.GenTypes module for type enum values

source
Giac.subtypeFunction
subtype(g::GiacExpr) -> Int32

Return 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)
source
Giac.is_integerFunction
is_integer(g::GiacExpr) -> Bool

Return 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"))       # false
source
Giac.is_numericFunction
is_numeric(g::GiacExpr) -> Bool

Return 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"))       # false
source
Giac.is_vectorFunction
is_vector(g::GiacExpr) -> Bool

Return true if the expression is a vector/list/sequence (VECT).

Example

is_vector(giac_eval("[1, 2, 3]"))  # true
is_vector(giac_eval("42"))         # false
source
Giac.is_symbolicFunction
is_symbolic(g::GiacExpr) -> Bool

Return 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"))      # false
source
Giac.is_identifierFunction
is_identifier(g::GiacExpr) -> Bool

Return true if the expression is an identifier/variable (IDNT).

Example

is_identifier(giac_eval("x"))       # true
is_identifier(giac_eval("x + 1"))   # false
source
Giac.is_fractionFunction
is_fraction(g::GiacExpr) -> Bool

Return true if the expression is a rational fraction (FRAC).

Example

is_fraction(giac_eval("3/4"))    # true
is_fraction(giac_eval("42"))     # false
source
Giac.is_complexFunction
is_complex(g::GiacExpr) -> Bool

Return true if the expression is a complex number (CPLX).

Example

is_complex(giac_eval("3+4*i"))   # true
is_complex(giac_eval("42"))      # false
source
Giac.is_stringFunction
is_string(g::GiacExpr) -> Bool

Return true if the expression is a string (STRNG).

Example

is_string(giac_eval(""hello""))  # true
is_string(giac_eval("42"))         # false
source
Giac.is_booleanFunction
is_boolean(g::GiacExpr) -> Bool

Return 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

to_julia, is_integer

source

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 ValueIntDescription
INT0Machine integer (Int64)
DOUBLE1Double-precision float (Float64)
ZINT2Arbitrary-precision integer (BigInt)
REAL3Extended precision real
CPLX4Complex number
POLY5Polynomial
IDNT6Identifier/variable
VECT7Vector/list/sequence
SYMB8Symbolic expression
SPOL19Sparse polynomial
FRAC10Rational fraction
EXT11Algebraic extension
STRNG12String value
FUNC13Function reference
ROOT14Polynomial root
MOD15Modular arithmetic
USER16User-defined type
MAP17Map/dictionary
EQW18Equation writer data
GROB19Graphic object
POINTER20Raw pointer
FLOAT21Float value
Giac.GenTypesModule
GenTypes

A 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)  # 7

Type 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

source
Giac.GenTypes.TType
T

Enum representing GIAC expression types, matching C++ gen_unary_types.

Values

ValueIntC++ NameDescription
T.INT0_INT_Machine integer
T.DOUBLE1_DOUBLE_Double-precision float
T.ZINT2_ZINTArbitrary precision integer
T.REAL3_REALExtended precision real
T.CPLX4_CPLXComplex number
T.POLY5_POLYPolynomial
T.IDNT6_IDNTIdentifier/variable
T.VECT7_VECTVector/list/sequence
T.SYMB8_SYMBSymbolic expression
T.SPOL19_SPOL1Sparse polynomial
T.FRAC10_FRACRational fraction
T.EXT11_EXTAlgebraic extension
T.STRNG12_STRNGString
T.FUNC13_FUNCFunction reference
T.ROOT14_ROOTRoot of polynomial
T.MOD15_MODModular arithmetic
T.USER16_USERUser-defined type
T.MAP17_MAPMap/dictionary
T.EQW18_EQWEquation writer data
T.GROB19_GROBGraphic object
T.POINTER20_POINTER_Raw pointer
T.FLOAT21_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      # true
source

Component Access

Functions for accessing components of compound types:

Giac.numerFunction
numer(g::GiacExpr) -> GiacExpr

Return 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 5
source
Giac.denomFunction
denom(g::GiacExpr) -> GiacExpr

Return the denominator of a fraction, or 1 for integers.

Example

denom(giac_eval("3/4"))   # GiacExpr representing 4
denom(giac_eval("5"))     # GiacExpr representing 1
source
Giac.real_partFunction
real_part(g::GiacExpr) -> GiacExpr

Return 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 5
source
Giac.imag_partFunction
imag_part(g::GiacExpr) -> GiacExpr

Return 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 0
source
Giac.symb_funcnameFunction
symb_funcname(g::GiacExpr) -> String

Return the function name of a symbolic expression.

Example

symb_funcname(giac_eval("sin(x)"))  # "sin"
source
Giac.symb_argumentFunction
symb_argument(g::GiacExpr) -> GiacExpr

Return the argument (operand) of a symbolic expression.

Example

arg = symb_argument(giac_eval("sin(x)"))  # GiacExpr representing x
source

Julia 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+1

Conversion Functions

Giac.to_juliaFunction
to_julia(m::GiacMatrix) -> Matrix

Convert 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, GiacMatrix

source
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 TypeJulia Return Type
Boolean (true/false)Bool
INTInt64
ZINTBigInt
DOUBLE, REALFloat64
FRACRational{Int64} or Rational{BigInt}
CPLXComplex{T} (T promoted from parts)
VECTVector{T} (T narrowed from elements)
STRNGString
SYMB, IDNT, FUNCGiacExpr (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_type, is_boolean, is_numeric, is_vector

source
Giac.to_giacFunction
to_giac(expr)

Convert an expression to GiacExpr. Extended by GiacSymbolicsExt for Symbolics.Num types and by GiacMathJSONExt for MathJSON.AbstractMathJSONExpr types.

source
Giac.to_symbolicsFunction
to_symbolics(expr::GiacExpr)

Convert a GiacExpr to a Symbolics.jl expression. Extended by GiacSymbolicsExt.

source

Utility Functions

Giac.is_stub_modeFunction
is_stub_mode()

Check if the wrapper is running in stub mode (without the actual library).

source

Core Functions

FunctionDescription
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