Skip to main content

Overview

The equation solving module provides comprehensive tools for solving various types of equations including:
  • Single variable algebraic equations
  • Polynomial equations (exact and numeric)
  • Systems of equations
  • Linear systems
  • Numeric root finding
  • Modular polynomial roots

Core Solving Functions

solve

e
gen
The equation or expression to solve
x
identificateur | gen
The variable to solve for
isolate_mode
int
Mode flags: bit 0 for complex mode, bit 1 for principal solutions only
contextptr
GIAC_CONTEXT
Context pointer for evaluation
return
vecteur
Vector of solutions
vecteur solve(const gen & e, const identificateur & x, int isolate_mode, GIAC_CONTEXT);
vecteur solve(const gen & e, const gen & x, int isolate_mode, GIAC_CONTEXT);
vecteur solve(const vecteur & v, bool complex_mode, GIAC_CONTEXT);
Solves equations symbolically. The isolate_mode parameter controls whether complex solutions are returned and whether only principal solutions are computed.
For polynomial inputs, use isolate_mode & 1 to enable complex mode and get all complex roots.

protect_solve

e
gen
The equation to solve
x
identificateur
The variable to solve for
isolate_mode
int
Solving mode flags
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Protected solution vector
vecteur protect_solve(const gen & e, const identificateur & x, int isolate_mode, GIAC_CONTEXT);
Protected version of solve that handles exceptions and edge cases more robustly.

_solve

args
gen
Arguments containing equation and variable
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Solutions as a gen expression
gen _solve(const gen & args, GIAC_CONTEXT);
Command-line interface wrapper for solve function. Converts solutions to appropriate expression format.

Numeric Solvers

fsolve

args
gen
Equation, variable, and optional initial guess/interval
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Numeric solution(s)
gen _fsolve(const gen & args, GIAC_CONTEXT);
gen in_fsolve(vecteur & v, GIAC_CONTEXT);
Finds numeric (floating-point) solutions to equations. Can accept initial guess or search interval.
// Find root near x=1
gen result = _fsolve(makesequence(x*x-2, x, 1), contextptr);

newton

f
gen
Function to find roots of
x
gen
Variable
guess
gen
Initial guess for the root
niter
int
Maximum number of iterations
eps1
double
Initial tolerance
eps2
double
Final tolerance
real
bool
If true, restrict random re-initialization to real values
xmin
double
Lower boundary for x
xmax
double
Upper boundary for x
rand_xmin
double
Lower boundary for random re-initialization
rand_xmax
double
Upper boundary for random re-initialization
init_prefactor
double
Initial step size prefactor
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Approximate root
gen newton(const gen & f, const gen & x, const gen & guess, int niter, 
           double eps1, double eps2, bool real, double xmin, double xmax, 
           double rand_xmin, double rand_xmax, double init_prefactor, 
           GIAC_CONTEXT);
gen _newton(const gen & args, GIAC_CONTEXT);
Newton’s method for finding roots with configurable tolerances and boundaries.

bisection_solver

equation
gen
The equation to solve
var
gen
Variable
a0
gen
Left endpoint of interval
b0
gen
Right endpoint of interval
iszero
int&
Input/output status flag (see description)
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Vector of roots or intervals with sign changes
vecteur bisection_solver(const gen & equation, const gen & var, 
                         const gen & a0, const gen & b0, int & iszero, 
                         GIAC_CONTEXT);
Finds roots using bisection method. The iszero parameter controls behavior:
  • Input: 0 for single root, -1 for multiple roots without step count, positive for multiple with nstep
  • Output: -2 if same sign at endpoints, -1 if error, 1 if zero found, 2 if sign reversal

solve_zero_extremum

equation
gen
Equation to analyze
variable
gen
Variable
guess
gen
Initial guess (can be interval with xmin, xmax)
type
int&
Input: 0 for zeros, 1 for extrema. Output: actual type found
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Zeros or extrema found
vecteur solve_zero_extremum(const gen & equation, const gen & variable, 
                            const gen & guess, int & type, GIAC_CONTEXT);
vecteur solve_zero_extremum(const gen & equation0, const gen & variable, 
                            const gen & guess, double xmin, double xmax, 
                            int & type, GIAC_CONTEXT);
Finds zeros or extrema near a guess point. For polynomial input, returns all zeros or extrema.

Linear Systems

linsolve

sl
vecteur
System of linear equations
x
vecteur
Vector of variables
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Solution vector
vecteur linsolve(const vecteur & sl, const vecteur & x, GIAC_CONTEXT);
gen _linsolve(const gen & args, GIAC_CONTEXT);
gen symb_linsolve(const gen & syst, const gen & vars);
Solves systems of linear equations.

linsolve_u / linsolve_l

m
matrice
Upper/lower triangular matrix
y
vecteur
Right-hand side vector
a
vecteur&
Output solution vector
void linsolve_u(const matrice & m, const vecteur & y, vecteur & a);
void linsolve_l(const matrice & m, const vecteur & y, vecteur & a);
Specialized solvers for upper and lower triangular systems.

aspen_linsolve

m
matrice
Coefficient matrix (augmented with right-hand side)
contextptr
GIAC_CONTEXT
Context pointer
return
int
0 for no solution, 1 for unique solution, 2 for infinite solutions, -1 for error
int aspen_linsolve(const matrice & m, GIAC_CONTEXT);
int aspen_linsolve_2x2(const gen & a, const gen & b, const gen & c, 
                       const gen & d, const gen & e, const gen & f, 
                       GIAC_CONTEXT);
