In> Div(5,3) Out> 1; In> Mod(5,3) Out> 2; |
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) |
Gcd({a,b,c}) = Gcd(Gcd(a,b),c) |
In> Gcd(55,10) Out> 5; In> Gcd({60,24,120}) Out> 12; |
Lcm(n,m) = Div(n*m,Gcd(n,m)) |
In> Lcm(60,24) Out> 120; |
Examples: 1<<10; should evaluate to 1024 -1024>>10; should evaluate to -1 |
These functions use the p-adic expansion capabilities of the built-in arbitrary precision math libraries.
In> FromBase(2,111111) Out> 63; In> ToBase(16,255) Out> ff; |
In> Precision(10) Out> True; In> N(Sin(1)) Out> 0.8414709848; In> Precision(20) Out> True; In> N(Sin(1)) Out> 0.84147098480789650665; In> GetPrecision() Out> 20; |
In addition, the variable Pi is bound to the value of pi up to the required precision.
In> 1/2 Out> 1/2; In> N(1/2) Out> 0.5; In> Sin(1) Out> Sin(1); In> N(Sin(1),10) Out> 0.8414709848; In> Pi Out> Pi; In> N(Pi,20) Out> 3.14159265358979323846; |
It does this by finding the smallest integer n such that multiplying the number with 10^n is an integer. Then it divides by 10^n again, depending on the internal gcd calculation to reduce the resulting division of integers.
In> Sin(1.234) Out> Sin(1.234); In> Rationalize(%) Out> Sin(617/500); |
The result of Factors is a list of lists of the form {p,n}, where each p^n divides the original x.
Factor shows the result of Factors in a nicer human readable format.
In> Factors(12) Out> {{2,2},{3,1}}; In> PrettyForm(Factor(12)) 2 2 * 3 |
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; |
In> PrettyForm(ContFrac(N(Pi))) 1 3 + --------------------------- 1 7 + ----------------------- 1 15 + ------------------ 1 1 + -------------- 1 292 + -------- 1 + rest |
Example:
In> Decimal(1/22) Out> {0,0,{4,5}}; In> N(1/22,30) Out> 0.045454545454545454545454545454; |
The library uses the formula
/ r \ r - MathFloor| ------ | * 2 * Pi \ 2 * Pi / |
In> 2*Pi() Out> 6.283185307; In> TruncRadian(6.28) Out> 6.28; In> TruncRadian(6.29) Out> 0.0068146929; |
In> Floor(1.1) Out> 1; In> Floor(-1.1) Out> -2; |
In> Ceil(1.1) Out> 2; In> Ceil(-1.1) Out> -1; |
In> Round(1.49) Out> 1; In> Round(1.51) Out> 2; In> Round(-1.49) Out> -1; In> Round(-1.51) Out> -2; |
In> Pslq({ 2*Pi+3*Exp(1) , Pi , Exp(1) },20) Out> {1,-2,-3}; |