Skip to main content

Overview

Vectors in Giac are represented using the vecteur type, which is a C++ std::vector<gen>. This provides a flexible container for generic algebraic elements.

Type Definitions

vecteur

typedef std::vector<gen> vecteur;
The fundamental vector type in Giac, a dynamic array of generic algebraic elements.

Iterator Types

typedef vecteur::const_iterator const_iterateur;
typedef vecteur::iterator iterateur;
Iterator types for traversing vectors.

Specialized Matrix Types

typedef vecteur matrice;
Matrices are represented as vectors of vectors (see Matrix Operations).

Vector Construction

makevecteur

Construct vectors with 1 to 14 elements.
vecteur makevecteur(const gen & a);
vecteur makevecteur(const gen & a, const gen & b);
vecteur makevecteur(const gen & a, const gen & b, const gen & c);
// ... up to 14 parameters
a, b, c, ...
const gen &
Elements to include in the vector
return
vecteur
A new vector containing the specified elements
Example:
vecteur v = makevecteur(1, 2, 3);

makesequence

Construct sequences (similar to makevecteur but returns gen).
gen makesequence(const gen & a);
gen makesequence(const gen & a, const gen & b);
// ... up to 9 parameters

mergevecteur

Merge two vectors.
vecteur mergevecteur(const vecteur & v, const vecteur & w);
v
const vecteur &
First vector
w
const vecteur &
Second vector
return
vecteur
Concatenation of v and w

Vector Arithmetic

addvecteur

Add two vectors element-wise.
vecteur addvecteur(const vecteur & a, const vecteur & b);
void addvecteur(const vecteur & a, const vecteur & b, vecteur & res);
a
const vecteur &
First vector
b
const vecteur &
Second vector
res
vecteur &
Output parameter for result (in-place version)
return
vecteur
Element-wise sum a + b

subvecteur

Subtract vectors element-wise.
vecteur subvecteur(const vecteur & a, const vecteur & b);
void subvecteur(const vecteur & a, const vecteur & b, vecteur & res);
a
const vecteur &
First vector
b
const vecteur &
Second vector
return
vecteur
Element-wise difference a - b

negvecteur

Negate all elements of a vector.
vecteur negvecteur(const vecteur & a);
a
const vecteur &
Input vector
return
vecteur
Vector with all elements negated

Scalar Multiplication

vecteur multvecteur(const gen & a, const vecteur & b);
void multvecteur(const gen & a, const vecteur & b, vecteur & res);
a
const gen &
Scalar multiplier
b
const vecteur &
Vector to multiply
return
vecteur
Vector with each element multiplied by a

Scalar Division

vecteur divvecteur(const vecteur & b, const gen & a);
void divvecteur(const vecteur & b, const gen & a, vecteur & res);
b
const vecteur &
Vector to divide
a
const gen &
Scalar divisor
return
vecteur
Vector with each element divided by a

Vector Products

dotvecteur

Compute the dot (scalar) product of two vectors.
gen dotvecteur(const vecteur & a, const vecteur & b);
gen dotvecteur(const gen & a, const gen & b);
a
const vecteur &
First vector
b
const vecteur &
Second vector
return
gen
Scalar product (does not conjugate)
This function does not conjugate. For the standard inner product with conjugation, see scalarproduct in misc.h.

cross

Compute the cross product (3D vectors).
vecteur cross(const vecteur & v, const vecteur & w, GIAC_CONTEXT);
gen cross(const gen & g1, const gen & g2, GIAC_CONTEXT);
v
const vecteur &
First 3D vector
w
const vecteur &
Second 3D vector
return
vecteur
Cross product v × w
Giac Command: _cross

Utility Functions

vrows

Get the number of elements in a vector.
int vrows(const vecteur & a);
a
const vecteur &
Input vector
return
int
Number of elements in the vector

freecopy

Make a free (modifiable) copy of a vector.
gen freecopy(const gen & g);
g
const gen &
Vector to copy
return
gen
Modifiable copy of the vector

is_fully_numeric

Check if all vector elements are numeric.
bool is_fully_numeric(const vecteur & v, int withfracint = 0);
bool is_fully_numeric(const gen & a, int withfracint = 0);
v
const vecteur &
Vector to check
withfracint
int
default:"0"
Fraction/integer handling mode
return
bool
true if all elements are numeric

is_exact

Check if vector contains only exact values.
bool is_exact(const vecteur & v);
bool is_exact(const gen & g);
v
const vecteur &
Vector to check
return
bool
true if all elements are exact (no floating point)

is_integer_vecteur

Check if all vector elements are integers.
bool is_integer_vecteur(const vecteur & m, bool intonly = false);
m
const vecteur &
Vector to check
intonly
bool
default:"false"
Restrict to machine integers only
return
bool
true if all elements are integers

Type Conversions

vecteur2index

Convert a vector to an index.
bool vecteur2index(const vecteur & v, index_t & i);

vector_int2vecteur

Convert integer vector to vecteur.
void vector_int2vecteur(const std::vector<int> & v, vecteur & res);

vecteur2vector_int

Convert vecteur to integer vector with modular reduction.
void vecteur2vector_int(const vecteur & v, int modulo, std::vector<int> & res);

See Also

Build docs developers (and LLMs) love