TAU
A Mathematical Engine
© S. Xamb贸


TAU functions

This page (work in progress) is intended to provide descriptions of all the functions that the Tau mathamatical engine can process through the interface TAU.

For the coding package (implemented in Tau), see CC (computational interface) and cc (user guide).

Warning. If the parameters of a function do not satisfy the specified conditions in its definition, there will be error at the Tau level. Debugging this sort of errors may be hard, as the current interface TAU only gives indirect information on them.


» | dic | ict |




       INDEX

Algebra


In this section we present some basic functions related to the algebra of polynomials.

A polynomial in the variables x,y (say) with rational coefficients (say) is a sum of terms of the form a xi yj, where a is a rational number and i, j are integers. Since this term can be input with the syntax a * x^i * y^j , we see that polynomials can be easily constructed with the operators +, * and ^.

Polynomials belong to the type Polynomial.


is? (p, Polynomial)
variables(p)
We can ascertain if an expression p is a polynomial with the call is?(p, Polynomial). The list of variables of a polynomial p is given by variables(p)

Examples: polynomial.t

» index | dic | ict |

Arithmetic


For the binary operators +, −, *, /, ^, // and mod, and the unary operators ! and !!, see the section Operators.

base_change (n, b), base_change ([k0, k1,...,kr], b)
If n≥0 and b>1 are integers, the first function returns the vector [k0, k1,...,kr] such that 0≤kj<b (j=0,...,r) and n=krbr+路路路+k1b+k0 or, alternatively, n=kr路路路k1k0 (b. Note the reversing of the order in the output vector. The second form of the function, in which the first parameter is a vector of non-negative integers, returns the integer k0+k1b+路路路+krbr.

bit (n, j), number_of_bits (n)
If n is a positive integer and n=br路路路b1b0 (2 is its binary expansion, then bit (n, j) returns bj. For a positive integer n, number_of_bits (n) returns the number of bits of n.

even? (n), odd? (n)
If n is an integer, these functions test whether it is even or odd.

factor_power_of_two (n), factor_power_of_integer (n , b)
If n is an integer, the first function returns the pair of integers {r, n'} such that n=2rn' witn n' odd. The second function works similarly, but for the integer b>1 instead of 2.

gcd (a, b), lcm (a, b)
If a and b are integers or univariate polynomials, gcd(a,b) and lcm(a,b) return the greatest common divisor and the least common multiple of span a and b.

Examples: gcd-lcm.t

phi_euler (n)
This function gives the number of k in 1..(n-1) such that gcd(k,n) = 1.

Examples: phi-euler.t

» index | dic | ict |

Chains

In this section we describe a few functions that are defined for any of the types List, Vector and Relation. Together, theis types constitute the type Chain (cf. the section Types).

length(c)
range(c)
c.k
head(c)
last(c)
If c is a Chain, length(c) gives the number of its elements, say n; range(c) provides the range 1..n; if k is in the range of c, c.k yields the k-th element of c. Instead of c.1 we can use head(c) and instead of c.n we can use last(c).

The functions described above work also for the types Range and Rule.

Examples: chain.t

join (a, b) ≡ a | b
If a and b are chains of the same sort, a | b constructs the chain obtained by joining b to the end of a. The infix operator a | b for chains is equivalent to the prefix form join(a, b).

Examples: join.t

» index | dic | ict |



Combinatorics

n! = permutations (n)
If n is a positive integer, this function computes the product n 路 (n −1) 路路路 2路1, which is the number of permutations that can be formed out of a set of n elements. By convention 0! = 1 (the empty set has exactly 1 permutation: the identity). If X is a list or a vector, permutations (X) constructs a list or a vector whose elements are all the permutations of X.

binomial (n, m) = combinations (n, m)
If n and m are positive integers with m ≤ n, binomial (n, m) computes the expression n!/(m!路(n-m)!), which is the number of subsets of cardinal m that can be formed with a set of n elements. If X is a list or a vector of length n, and n ≤ m, combinations (X, m) supplies a list or a vector whose elements are all the combinations of length m that can be formed with the elements of X.

tartaglia (n)
If n is a non-negative integer, this function constructs the list {binomial (n, j) with j in 0..n}.

variations (n, m)
If n and m non-negative integers with m ≤ n, variations (n, m) computes the expression n!/(n-m)! = n路(n − 1)路路路 (n − m + 1), which is the number of sublists of m elements that can be formed out of a list of n elements. If X is a list or a vector of length n, and n ≤ m, variations (X, m) supplies a list or a vector whose elements are all the sublists of length m of X.

combinations_with_repetition (n, m)
If n and m are positive integers, this function compute binomial (n+m-1, m), which is the number of combinations of m elements with (possible) repetition that can be formed out of a set of n elements. If X is a list or a vector of length n, combinations_with_repetition (X, m) supplies a list or a vector whose elements are all the combinations with (possible) repetition of length m that can be formed with the elements of X.

permutations_with_repetition (n, n1, ..., nk)
If n, n1, ..., nk are a non-negative integers and and n =n1 + 路路路 +nk, this funtion computes the expression n!/(n1! 路路路 nk!), which is the number of permutations of n with k distinct elements repeated n1, ..., nk times, respectively. If X is a list or a vector of length n containing k distinct elements that are repeated n1, ..., nk times, respectively, permutations_with_repetition (n, X) supplies a list or a vector whose elements are all the permutations of X that can be formed with the elements of X with the constraint that the elements in each group are undistinguishable.

Combinatorial  functions
Meaning
Examples
bernoulli_number(n:Pos)
B_(n:Pos)
<> (-1)n-1 · worpitzki_bernouilli_number(2·n)
<> (-1)n-1 · WB_(2·n)
B_(7)
» 7/6
denominator_bernoulli_number(n:Pos) The denominator of the Bernoulli number B2·n ,
or of  B_(n).
@ n=100
» 1366530



stirling_number(n, k)
S_(n, k)
Stirling number of the second kind:
Number of partitions of a set of n+1
elements into k+1 non-empty subsets
S_(4,2)
» 7

worpitzki_bernoulli_number(n:Nat)
WB_(n:Nat)
The n-th Bernoulli number Bn:
B0=1, B1=1/2, B2=1/6, B3=0, B4=-1/30, ...
WB_(14)
» 7/6
worpitzki_number(n:Nat, k:Nat)
W_(n:Nat, k:Nat)
k! · stirling_number(n+1, k+1)
k! · S_(n+1, k+1)
W_(3,1)
» 7

» index | dic | ict |


Equations

In this section we describe a few functions that are handy to solve systems of polynomial equations, and in particular linear equations.

solve(A,v)
If A is a matrix of type m×n and v is a vector of length m, the output of solve(A,v) describes the solutions of the linear system of equations AxT=vT, where x=(x1,...,xn) denotes the vector of unknowns (the expressions xT and vT denote the vectors x and v written in column form). If the system of equations has a unique solution, then this solution is output as a row vector. If the system has more than one solution, the output is a list S with two components: S.1 is an matrix of type n×k whose columns form a basis of the linear space of solutions of AxT=0 (so k=n-r, r the rank of A) and S.2 is a (row) vector that is a particular solution of the system AxT=vT. In this case, the solutions xT of this system are the sum of (S.2)T and an arbitrary linear combination of the columns of S.1 (the latter have the form (S.1)λT, where λ=(λ1,..,λk) take arbritrary values in the field over which A is defined (the real numbers by default). Finally, the output is empty if the system AxT=vT has no solutions.

Examples: Equations-1.t

solve_polynomial([P])
In this function call, P is a sequence of polynomials p1,...,pn in some indeterminates X1,...,Xn) (hence [P] is a vector of polynomials). The output of the function is empty if the system of equations does not have a solution. Otherwise is a list of 1 or more Substitutions each of which has the form {X1⇒a1,...,Xn⇒an), where a1,...,an is a solution. Undeterminates that remain free appear in the form Xj⇒Xj. If S is any of the substitutions in the output and e is an expression in the indeterminates X1,...,Xn, then S(e) yields the value of the result of performing the subsitution indicated by e in e.

Examples: Equations-2.t

» index | dic | ict |


Expressions and functions

The reader is adviced to look at the Tau example functions.t while reading this introduction.

Pure functions are defined with the following syntax:

    x --> e
where x stands for the parameter specifications and e for an expression (the body of the function). The value of the expression x --> e (a function) can be applied to any instance a of the parameters x:
    (x --> e) (a)
This returns the value of the function when its parameters are instantiated as a.

The pure function x --> e can be assigned to a variable (say f):

    f = x --> e
In this case, the value of the expression f(a) is the value of the funtion for a.

The syntax for defining a function and at the same time assigning it to a name (say, again, f) is as follows:

    f(x) := e

Objects such as 32 (a number), N (a variable), N = 11 (an assignement), N := x+y (a delayed assignement), binomial(27,12) (a call to a core function), sin(x)-3*cos(x) (a trigonometric expression), and so on, will be called simple expressions. Each of them can form the body of a function (we refer again to functions.t).

For the remaining part of this introduction, we refer to the examples in iterators.t.

Compound expressions are formed by a sequence of simple expressions, separated by ';' or the end of line, and surrounded by a pair of reserved identifiers among a short list. The efect of any such pair is to weld the sequence of expressions into a an object that behaves as a simple expression, with value the value of the last expression in the sequence.

The following function, which computes the binary expression of a real number x with BP bits in the fractional part, illustrates many of these features and several others:

	binary(x: Real, BP: Integer) check (BP>=0) :=
	begin
	    local e = floor(x), b, r = [], j = 0
	    x = x-e
	    e=reverse(base_change(e,2))
	    while (j < BP) do
		j=j+1
		x=2*x
		b=floor(x)
		if b>=1 then x=x-b; r=r|[1] else r=r|[0] end
	    end
	   {e,r}
	end;
	#
	binary(x:Real):=binary(x,6);
The pair begin ... end is used to signal the beiginning and the end of a function body formed by a compound expression, which in this case consists of five expressions. The value of the last of these expressions, the pair {e,r}, is the value returned by the function binary: e is the binary expression of the integral part of the real number a (the first parameter of the function) and r is formed by the first BP bits of the binary expansion of the franctional part of a.

The other pairs of compound statement wrappers can appear anywhere in the body of a function and are the following: do ... end (used with while and for expressions); then ... else, elif ... end, else ... end (used in if expressions), and repeat ... until. For further illustrations of these constructs, see the examples in iterators.t.

» index | dic | ict |


Identifiers

Identifier* functions
Meaning
Examples
identifier(x:Name, k:Nat)
Identifier formed by concatenating the Name x
and the integer k.
@ x=a, k=3
» a3
x=v
If x is a Name, x is assigned the value v.
The value of the expression is v
Z=2+3
» 5
x:=v Delayed assignment

* An identifier is a literal character (this includes underscore, "_", and the acute accent, "´", not to be confused with the apostrophe " ' ") followed by 0 or more characters each of which is a literal or a decimal digit. Some identifiers, as for example _, are reserved words.

» index | dic | ict |


Lists

List functions
Meaning
{x1,...,xn}
List formed with the sequence x1,...,xn
list(r:Range)
The list formed with the actual values of r

» index | dic | ict |


Matrices

A', transpose (A)
The transpose of A.

A | B
If A and B are matrices with the same number of rows, the expression produces the splicing of B to the right of A.

Example: [[1, 2, 3], [x, y, z]] | [[x,y], [1, 2]] is the matrix [[1, 2, 3, x, y], [x, y, z, 1, 2]].

Example: [[1, 2], [4,7]] | [x,y] is the matrix [[1, 2, x], [4,7,y]].

A | v
If A is a matrix and v a vector with length equal to the number of rows of A, this expression evaluates as A | v' (the latter that follows the customary conventions of mathematics, so the possibility of wrting just A | v is nothing but a little sugaring for the syntax).

number_of_rows (A), n_rows(A)
The number of rows of the matrix A.

number_of_columns (A), n_columns(A)
The number of columns of the matrix A.

range (A)
Its value is 1..r, where r is the number of rows of the matrixA.

A.j.k
If A is an m × n matrix then A.j.k extracts the element of A in the cell (j,k), provide, of course, that j lies in 1..m and k in 1..n.

determinant (A), der (A)
The determinant of A, assuming A is a square matrix.

trace (A)
The trace of A, assuming A is a square matrix.

A*v
This is a little bit of syntatic sugaring: If A is an m×n matrix and v is a vector of length n, the expression A*v is interpreted as A*v', which is what makes sense according to the usual mathematical conventions.

v*A
If A is an m×n matrix and v is a vector of length m, the expression gives the usual matrix product of v times A (it yields a vector of length n).

» index | dic | ict |

Operators

Operators
Binary
Meaning
Examples
+
plus (addition) 1+1, x+2
-
minus (subtraction)
2-1, x-y
*
times (product)
2*3
^
power
2^3
/
quotient (division)
5/4
/
list or vector difference
[1,2,3,4]/[2,4]
//
quotient in Euclidean division
5//4
mod
remainder in Euclidean division
5 mod 4
|
concatenation of vectors and lists [1,1]|[0,2,4]
|
splicing of matrices with the same number or rows

|
logical or
true|false
List|Vector
&
logical and
false & true
&
stacking of vectors of the same length
[1,1] & [2,3]
» [[1,1],[2,3]]
&
stacking of matrices with the same number of columns

\
make postfix a prefix function
36\factor
\\
make postfix and recursive a Substitution call


Unary prefix
Meaning
Examples
+
prefix plus
 +5
-
prefix minus
 -3

Unary postfix
Meaning
Examples
+
prefix plus
 +5
-
prefix minus
 -3
!
factorial (postfix)
  6!
!!
semifactorial (postfix)
10!!
not
logical negation
not false
'
apostrophy: transposition
operator for matrices
([1,1]&[2,2])'
'
apostrophy: derivative operator for
univariate polynomials
(x^2+x)'
' apostrophy: negation of
Boolean values (true' <> false)
false'

» index | dic | ict |


Random numbers

All the calls in this section are named random, but they actually supply pseudorandom numbers, which here, for simplicity, will be called random numbers. For random constructions or choices of other objects, we refer to Random resources in the CC user guide.

random()
Returns a random decimal number in the interval [0,1].

random(a)
If a is a non-zero decimal number, this function returns a random decimal number in the interval [0,a]. If a is a positive integer, it supplies a random integer in the range 0..(a-1).

random(a,b)
If a and b are decimal numbers, this function call supplies a random decimal number in the interval [a,b]. If a and b are integers, with a < b, the function yields a random number in the range a..b.

» index | dic | ict |


Ranges

Range functions
Meaning
Examples
a..b
a..b..1 1..3 »'1,2,3'
a..b..d If a and b are real numbers, the (potential*)
sequence of numbers a+j·d, for j>=0  and a+j·d<=b
10..57..13
» '10,23,36,49'
r·j
If r is a Range, the (actual) j-th member of r,  
provided j is in its range of indices. 
(10..57..13).2
» 23
length(r:Range)
The number of terms in r
length(10..57..13)
» 4
* It means that the actual values of the range are not computed; we indicate this by surrounding the virtual sequence with single quotes. The actual values are determined whenever a given range is involved in some computation.

» index | dic | ict |


Real functions

Function
Meaning
ln(x:Real)
For x>0, the natural logarithm of x
log(x:Real)
For x>0, the decimal logarithm of x
log(x:Real, b:Real)
If x, b>0, the logarithm of x to the base b

» index | dic | ict |


Special symbols

Symbol Meaning
B_
bernoulli_number
(see Combinatorial Functions)
C_ or CC
Complex (see types)
e_
2.7283... decimal representation of e
E_
e (base of natural logarithms)
GF
Finite_field
i_
i (imaginary unit, i2 = -1)
pi_
3.141592... decimal representation of p
Pi_
p
R_ or RR
Real (see Types)
W_
wolpitzki_number
(see Combinatorial Functions)
WB_
wolpitzki_bernoulli_number
(see Combinatorial Functions)
Z_ or ZZ
Integer (see Types)

» index | dic | ict |


Strings

ascii(s), ascii ([c1,...,cr])
If s is a character string, ascii(s) returns a vector [c1,...,cr] whose components are the ASCII codes of the characters in the string. The second form of the call reproduces the string from the vector of codes.

» index | dic | ict |


Types

Chain
Defined as Chain = Range|List|Vector|Relation|Rule

Complex
The complex numbers.

Float
Decimal numbers (up to 15 siginificant decimal digits). pi_ and e_ provide Float representations of π and e=exp(1).

Integer
The integers. Examples: -3, 0, 5, 2^64. Synonyms: ZZ and Z_.

List
The type of lists. Example: {1,a,x^2}.

Matrix
A vector whose components are vectors of the same length. Example: [[1,2],[3,4]] .

Name
Identifiers, including those that have a value assigned.

Nat
Non-negative integer. Examples: 0, 17, 3^11 .

Pos
Positive integers. Examples: 1, 2, 3 .

Range
The type of ranges. A range can be thought as a finite sequence of numbers. Examples: 11..19, 3..29..2 .

Real
The real numbers. Example: Pi_ (the real number π).

Relation
The type of relations. A Relation is a list of objects of the form x->v (relators). Example: {a -> 1, b -> 0, c -> -1}.

Rule
The type of rules. A Rule is a list of objects of the form x=>v. Example: {a=>1, b=>3/2}.

Sequence
The type of sequences. Example: 1, x, 2.

Vector
The type of vectors. Examples: [-1,0,2], [1..10..2].

String
The type of strings of characters. Example: "a1b2xy" .

Vector(T)
The type of vectors whose components have type T. For example, Vector(Integer) is the type of vectors of integers.

» index | dic | ict |


Vectors

[x1,...,xn]
Vector formed whose components are the objects with the objects x1,...,xn.

Examples: [x1,..., xn], [ ] (empty vector), [4,-3,1], [1..8]

[r:Range]
The vector [r1,...,rn] , where n = length(r) and rj (j =1,...,n.

[ e in R such_that P(e)]
If R is a Chain and P a Boolean function defined for any expression e in R, it yields the vector whose components are the elements of R that satisfy P.

Example: [n in 3..100..2 such_that prime?(n)].

x.j
If x is a vector and j an integer in its range of indices, x.j is the j-th component of x.

Example: The value of[2,3,5].2 is 3.

x.r
If x is a vector and r is a range, list or vector, this expression yields the vector whose components are the components of x with index in r.

Example: the value of [1, 4, 9, 25].{2,4} is [4,25].

range(x)
If x is a vector, the value of this expression is the range 1..length(x).

Example: range([1,4,9,25])1..length(x) delivers 1..4.

constant_vector(n, a), constant_vector(n)
For a positive integer n and a value a, this function contructs the vector [a,...,a] (a repeated n times). The second form of the function is equivalent to constant_vector(n, 0).

Example: constant_vector(3) produces [0,0,0].

convolution (u, v, k)
convolution (u, v, R)
If u and v are vectors, convolution (u, v, k) yields the (k-1) -component of the convolution of u and v.

Example: the value of convolution ([a,b], [5,7], 3) is 7a+5b.

If R is a range, list or vector, the second form of the function yields concolution(u,v).R

convolution (u, v)
If u and v are vectors, this function computes the convolution of u and v.

Example: convolution ([a,b], [5,7]) returns [7a, 5a+7b, 5b].

cut_off(x, k)
This function is defined as
	if (k < 0) then [ ]	  
	elif k < length(x) then take(x,k)
	else x
	end
  
Examples: cut_off([x,y,z], 2) returns [x,y] and cut_off([x,y,z], 4) returns [x,y,z].

length(x)
If x is a vector, this expression returns the number of components of x.

purge(x,a)
If x is a vector and a a value, this function yields the vector formed with all the components of x that are different from a.

take (x,k), tail (x)
If x is a vector and k an integer, then take (x,k) returns the vector [x.1,...,x.k] if k is in the range of indices of x and the empty vector [ ] if k = 0. If k-r and r is in the range of indices of x, the result is the vector [x.(n-r+1),...,x.n] (the last k components of x).

tensor(u,v)
[u.i*v.j with (i,j) in (range(u), range(v))]

trim(x), trim_left(x), trim_right(x)
If x is a vector, trim(x) is equivalent to purge(x,0): it is the vector formed with the non-zero components of x. On the other hand, trim_left(x) and trim_right(x) drop the leading and trailing 0's of x, respectively.

vector(x,n)
If x is a name, this function constructs the identifiers x1, x2, ...,xn and returs the vector [x1, x2, ...,xn].

» index | dic | ict |



© S. Xamb贸
Last update: 26.10.2012
SXD