Number Theory¶
General Functions¶
-
simula.ntheory.functions.
Abs
(f)¶ Returns the absolute value of
f
i. e |f|.EXAMPLES:
simula : Abs(2-pi) -2 + pi simula : Abs(x) Abs(x)
-
class
simula.ntheory.functions.
Integer
(i)¶
-
class
simula.ntheory.functions.
IntegerFactorization
(i)¶ Representation of the prime decomposition of an integer.
-
simula.ntheory.functions.
Max
(*args)¶ Returns the maximum of
args
.EXAMPLES:
simula : Max(4, 8, 9, 5) 9 simula : Max([4, 8, 9, 5, 20]) 20
-
simula.ntheory.functions.
Min
(*args)¶ Returns the minimun of
args
.EXAMPLES:
simula : Min(4, 8, 9, 5) 4 simula : Min([4, 8, 9, 2, 5, 20]) 2
-
simula.ntheory.functions.
Mod
(g, f)¶ Represents a modulo operation on symbolic expressions i. e
g
modulof
.
-
simula.ntheory.functions.
N
(x, *, precision=15)¶ Returns a numerical approximation of
x
for a given precisionprecision
(default : 15).EXAMPLES :
simula : numerical_approx(pi) 3.141592653589793 simula : numerical_approx(pi, precision=20) 3.14159265358979323846
-
simula.ntheory.functions.
beta
(a, b)¶ Returns Beta(a, b).
EXAMPLES:
simula : beta(3, 1) 1/3 simula : numerical_approx(beta(2, 2)) 0.1666666666666667
-
simula.ntheory.functions.
binomial
(n, k)¶ Returns the binomial coefficient \(\dfrac{n!}{(n-k)! \times k! }\).
-
simula.ntheory.functions.
ceil
(a)¶ Returns the smallest integer value not less than
a
.
-
simula.ntheory.functions.
denominator
(expr)¶ Returns the denominator of
expr
.EXAMPLES:
simula : f = 2/(sqrt(3)-1); f 2 simula : denominator(f) -1 + sqrt(3) simula : denominator(3pi/5) 5
-
simula.ntheory.functions.
ellipsis_range
(a, b, c=None)¶ Returns
[a, b, a + (b-a), ..., c]
ifc
is notNone
otherwise[a, a+1, ..., b]
.EXAMPLES:
simula : ellipsis_range(2, 5) [2, 3, 4, 5] simula : ellipsis_range(2, 3, 10) [2, 3, 4, 5, 6, 7, 8, 9, 10] simula : ellipsis_range(1, 1.5, 5) [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]
-
simula.ntheory.functions.
euler_phi
(n)¶ Returns the image of the Euler totient function at n.
EXAMPLES:
simula : euler_phi(3) 2 simula : euler_phi(10) 4 simula : euler_phi(15) 8
-
simula.ntheory.functions.
evalf
(x, *, precision=15)¶ Returns a numerical approximation of
x
for a given precisionprecision
(default : 15).EXAMPLES :
simula : numerical_approx(pi) 3.141592653589793 simula : numerical_approx(pi, precision=20) 3.14159265358979323846
-
simula.ntheory.functions.
factorial
(n)¶ Returns the factorial of
n
.- Paramètres
n – a nonnegative integer
EXAMPLES:
simula : factorial(4) 24 simula : factorial(5) 120
-
simula.ntheory.functions.
floor
(a)¶ Returns the largest integer value not greater than
a
.
-
simula.ntheory.functions.
fraction
(a, b=1)¶ Returns
a/b
.EXAMPLES:
simula : fraction(3,5) 3/5
-
simula.ntheory.functions.
gamma
(n)¶ Returns gamma(n).
EXAMPLES:
simula : gamma(2) 1 simula : gamma(6) 120 simula : gamma(2.5) 1.32934038817914
-
simula.ntheory.functions.
integer_decomposition
(n)¶ Returns the prime decomposition of the integer
n
.
-
simula.ntheory.functions.
inverse_mod
(a, n)¶ Returns the inverse of
a
modn
provided thata
is prime withn
.EXAMPLES:
simula : inverse_mod(2, 5) 3 simula : inverse_mod(4, 7) 2
-
simula.ntheory.functions.
is_prime
(n)¶ Tests if
n
is a prime number.- Paramètres
n – a nonnegative integer
EXAMPLES:
simula : is_prime(5) True simula : is_prime(201) False
-
simula.ntheory.functions.
is_primitive_root
(a, p)¶ Tests if
a
is a primitive root ofp
.- Paramètres
a – an integer
p – a prime number.
EXAMPLES:
simula : is_primitive_root(2, 5) True simula : is_primitive_root(3, 11) False
-
simula.ntheory.functions.
is_quad_residue
(a, p)¶ Tests if
a
modulop
is in the set of squares modp`
.- Paramètres
a – an integer
p – a prime number.
EXAMPLES:
simula : is_quad_residue(2, 5) False simula : is_quad_residue(3, 11) True
-
simula.ntheory.functions.
jacobi_symbol
(m, n)¶ Returns the Jacobi symbol
(m / n)
.- Paramètres
m – an integer
n – an odd positive integer
EXAMPLES:
simula : jacobi_symbol(7, 15) -1 simula : jacobi_symbol(2, 33) 1
-
simula.ntheory.functions.
legendre_symbol
(a, p)¶ Returns the Legendre symbol
(m / n)
.- Paramètres
m – an integer
n – an odd prime number
EXAMPLES:
simula : legendre_symbol(7, 11) -1 simula : legendre_symbol(3, 37) 1
-
simula.ntheory.functions.
list_divisors
(n, *, proper=False)¶ Return all divisors of
n
sorted from1
ton
.- Paramètres
n – an integer
proper – (a boolean, default
False
) specify ifn
is included to the list o divisors or not.
EXAMPLES:
simula : list_divisors(10) [1, 2, 5, 10] simula : list_divisors(10, proper=True) [1, 2, 5]
-
simula.ntheory.functions.
loggamma
(n)¶ Returns log(gamma(n)).
EXAMPLES:
simula : loggamma(1) 0 simula : loggamma(2) log(2)
-
simula.ntheory.functions.
mobius
(n)¶ Returns
mobius(n)
which maps natural number to {-1, 0, 1}.- Paramètres
n – a positive integer
EXAMPLES:
simula : mobius(2) -1 simula : mobius(15) 1
-
simula.ntheory.functions.
multiplicity
(m, n)¶ Returns the greatest integer
k
such thatm^k
dividesn
.- Paramètres
m – an integer
n – an integer
EXAMPLES:
simula : multiplicity(10, 100) 2 simula : multiplicity(3, 36) 2
-
simula.ntheory.functions.
n
(x, *, precision=15)¶ Returns a numerical approximation of
x
for a given precisionprecision
(default : 15).EXAMPLES :
simula : numerical_approx(pi) 3.141592653589793 simula : numerical_approx(pi, precision=20) 3.14159265358979323846
-
simula.ntheory.functions.
nAk
(n, k)¶ Returns the
k
-arrangement inn
i.e. \(\dfrac{n!}{(n-k)!}\).
-
simula.ntheory.functions.
nCk
(n, k)¶ Returns the binomial coefficient \(\dfrac{n!}{(n-k)! \times k! }\).
-
simula.ntheory.functions.
next_prime
(n)¶ Returns the i-th prime number greater than
n
.- Paramètres
n – an integer
EXAMPLES:
simula : next_prime(4) 5 simula : next_prime(23) 29
-
simula.ntheory.functions.
nthroot_mod
(a, n, p, *, all_roots=False)¶ Returns the solutions to
x^n = a mod p
.- Paramètres
a – an integer
n – a positive integer
p – a positive integer
all_roots – (default
False
) ifFalse
returns the smallest root, else the list of roots
EXAMPLES:
simula : nthroot_mod(1, 2, 7) 1 simula : nthroot_mod(1, 2, 7, all_roots=True) [1, 6]
-
simula.ntheory.functions.
number_divisors
(n, *, proper=False)¶ Return the number of divisors of
n
.- Paramètres
n – an integer
proper – (default
False
) IfTrue
then the divisor ofn
will not be counted
EXAMPLES:
simula : number_divisors(10) 4 simula : number_divisors(10, proper=True) 3
-
simula.ntheory.functions.
numerator
(expr)¶ Returns the numerator of
expr
.EXAMPLES:
simula : f = 2/(sqrt(3)-1); f 2/(-1 + sqrt(3)) simula : numerator(f) 2 simula : numerator(3pi/5) 3pi
-
simula.ntheory.functions.
numerical_approx
(x, *, precision=15)¶ Returns a numerical approximation of
x
for a given precisionprecision
(default : 15).EXAMPLES :
simula : numerical_approx(pi) 3.141592653589793 simula : numerical_approx(pi, precision=20) 3.14159265358979323846
-
simula.ntheory.functions.
order_modulo
(a, n)¶ Returns the order of
a
modulon
.- Paramètres
a – an integer
n – an integer relatively prime to
a
EXAMPLES:
simula : order_modulo(2, 9) 6 simula : order_modulo(3, 11) 5
-
simula.ntheory.functions.
perfect_power
(n)¶ Returns
(a, e)
such that \(n=a^e\) ifn
is a perfect power withe > 1
, elseFalse
.- Paramètres
n – an integer
EXAMPLES:
simula : perfect_power(6) False simula : perfect_power(100) (10, 2) simula : perfect_power(16807) (7, 5)
-
simula.ntheory.functions.
power_mod
(x, a, n)¶ Returns the power
x^a mod n
.EXAMPLES:
simula : power_mod(100, 10000, 11) 1 simula : power_mod(99, 99876655, 13) 5
-
simula.ntheory.functions.
previous_prime
(n)¶ Returns the i-th prime number less than
n
.- Paramètres
n – an integer
EXAMPLES:
simula : previous_prime(4) 3 simula : previous_prime(23) 19
-
simula.ntheory.functions.
prime_factors
(n)¶ Returns a sorted list of
n
’s prime factors, ignoring multiplicity.- Paramètres
n – an integer
EXAMPLES:
simula : prime_factors(6) [2, 3] simula : prime_factors(20) [2, 5]
-
simula.ntheory.functions.
prime_pi
(n)¶ Returns
pi(n)
the number of prime numbers less than or equal ton
.- Paramètres
n – an integer
EXAMPLES:
simula : prime_pi(4) 2 simula : prime_pi(20) 8
-
simula.ntheory.functions.
prime_position
(n)¶ Returns the n-th prime number.
- Paramètres
n – a positive integer
EXAMPLES:
simula : prime_position(1) 2 simula : prime_position(2) 3 simula : prime_position(10) 29
-
simula.ntheory.functions.
prime_range
(a, b)¶ Returns the list of primes between
a
andb
.
-
simula.ntheory.functions.
primes
(start, end)¶ Generators of primes between
start
andend
(both included).EXAMPLES:
simula : 11 in primes(10, 40) True simula : for i in primes(10, 40): . . . . . . : print(i) 11 13 17 19 23 29 31 37
-
simula.ntheory.functions.
primitive_root
(n)¶ Returns the smallest primitive root modulo n or Raise an exception
valueError
.EXAMPLES:
simula : primitive_root(7) 3 simula : primitive_root(10) 3 simula : primitive_root(29) 2
-
simula.ntheory.functions.
primitive_root_mod
(n)¶ Returns the smallest primitive root or
None
.- Paramètres
n – a positive integer
EXAMPLES:
simula : primitive_root_mod(4) 3 simula : primitive_root_mod(20) simula : primitive_root_mod(19) 2
-
simula.ntheory.functions.
quadratic_residues
(n)¶ Returns the set of quadratic residues mod
n
.- Paramètres
n – a positive integer
EXAMPLES:
simula : quadratic_residues(4) {0, 1} simula : quadratic_residues(20) {0, 1, 4, 5, 9, 16}
-
simula.ntheory.functions.
randint
(a, b=None)¶ Returns a random integer between
a
andb
ifb
is notNone` otherwise between ``0
and ``a`.- Paramètres
b (Optional[int]) –
-
simula.ntheory.functions.
random_prime
(a, b=None)¶ Returns randomly a prime number between
a
andb
.- Paramètres
b (Optional[int]) –
-
simula.ntheory.functions.
random_prime_size
(size)¶ Returns randomly a prime of size
size
bits.- Paramètres
size (int) –
-
simula.ntheory.functions.
rationalize_denominator
(expr)¶ Rationalizes the denominator of
expr
.EXAMPLES:
simula : f = 2/(sqrt(3)-1); f 2/(-1 + sqrt(3)) simula : rationalize_denominator(f) 1 + sqrt(3) simula : rationalize_denominator(1/(5-sqrt(11))) (sqrt(11) + 5)/14
- Paramètres
expr (sympy.core.expr.Expr) –
-
simula.ntheory.functions.
sign
(x)¶ Returns the sign of
x
.EXAMPLES:
simula : sign(2-pi) -1 simula : sign(2-sqrt(3)) 1
-
simula.ntheory.functions.
sqrt_mod
(a, n, all_roots=False)¶ Returns a root of \(x^2 = a \mod n\) or
None
.- Paramètres
a – an integer
n – a positive integer
all_roots – (default
False
) ifTrue
the list of roots is returned orNone
EXAMPLES:
simula : sqrt_mod(4, 7) 2 simula : sqrt_mod(4, 7, all_roots=True) [2, 5] simula : sqrt_mod(5, 11, all_roots=True) [4, 7] simula : sqrt_mod(5, 10, all_roots=True) [5]
-
simula.ntheory.functions.
srange
(start, stop=None, step=1)¶ Returns all integers from
start
tostop
provided thatstop
is notNone
otherwise returns all integers from0
tostart
for a given step` (default is1
).EXAMPLES:
simula : srange(2, 9) [2, 3, 4, 5, 6, 7, 8] simula : srange(9, 0, -1) [9, 8, 7, 6, 5, 4, 3, 2, 1]
Complex Numbers¶
Functions acting on Complex numbers
-
simula.ntheory.complexe.
argument
(z)¶ return the argument of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : argument(1-I) -pi/4 simula : argument(I) pi/2
-
simula.ntheory.complexe.
complex_alg_form
(z)¶ return the algebraic form of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : z = 1/(1 - I); z (1 + I)/2 simula : complex_alg_form(z) 1/2 + I/2
-
simula.ntheory.complexe.
complex_exp_form
(z)¶ return the exponential form of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : complex_exp_form(1 - I) 'sqrt(2)*exp(-I*pi/4)' simula : complex_exp_form(-I) 'exp(-I*pi/2)'
-
simula.ntheory.complexe.
complex_trig_form
(z)¶ return the trigonometric form of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : complex_trig_form(1 - I) 'sqrt(2)(cos(-pi/4)+I*sin(-pi/4))' simula : complex_trig_form(-I) 'cos(-pi/2)+I*sin(-pi/2)'
-
simula.ntheory.complexe.
complexe
(a, b=0)¶ return the complex number
a + bI
.- Paramètres
a (int) – an real number
b – an real number
EXAMPLES:
simula : complex(2, 6) 2 + 6I simula : complex(1, 1) 1 + I
-
simula.ntheory.complexe.
conjugate
(z)¶ return the conjugate of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : conjugate(1-I) 1 + I simula : conjugate(1-I)(6I) -6I
-
simula.ntheory.complexe.
im_part
(z)¶ return the imaginary part of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : im_part(1-I) -1 simula : im_part(6I) 6
-
simula.ntheory.complexe.
imag_part
(z)¶ return the imaginary part of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : im_part(1-I) -1 simula : im_part(6I) 6
-
simula.ntheory.complexe.
module
(z)¶ return the module of
z
i.e. |z|.- Paramètres
z – a complex number
EXAMPLES:
simula : module(1-I) sqrt(2) simula : module(-I) 1
-
simula.ntheory.complexe.
real_part
(z)¶ return the real part of
z
.- Paramètres
z – a complex number
EXAMPLES:
simula : real_part(1-I) 1 simula : real_part(6I) 0