int aspen_linsolve_3x3(const gen & a, const gen & b, const gen & c, const gen & d,
                       const gen & e, const gen & f, const gen & g, const gen & h,
                       const gen & i, const gen & j, const gen & k, const gen & l,
                       GIAC_CONTEXT);
Optimized linear solvers for small systems (2x2 and 3x3).

System Solving

gsolve

eq_orig
vecteur
System of equations
var
vecteur
Vector of variables
complexmode
bool
Whether to find complex solutions
evalf_after
int
Whether to evaluate solutions numerically after solving
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Vector of solution sets
vecteur gsolve(const vecteur & eq_orig, const vecteur & var, 
               bool complexmode, int evalf_after, GIAC_CONTEXT);
General system solver using Gröbner basis methods for polynomial systems.

Modular Arithmetic

modpolyroot

a
vecteur
Polynomial coefficients
p
gen
Prime modulus
v
vecteur&
Output vector of roots modulo p
dogcd
bool
Whether to compute gcd with x^p-x first
contextptr
GIAC_CONTEXT
Context pointer
return
bool
True if successful
bool modpolyroot(const vecteur & a, const gen & p, vecteur & v, 
                 bool dogcd, GIAC_CONTEXT);
Finds all roots of a polynomial modulo a prime p. Set dogcd to false if you’ve already computed gcd with x^p-x.

Gröbner Bases

gbasis

v
vectpoly
Vector of polynomials
order
gen
Monomial ordering
with_cocoa
bool
Whether to use CoCoA library if available
modular
int
Modular algorithm flag
env
environment*
Polynomial environment
rur
int&
Rational univariate representation flag
contextptr
GIAC_CONTEXT
Context pointer
gbasis_param
gbasis_param_t
Additional parameters for Gröbner basis computation
coeffsptr
std::vector<vectpoly>*
Optional pointer to store transformation coefficients
return
vectpoly
Gröbner basis
vectpoly gbasis(const vectpoly & v, const gen & order, bool with_cocoa, 
                int modular, environment * env, int & rur, GIAC_CONTEXT,
                gbasis_param_t gbasis_param, 
                std::vector<vectpoly> * coeffsptr=0);
gen _gbasis(const gen & args, GIAC_CONTEXT);
Computes Gröbner basis of polynomial ideals. Essential for solving polynomial systems.

eliminate

args
gen
System and variables to eliminate
contextptr
GIAC_CONTEXT
Context pointer
return
gen
System with variables eliminated
gen _eliminate(const gen & args, GIAC_CONTEXT);
Eliminates variables from polynomial systems using Gröbner bases.

greduce

args
gen
Polynomial and basis to reduce with
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Reduced polynomial
gen _greduce(const gen & args, GIAC_CONTEXT);
Reduces a polynomial with respect to a Gröbner basis.

Optimization

fmin_cobyla

f
gen
Objective function to minimize
constraints
vecteur
Vector of constraint expressions (must be positive for feasibility)
variables
vecteur
Variables to optimize
guess
vecteur
Initial point
eps0
gen
Tolerance
maxiter0
gen
Maximum iterations
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Optimal point or error
gen fmin_cobyla(const gen & f, const vecteur & constraints, 
                const vecteur & variables, const vecteur & guess, 
                const gen & eps0, const gen & maxiter0, GIAC_CONTEXT);
Minimizes function subject to constraints using COBYLA (Constrained Optimization BY Linear Approximation).
Constraints must be written so that positive values indicate feasibility. For example, to express x ≤ MAX, use the constraint MAX - x.

giac_cobyla

gc
cobyla_gc*
Structure containing function, constraints, and variables
x0
vecteur&
Input: initial point. Output: final point
maxiter
int&
Input: max evaluations. Output: actual evaluations
eps
double
Tolerance (default 1e-8)
msg
int
Verbosity level 0-3 (default 0)
return
int
Return code indicating success or failure
int giac_cobyla(cobyla_gc *gc, vecteur &x0, int &maxiter, 
                double eps=1e-8, int msg=0);
Lower-level COBYLA interface with more control over algorithm parameters.

Utility Functions

find_singularities

e
gen
Expression
x
identificateur
Variable
cplxmode
int
Complex mode flag
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Vector of singularities
vecteur find_singularities(const gen & e, const identificateur & x, 
                           int cplxmode, GIAC_CONTEXT);
vecteur protect_find_singularities(const gen & e, const identificateur & x, 
                                   int cplxmode, GIAC_CONTEXT);
Finds singularities (poles, branch points) of an expression.

solvepostprocess

g
gen
Raw solution
x
gen
Variable
contextptr
GIAC_CONTEXT
Context pointer
return
gen
Processed solution
gen solvepostprocess(const gen & g, const gen & x, GIAC_CONTEXT);
Post-processes solutions to simplify and format them appropriately.

solvepreprocess

args
gen
Input arguments
complex_mode
bool
Whether complex mode is enabled
contextptr
GIAC_CONTEXT
Context pointer
return
vecteur
Preprocessed equations and variables
vecteur solvepreprocess(const gen & args, bool complex_mode, GIAC_CONTEXT);
Preprocesses solve arguments to normalize equations and extract variables.
  • Sturm Sequences - Root counting and isolation methods
  • Polynomial roots - See polynomial module
  • Numeric evaluation - See evalf module

Build docs developers (and LLMs) love