Monomials
This chapter describes Monomial objects useful to encode the variables powers of Multivariate Taylor Series used by the Differential Algebra library of MAD-NG. The module for monomials is not exposed, only the contructor is visible from the MAD
environment and thus, monomials must be handled directly by their methods. Monomial objects do not know to which variables the stored orders belong, the relationship is only through the indexes. Note that monomials are objects with reference semantic that store variable orders as 8-bit unsigned integers, thus arithmetic on variable orders occurs in the ring \(\mathbb{N}/2^8\mathbb{N}\).
Constructors
The constructor for monomial is directly available from the MAD
environment.
- monomial([len_, ] ord_)
Return a monomial of size
len
with the variable orders set to the values given byord
, as computed bymono:fill(ord_)
. Iford
is omitted thenlen
must be provided. Default:len_ = #ord
,ord_ = 0
.
Attributes
- mono.n
The number of variable orders in
mono
, i.e. its size or length.
Functions
- is_monomial(a)
Return
true
ifa
is a monomial,false
otherwise. This function is only available from the moduleMAD.typeid
.
Methods
The optional argument r_
represents a destination placeholder for results.
- mono:same(n_)
Return a monomial of length
n
filled with zeros. Default:n_ = #mono
.
- mono:copy(r_)
Return a copy of
mono
.
- mono:fill(ord_)
Return
mono
with the variable orders set to the values given byord
. Default:ord_ = 0
.If
ord
is a number then all variable orders are set to the value oford
.If
ord
is a list then all variable orders are set to the values given byord
.If
ord
is a string then all variable orders are set to the values given byord
, where each character in the set[0-9A-Za-z]
is interpreted as a variable order in the Basis 62, e.g. the string"Bc"
will be interpreted as a monomial with variable orders 11 and 38. Characters not in the set[0-9A-Za-z]
are not allowed and lead to an undefined behavior, meaning that orders \(\ge 62\) cannot be safely specified through strings.
- mono:min()
Return the minimum variable order of
mono
.
- mono:max()
Return the maximum variable order of
mono
.
- mono:ord()
Return the order of
mono
, that is the sum of all the variable orders.
- mono:ordp(step_)
Return the product of the variable orders of
mono
at everystep
. Default:step_ = 1
.
- mono:ordpf(step_)
Return the product of the factorial of the variable orders of
mono
at everystep
. Default:step_ = 1
.
- mono:add(mono2, r_)
Return the sum of the monomials
mono
andmono2
, that is the sum of the all their variable orders, i.e. \((o_1 + o_2) \mod 256\) where \(o_1\) and \(o_2\) are two variable orders at the same index inmono
andmono2
.
- mono:sub(mono2, r_)
Return the difference of the monomials
mono
andmono2
, that is the subtraction of the all their variable orders, i.e. \((o_1 - o_2) \mod 256\) where \(o_1\) and \(o_2\) are two variable orders at the same index inmono
andmono2
.
- mono:concat(mono2, r_)
Return the concatenation of the monomials
mono
andmono2
.
- mono:reverse(r_)
Return the reverse of the monomial
mono
.
- mono:totable()
Return a list containing all the variable orders of
mono
.
- mono:tostring(sep_)
Return a string containing all the variable orders of
mono
encoded with characters in the set[0-9A-Za-z]
and separated by the stringsep
. Default:sep_ = ''
.
Operators
- #mono
Return the number of variable orders in
mono
, i.e. its length.
- mono[n]
Return the variable order at index
n
for1 <= n <= #mono
,nil
otherwise.
- mono[n] = v
Assign the value
v
to the variable order at indexn
for1 <= n <= #mono
, otherwise raise an “out of bounds” error.
- mono + mono2
Equivalent to
mono:add(mono2)
.
- mono - mono2
Equivalent to
mono:sub(mono2)
.
- mono < mono2
Return
false
if one variable order inmono
is greater or equal to the variable order at the same index inmono2
,true
otherwise.
- mono <= mono2
Return
false
if one variable order inmono
is greater than the variable order at the same index inmono2
,true
otherwise.
- mono == mono2
Return
false
if one variable order inmono
is not equal to the variable order at the same index inmono2
,true
otherwise.
- mono .. mono2
Equivalent to
mono:concat(mono2)
.
Iterators
- ipairs(mono)
Return an ipairs iterator suitable for generic
for
loops. The generated values are those returned bymono[i]
.
C API
-
type ord_t
The variable order type, which is an alias for 8-bit unsigned integer. In the C API, monomials are arrays of variable orders with their size
n
tracked separately, i.e.a[n]
.
-
ssz_t mad_mono_str(ssz_t n, ord_t a[n], str_t s)
Return the number of converted characters from the string
s
into variable orders stored to the monomiala[n]
, as decribed in the method:fill()
.
-
str_t mad_mono_prt(ssz_t n, const ord_t a[n], char s[n + 1])
Return the string
s
filled with characters resulting from the conversion of the variable orders given in the monomiala[n]
, as decribed in the method:tostring()
.
-
void mad_mono_copy(ssz_t n, const ord_t a[n], ord_t r[n])
Copy the monomial
a[n]
to the monomialr[n]
.
-
ord_t mad_mono_min(ssz_t n, const ord_t a[n])
Return the minimum variable order of the monomial
a[n]
.
-
ord_t mad_mono_max(ssz_t n, const ord_t a[n])
Return the minimum variable order of the monomial
a[n]
.
-
num_t mad_mono_ordp(ssz_t n, const ord_t a[n], idx_t stp)
Return the product of the variable orders of the monomial
a[n]
at everystp
.
-
num_t mad_mono_ordpf(ssz_t n, const ord_t a[n], idx_t stp)
Return the product of the factorial of the variable orders of the monomial
a[n]
at everystp
.
-
log_t mad_mono_eq(ssz_t n, const ord_t a[n], const ord_t b[n])
Return
FALSE
if one variable order in monomiala[n]
is not equal to the variable order at the same index in monomialb[n]
,TRUE
otherwise.
-
log_t mad_mono_lt(ssz_t n, const ord_t a[n], const ord_t b[n])
Return
FALSE
if one variable order in monomiala[n]
is greater or equal to the variable order at the same index in monomialb[n]
,TRUE
otherwise.
-
log_t mad_mono_le(ssz_t n, const ord_t a[n], const ord_t b[n])
Return
FALSE
if one variable order in monomiala[n]
is greater than the variable order at the same index in monomialb[n]
,TRUE
otherwise.
-
int mad_mono_cmp(ssz_t n, const ord_t a[n], const ord_t b[n])
Return the difference between the first variable orders that are not equal for a given index starting from the beginning in monomials
a[n]
andb[n]
.
-
int mad_mono_rcmp(ssz_t n, const ord_t a[n], const ord_t b[n])
Return the difference between the first variable orders that are not equal for a given index starting from the end in monomials
a[n]
andb[n]
.
-
void mad_mono_add(ssz_t n, const ord_t a[n], const ord_t b[n], ord_t r[n])
Put the sum of the monomials
a[n]
andb[n]
in the monomialr[n]
.
-
void mad_mono_sub(ssz_t n, const ord_t a[n], const ord_t b[n], ord_t r[n])
Put the difference of the monomials
a[n]
andb[n]
in the monomialr[n]
.
-
void mad_mono_cat(ssz_t n, const ord_t a[n], ssz_t m, const ord_t b[m], ord_t r[n + m])
Put the concatenation of the monomials
a[n]
andb[m]
in the monomialr[n+m]
.