Mathematics

Table of contents

  1. Notations
  2. Integer division
  3. Rational numbers
  4. 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 math.na: inv, diffh, integral
use cmath: conj, re, im
diff = diffh(order=false)
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

Integer division

There are different forms of integer division.

# Floor division
div_floor = |x,y| x//y
mod_floor = |x,y| x%y


# Euclidean division
div_euc = |x,y| sgn(y)*(x//abs(y))
mod_euc = |x,y| x%abs(y)


# Truncating division
div_trunc = |x,y| sgn(x)*sgn(y)*(abs(x)//abs(y))
mod_trunc = |x,y| x%(sgn(x)*abs(y))

In case of y>0, flooring division and Euclidean division coincide. In case of x>0 and y>0, all of them coincide.

Furthermore, there are floating point counterparts:

use math: floor, trunc

# Floor division
div_floor = |x,y| floor(x/y)
mod_floor = |x,y| x-y*floor(x/y)


# Euclidean division
div_euc = |x,y| sgn(y)*floor(x/abs(y))
mod_euc = |x,y| x-abs(y)*floor(x/abs(y))


# Truncating division
div_trunc = |x,y| trunc(x/y)
mod_trunc = |x,y| x-y*trunc(x/y)

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

Main chapter: Linear algebra.

Module math.la provides vector algebra.

use math.la: vector, matrix

v = vector(1,2)

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

print(A*v)