Introduction
The Giac C++ API provides a comprehensive computer algebra system with support for symbolic computation, numerical evaluation, polynomial algebra, linear algebra, and more. All functionality is contained within thegiac namespace.
Main Headers
To use the Giac API, include the following headers fromsrc/giac/headers/:
- gen.h - Core gen class and type system
- global.h - Global context and configuration
- vecteur.h - Vectors and matrices
- symbolic.h - Symbolic expressions
- unary.h - Functions and operators
Quick Start
Core Components
The gen Class
The central type in Giac isgen, a polymorphic container that can hold:
- Integers (immediate or arbitrary precision)
- Floating-point numbers (double or arbitrary precision)
- Complex numbers
- Symbolic expressions
- Vectors and matrices
- Rational numbers
- Polynomials
- And more
Context System
Giac uses a context-based evaluation model. Thecontext class manages:
- Symbol tables
- Global settings (precision, angle mode, etc.)
- Evaluation state
Evaluation
Giac provides multiple evaluation modes:- eval() - Symbolic evaluation
- evalf() - Floating-point evaluation
- evalf_double() - Force double precision
Namespace
All Giac functionality is in thegiac namespace:
Type System
The gen type system is defined indispatch.h with constants like:
_INT_- Integer type_DOUBLE_- Double type_CPLX- Complex type_SYMB- Symbolic type_VECT- Vector type_FRAC- Fraction type_ZINT- Arbitrary precision integer
Memory Management
Giac uses reference counting for complex types. The gen class handles memory automatically through:- Reference-counted pointers for heap-allocated types
- Immediate values for small integers and doubles (with DOUBLEVAL)
- Copy-on-write semantics for efficiency
Thread Safety
Giac can be compiled with thread support using LIBPTHREAD. Each context can be used independently across threads.Configuration
Compile-time options:SMARTPTR64- Use 64-bit smart pointers (reduces gen size to 8 bytes)DOUBLEVAL- Store doubles directly in gen (increases size but improves precision)USE_GMP_REPLACEMENTS- Use custom implementations instead of GMPHAVE_LIBMPFR- Enable MPFR for arbitrary precision floats
Error Handling
Giac provides error functions that set error state:Next Steps
- gen class reference - Complete gen class documentation
- Context API - Context creation and configuration
- Evaluation functions - Evaluation modes and options
