[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Numbers


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.1 idiv, irem

idiv(i1,i2)

:: Integer quotient of i1 divided by i2.

irem(i1,i2)

:: Integer remainder of i1 divided by i2.

return

integer

i1 i2

integer

[0] idiv(100,7);
14
[0] idiv(-100,7);
-14
[1] irem(100,7);
2
[1] irem(-100,7);
-2
References

sdiv, sdivm, srem, sremm, sqr, sqrm, %.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.2 fac

fac(i)

:: The factorial of i.

return

integer

i

integer

[0] fac(50);
30414093201713378043612608166064768844377641568960512000000000000

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.3 igcd,igcdcntl

igcd(i1,i2)

:: The integer greatest common divisor of i1 and i2.

igcdcntl([i])

:: Selects an algorithm for integer GCD.

return

integer

i1 i2 i

integer

[0] A=lrandom(10^4)$
[1] B=lrandom(10^4)$
[2] C=lrandom(10^4)$
[3] D=A*C$
[4] E=A*B$
[5] cputime(1)$
[6] igcd(D,E)$
0.6sec + gc : 1.93sec(2.531sec)
[7] igcdcntl(1)$
[8] igcd(D,E)$  
0.27sec(0.2635sec)
[9] igcdcntl(2)$
[10] igcd(D,E)$  
0.19sec(0.1928sec)
[11] igcdcntl(3)$
[12] igcd(D,E)$  
0.08sec(0.08023sec)
References

gcd, gcdz.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.4 ilcm

ilcm(i1,i2)

:: The integer least common multiple of i1 and i2.

return

integer

i1 i2

integer

References

igcd,igcdcntl, mt_save, mt_load.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.5 isqrt

isqrt(n)

:: The integer square root of n.

return

non-negative integer

n

non-negative integer


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.6 inv

inv(i,m)

:: the inverse (reciprocal) of i modulo m.

return

integer

i m

integer

[71] igcd(1234,4321);  
1
[72] inv(1234,4321);
3239
[73] irem(3239*1234,4321);
1
References

igcd,igcdcntl.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.7 prime, lprime

prime(index)
lprime(index)

:: Returns a prime number.

return

integer

index

integer

[95] prime(0);
2
[96] prime(1228);
9973
[97] lprime(0);
99999989
[98] lprime(999);
0
References

pari.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.8 random

random([seed])
seed
return

non-negative integer

References

lrandom, mt_save, mt_load.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.9 lrandom

lrandom(bit)

:: Generates a long random number.

bit
return

integer

References

random, mt_save, mt_load.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.10 mt_save, mt_load

mt_save(fname)

:: Saves the state of the random number generator.

mt_load(fname)

:: Loads a saved state of the random number generator.

return

0 or 1

fname

string

[340] random();
3510405877
[341] mt_save("/tmp/mt_state");
1
[342] random();
4290933890
[343] quit;
% asir
This is Asir, Version 991108.
Copyright (C) FUJITSU LABORATORIES LIMITED.
3 March 1994. All rights reserved.
[340] mt_load("/tmp/mt_state");
1
[341] random();
4290933890
References

random, lrandom.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.11 nm, dn

nm(rat)

:: Numerator of rat.

dn(rat)

:: Denominator of rat.

return

integer or polynomial

rat

rational number or rational expression

[2] [nm(-43/8),dn(-43/8)];
[-43,8]
[3] dn((x*z)/(x*y));
y*x
[3] dn(red((x*z)/(x*y)));
y
References

red.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.12 conj, real, imag

real(comp)

:: Real part of comp.

imag(comp)

:: Imaginary part of comp.

conj(comp)

:: Complex conjugate of comp.

return comp

complex number

[111] A=(2+@i)^3; 
(2+11*@i)
[112] [real(A),imag(A),conj(A)];
[2,11,(2-11*@i)]

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.13 eval, deval

eval(obj[,prec])
deval(obj)

:: Evaluate obj numerically.

return

number or expression

obj

general expression

prec

integer

[118] eval(exp(@pi*@i));   
-1.0000000000000000000000000000
[119] eval(2^(1/2));
1.414213562373095048763788073031
[120] eval(sin(@pi/3));
0.86602540378443864674620506632
[121] eval(sin(@pi/3)-3^(1/2)/2,50);
-2.78791084448179148471 E-58
[122] eval(1/2);
1/2
[123] deval(sin(1)^2+cos(1)^2);
1
References

ctrl, setbprec, setprec.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.14 pari

pari(func,arg,prec)

:: Call PARI function func.

return

Depends on func.

func

Function name of PARI.

arg

Arguments of func.

prec

integer

/* Eigen vectors of a numerical matrix */
[0] pari(eigen,newmat(2,2,[[1,1],[1,2]]));
[ -1.61803398874989484819771921990 0.61803398874989484826 ]
[ 1 1 ]
/* Roots of a polynomial */
[1] pari(roots,t^2-2);
[ -1.41421356237309504876 1.41421356237309504876 ]
References

setbprec, setprec.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.15 setbprec, setprec

setbprec([n])
setprec([n])

:: setbprec, setprec set the precision for bigfloat operations to n bits, n digits respectively.

return

integer

n

integer

[1] setprec();
15
[2] setprec(100);
15
[3] setprec(100);
99
[4] setbprec();
332

ctrl, eval, deval.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.16 setround

setround([mode])

:: Sets the rounding mode mode.

return

integer

mode

integer

[1] setprec();
15
[2] setprec(100);
15
[3] setprec(100);
99
[4] setbprec();
332

ctrl, eval, deval.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.17 setmod

setmod([p])

:: Sets the ground field to GF(p).

return

integer

n

prime less than 2^27

[0] A=dp_mod(dp_ptod(2*x,[x]),3,[]);
(2)*<<1>>
[1] A+A;
addmi : invalid modulus
return to toplevel
[1] setmod(3);
3
[2] A+A;
(1)*<<1>>
References

dp_mod, dp_rat, Types of numbers.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.18 ntoint32, int32ton

ntoint32(n)
int32ton(int32)

:: Type-conversion between a non-negative integer and an unsigned 32bit integer.

return

unsigned 32bit integer or non-negative integer

n

non-negative integer less than 2^32

int32

unsigned 32bit integer

References

Distributed computation, Types of numbers.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.19 inttorat

inttorat(a,m,b)

:: Perform the rational reconstruction.

return

list or 0

a
m
b

integer

[2121] M=lprime(0)*lprime(1);
9996359931312779
[2122] B=isqrt(floor(M/2));
70697807
[2123] A=234234829304;
234234829304
[2124] inttorat(A,M,B);
[-20335178,86975031]
References

ceil, floor, rint, dceil, dfloor, drint, isqrt.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on December 30, 2024 using texi2html 5.0.