Everything in GEL is really just an expression. Expressions are stringed together with different operators. As we have seen, even the separator is simply a binary operator in GEL. Here is a list of the operators in GEL.
a;b
C'est le séparateur, il évalue simplement à la fois a
et b
mais ne renvoie que le résultat de b
.
a=b
L'opérateur d'attribution. Il attribue b
à a
(a
doit être une valeur à gauche valide). Remarquez que cet opérateur peut être transformé en ==
s'il est utilisé là où une expression booléenne est attendue.
a:=b
L'opérateur d'attribution. Il attribue b
à a
(a
doit être une valeur à gauche valide). Il est différent de =
car il n'est jamais transformée en ==
.
|a|
Absolute value.
In case the expression is a complex number the result will be the modulus
(distance from the origin). For example:
|3 * e^(1i*pi)|
returns 3.
Consultez Mathworld pour plus d'informations.
a^b
Exposant, met a
à la puissance b
.
a.^b
Exposant élément par élément. Met chaque élément d'une matrice a
à la puissance b
. Si b
est une matrice de la même taille que a
alors l'opération se réalise élément par élément. Si a
est un nombre et b
est une matrice alors cela crée une matrice de la même taille que b
contenant a
mis à la puissance de chaque élément de b
.
a+b
Addition. Adds two numbers, matrices, functions or strings. If you add a string to anything the result will just be a string. If one is a square matrix and the other a number, then the number is multiplied by the identity matrix.
a-b
Soustraction. Soustrait deux nombres, matrices ou fonctions.
a*b
Multiplication. C'est la multiplication matricielle normale.
a.*b
Multiplication élément par élément si a
et b
sont des matrices.
a/b
Division. When a
and b
are just numbers
this is the normal division. When they are matrices, then this is
equivalent to a*b^-1
.
a./b
Element by element division. Same as a/b
for
numbers, but operates element by element on matrices.
a\b
Division arrière. C'est donc la même chose que b/a
.
a.\b
Division arrière élément par élément.
a%b
The mod operator. This does not turn on the modular mode, but
just returns the remainder of integer division
a/b
.
a.%b
Element by element mod operator. Returns the remainder
after element by element integer division
a./b
.
a mod b
Opérateur d'évaluation modulaire. L'expression a
est évaluée modulo b
. Consultez the section called “Évaluation modulaire”. Certaines fonctions et opérateurs se comportent différemment modulo un entier.
a!
Opérateur factoriel. Il s'agit de 1*...*(n-2)*(n-1)*n
.
a!!
Opérateur double factoriel. Il s'agit de 1*...*(n-4)*(n-2)*n
.
a==b
Equality operator.
Returns true
or false
depending on a
and b
being equal or not.
a!=b
Opérateur inégalité, renvoie true
si a
n'est pas égal à b
sinon renvoie false
.
a<>b
Autre opérateur inégalité, renvoie true
si a
n'est pas égal à b
sinon renvoie false
.
a<=b
Less than or equal operator,
returns true
if a
is
less than or equal to
b
else returns false
.
These can be chained as in a <= b <= c
(can
also be combined with the less than operator).
a>=b
Greater than or equal operator,
returns true
if a
is
greater than or equal to
b
else returns false
.
These can be chained as in a >= b >= c
(and they can also be combined with the greater than operator).
a<b
Less than operator,
returns true
if a
is
less than
b
else returns false
.
These can be chained as in a < b < c
(they can also be combined with the less than or equal to operator).
a>b
Greater than operator,
returns true
if a
is
greater than
b
else returns false
.
These can be chained as in a > b > c
(they can also be combined with the greater than or equal to operator).
a<=>b
Opérateur comparaison. Si a
est égal à b
, cela renvoie 0, si a
est inférieur à b
, cela renvoie -1 et si a
est supérieur à b
, cela renvoie 1.
a and b
Logical and. Returns true if both
a
and b
are true,
else returns false. If given numbers, nonzero numbers
are treated as true.
a or b
Logical or.
Returns true if either
a
or b
is true,
else returns false. If given numbers, nonzero numbers
are treated as true.
a xor b
Logical xor.
Returns true if exactly one of
a
or b
is true,
else returns false. If given numbers, nonzero numbers
are treated as true.
not a
Logical not. Returns the logical negation of a
.
-a
Negation operator. Returns the negative of a number or a matrix (works element-wise on a matrix).
&a
Variable referencing (to pass a reference to a variable). See the section called “Références”.
*a
Variable dereferencing (to access a referenced variable). See the section called “Références”.
a'
Matrix conjugate transpose. That is, rows and columns get swapped and we take complex conjugate of all entries. That is
if the i,j element of a
is x+iy, then the j,i element of a'
is x-iy.
a.'
Matrix transpose, does not conjugate the entries. That is,
the i,j element of a
becomes the j,i element of a.'
.
a@(b,c)
Get element of a matrix in row b
and column
c
. If b
,
c
are vectors, then this gets the corresponding
rows, columns or submatrices.
a@(b,)
Renvoie une ligne de matrice (ou plusieurs lignes si b
est un vecteur).
a@(b,:)
Comme ci-dessus.
a@(,c)
Renvoie une colonne de matrice (ou des colonnes si c
est un vecteur).
a@(:,c)
Comme ci-dessus.
a@(b)
Renvoie un élément d'une matrice en le traitant comme un vecteur. Cela parcourt la matrice dans le sens des lignes.
a:b
Build a vector from a
to b
(or specify a row, column region for the @
operator). For example to get rows 2 to 4 of matrix A
we could do
A@(2:4,)
as 2:4
will return a vector
[2,3,4]
.
a:b:c
Build a vector from a
to c
with b
as a step. That is for example
genius> 1:2:9
=
`[1, 3, 5, 7, 9]
When the numbers involved are floating point numbers, for example
1.0:0.4:3.0
, the output is what is expected
even though adding 0.4 to 1.0 five times is actually just slightly
more than 3.0 due to the way that floating point numbers are
stored in base 2 (there is no 0.4, the actual number stored is
just ever so slightly bigger). The way this is handled is the
same as in the for, sum, and prod loops. If the end is within
2^-20
times the step size of the endpoint,
the endpoint is used and we assume there were roundoff errors.
This is not perfect, but it handles the majority of the cases.
This check is done only from version 1.0.18 onwards, so execution
of your code may differ on older versions. If you want to avoid
dealing with this issue, use actual rational numbers, possibly
using the float
if you wish to get floating
point numbers in the end. For example
1:2/5:3
does the right thing and
float(1:2/5:3)
even gives you floating
point numbers and is ever so slightly more precise than
1.0:0.4:3.0
.
(a)i
Make a
into an imaginary number (multiply a
by the
imaginary). Normally the imaginary number i
is
written as 1i
. So the above is equal to
(a)*1i
`a
Apostropher un identifiant afin qu'il ne soit pas évalué. Ou apostropher une matrice afin qu'elle ne soit pas étendue.
a swapwith b
Échange la valeur de a
par la valeur de b
. Pour le moment, ne fonctionne pas sur des ensembles d'éléments de matrice. Renvoie null
. Disponible à partir de la version 1.0.13.
increment a
Incrémente la variable a
de 1. Si a
est une matrice alors incrémente chaque élément. C'est équivalent à a=a+1
mais est plus rapide. Renvoie null
. Disponible à partir de la version 1.0.13.
increment a by b
Incrémente la variable a
de b
. Si a
est une matrice alors incrémente chaque élément. C'est équivalent à a=a+b
mais est plus rapide. Renvoie null
. Disponible à partir de la version 1.0.13.
L'opérateur @() rend l'opérateur : très utile. Grâce à lui, vous pouvez indiquer des régions d'une matrice. Ainsi a@(2:4,6) sont les lignes 2,3,4 de la colonne 6 ou a@(,1:2) vous renvoie les deux premières colonnes d'une matrice. Vous pouvez également attribuer un opérateur @() tant que la valeur de droite est une matrice qui correspond en taille à la région ou si c'est n'importe quel autre type de valeur.
The comparison operators (except for the <=> operator, which behaves normally), are not strictly binary operators, they can in fact be grouped in the normal mathematical way, e.g.: (1<x<=y<5) is a legal boolean expression and means just what it should, that is (1<x and x≤y and y<5)
L'opérateur unitaire « moins » agit de manière différente en fonction de l'endroit où il apparaît. S'il apparaît devant un nombre, il est très prioritaire, s'il apparaît devant une expression, il est moins prioritaire que les opérateurs puissance et factoriel. Par exemple, -1^k
est bien (-1)^k
, mais -foo(1)^k
est bien -(foo(1)^k)
. En conséquence, faites attention à son utilisation et, en cas de doute, ajoutez des parenthèses.