Div , Mod , Gcd , Lcm , << , >> , FromBase , ToBase , Precision , GetPrecision , Rationalize , IsPrime , IsPrimePower , Factors , PAdicExpand , ContFrac , Decimal , TruncRadian , Other operations on numbers

Other operations on numbers


Div and Mod

Standard math library
Calling Sequence:
Div(x,y)
Mod(x,y)
Parameters:
x and y - integers
Description:
Div performs integer division and Mod returns the remainder after division. Div and Mod are also defined for polynomials.
Examples:
In> Div(5,3)
Out> 1;
In> Mod(5,3)
Out> 2;
See Also:


Gcd

Standard math library
Calling Sequence:
Gcd(n,m)
Gcd(list)
Parameters:
n,m - integers or univariate polynomials
list - a list of all integers or all univariate polynomials
Description:
Gcd(n,m) returns the greatest common divisor of n and m. The gcd is the largest number that divides n and m. The library code calls MathGcd, which is an internal function. This function implements the binary Euclidean algorithm for determining the greatest common divisor:
Routine for calculating Gcd(n,m)

1) if n = m then return n
2) if both n and m are even then return 2*Gcd(n/2,m/2)
3) if exactly one of n or m (say n) is even then return Gcd(n/2,m)
4) if both n and m are odd and, say, n>m then return Gcd( (n-m)/2,m)
This is a rather fast algorithm on computers that can efficiently shift integers.
Gcd(list), with list a list of arbitrary length of integers, will return the greatest common divisor of all the integers listed. For lists Gcd uses the identity
Gcd({a,b,c}) = Gcd(Gcd(a,b),c)
Examples:
In> Gcd(55,10)
Out> 5;
In> Gcd({60,24,120})
Out> 12;
See Also:
Lcm ,


Lcm

Standard math library
Calling Sequence:
Lcm(n,m)
Parameters:
n,m - integers
Description:
Lcm(n,m) : returns the least common multiple of a and b. The least common multiple L of two numbers n,m is the number L=Lcm(n,m) for which there are two integers p,q so such that p*n=q*m=L. This is calculated with the formula:
Lcm(n,m) = Div(n*m,Gcd(n,m))
This means it also works on polynomials, since Div, Gcd and multiplication are also defined for them.
Examples:
In> Lcm(60,24)
Out> 120;
See Also:
Gcd ,


<< and >>

Standard math library
Calling Sequence:
n<<m and n>>m
Parameters:
n,m - integers
Description:
These operators shift integers to the left or to the right. They are similar to the c shift operators. These are sign-extended shifts, so they act like multiplication or division by powers of 2.
Examples:
Examples:
1<<10; should evaluate to 1024
-1024>>10; should evaluate to -1


FromBase(base,number)

FromBase(base,number) : Conversion of numbers to base 10 numbers. Example: "ToBase(2,255);" should return "11111111".


ToBase(base,number)

ToBase(base,number) : Conversion of numbers from base 10 numbers. Example: "ToBase(16,255);" should return "ff".


Precision(n)

Precision(n) : Specifies that calculations should be performed with a precision of "n" digits.


GetPrecision()

GetPrecision() : return the current precision used for calculations.


Rationalize(x)

Rationalize(x) : Convert all floating point numbers to rationals in expression x.


IsPrime(n)

IsPrime(n) : returns True if n is prime, False otherwise.


IsPrimePower(n)

IsPrimePower(n) : returns True if there is a prime p such that p^m = n.


Factors(n)

Factors(n) : factorizes n. Returns a list containing the factors.


PAdicExpand(n,p)

PAdicExpand returns the p-adic expansion of n:

n = a0 +a1*p +a2*p^2+...

So for instance
In> PrettyForm(PAdicExpand(1234,10))

                   2     3
4 + 3 * 10 + 2 * 10  + 10 

Out> True;
This function should also work on polynomials.


ContFrac(x) or ContFrac(x,maxdepth)

Return the continued fraction expansion of a floating point number. Example:
In> PrettyForm(ContFrac(N(Pi)))

                 1             
3 + ---------------------------
                   1           
    7 + -----------------------
                     1         
        15 + ------------------
                       1       
             1 + --------------
                          1    
                 292 + --------
                       1 + rest


Decimal(frac)

Decimal(frac) : return the infinite decimal representation of a number. This function returns a list, with the first element being the number before the decimal point and the last element the sequence of digits that will repeat forever. All the intermediate list elements are the initial digits.

Example:
In> Decimal(1/22)
Out> {0,0,{4,5}};
In> N(1/22,30)
Out> 0.045454545454545454545454545454;


TruncRadian

Standard math library
Calling Sequence:
TruncRadian(r)
Parameters:
r - a radian
Description:
TruncRadian calculates r mod 2*Pi, returning a value between 0 and 2*Pi. This function is used in the trigonometry functions, just before doing the numerical calculation. It greatly speeds up the calculation if the value passed is a big number.

The library uses the formula

             /   r    \         
r - MathFloor| ------ | * 2 * Pi
             \ 2 * Pi /         


where r and 2*Pi are calculated with twice the precision used in the environment to make sure there is no rounding error in the significant digits.

Examples:
In> 2*Pi()
Out> 6.283185307;
In> TruncRadian(6.28)
Out> 6.28;
In> TruncRadian(6.29)
Out> 0.0068146929;
See Also:
Sin , Cos , Tan ,