Mathematics

Table of contents

  1. Notations
  2. Rational numbers
  3. Linear algebra

Notations

There are a number of notations similar to mathematical notation.

Math Moss Notes
x := a x=a assignment
a = b a==b comparison
xn x^n to the power of
ai a[i] index
a mod m a%m modulo
¬a not a logical negation
ab, ab a and b, a or b logical and, or
x ∈ A x in A is an element of
AB, AB A<=B, A<B subset, proper subset
AB, AB A&B, A|B intersection, union
A\B, AΔB A-B, A$B difference, symmetric difference
N0, N* (0..), (1..) non-negative integers, positive integers
a if c else b
distinction of cases
x ↦ 2x |x| 2*x anonymous function
fn(x) (f^n)(x) iterated function
{abc} {a,b,c} sets
(abc) [a,b,c] tuples
A×B, An A*B, A^n cartesian product, power

Furthermore:

Math Moss Notes
(m..n).sum(|k| f(k))
summation over a range
M.sum(|k| f(k))
summation over an iterable object
a.sum()
summation
(m..n).prod(|k| f(k))
product over a range
xM(p(x)) M.all(|x| p(x)) universal quantifier
xM(p(x)) M.any(|x| p(x)) existential quantifier
{xM | p(x)} M.filter(|x| p(x)) set builder notation
#{xM | p(x)} M.count(|x| p(x)) counting
f(A) f[A] image of a function
use math: sqrt, root
use na: diff, integral, inv
use cmath: conj, re, im
Math Moss Notes
sqrt(x), root(n,x) square root and general root
diff(f,a)
derivative
diff(f,a,n)
derivative of order n
integral(a,b,|x| f(x))
definite integral
inv(f,x,a,b) inverse function
a+bi a+b*1i complex numbers
abs(z), conj(z) absolute value, conjugation
Re z, Im z re(z), im(z) real part, imaginary part

Rational numbers

Module math.rational provides rational numbers. A rational number a/b is denoted as rat(a,b).

> use math.rational: rat
> rat(1,2)+2
5/2

> rat(4,5)^40+rat(2,3)^20
13752006853860928837764998235160576/
31712119389339932240545749664306640625

You can check this with the computer algebra system Maxima:

(%i1) (4/5)^40+(2/3)^20;

             13752006853860928837764998235160576
(%o1)       --------------------------------------
            31712119389339932240545749664306640625

Linear algebra

Module la provides an array data type which can be used to calculate with coordinate vectors and matrices.

use la: vector, matrix

v = vector(1,2)

A = matrix(
  [1,2],
  [3,4]
)

print(A*v)
Module math.la provides the polymorphic version of this array data type.
use math.la: matrix

A = matrix(
  [1,2],
  [3,4]
)

print(A^40)

# Output (long integers instead of floating point numbers):
# matrix(
#   [38418114959269691024862069751, 55991602170538933080248818850],
#   [83987403255808399620373228275, 122405518215078090645235298026]
# )

It is possible to combine this with rational numbers. A rational number a/b is denoted as rat(a,b).

use math.la: matrix
use math.rational: rat

A = matrix(
  [rat(4,1),rat(2,3)],
  [rat(9,5),rat(1,2)]
)

print(A^2)

# Output:
# matrix(
#   [86/5, 3],
#   [81/10, 29/20]
# )