This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ntl.py
232 lines (154 loc) · 6.6 KB
/
ntl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# -*- coding: utf-8 -*-
'''
Alternative declaration:
__import__([folder.]module).[module.]function(*args, **kwargs)
'''
from .NTLArchive import NTLCongruence
from .NTLArchive import NTLFraction
from .NTLArchive import NTLIndex
from .NTLArchive import NTLJacobi
from .NTLArchive import NTLLegendre
from .NTLArchive import NTLPolynomial
from .NTLArchive import NTLQuadratic
__all__ = [
'Congruence', 'Fraction', 'Index', 'Jacobi', 'Legendre', 'Polynomial', 'Quadratic',
'bezout', 'binary', 'carmicheal', 'congsolve', 'coprime', 'crt', 'decomposit',
'eealist', 'euler', 'factor', 'fraction', 'gcd', 'isdivisible', 'isprime',
'jacobi', 'lcm', 'legendre', 'modulo', 'ord', 'polydiv', 'prc', 'prime', 'primelist',
'pseudo', 'quadratic', 'root', 'simplify'
]
##############################################################################
# Class session.
##############################################################################
# Derives from Congruence class.
class Congruence(NTLCongruence.Congruence):
pass
# Derives from Fraction class.
class Fraction(NTLFraction.Fraction):
pass
# Derives from Index class.
class Index(NTLIndex.Index):
pass
# Derives from Jacobi class.
class Jacobi(NTLJacobi.Jacobi):
pass
# Derives from Legendre class.
class Legendre(NTLLegendre.Legendre):
pass
# Derives from Polynomial class.
class Polynomial(NTLPolynomial.Polynomial):
pass
# Derives from Quadratic class.
class Quadratic(NTLQuadratic.Quadratic):
pass
##############################################################################
# Method session.
##############################################################################
# Returns the parameters of a and b in Bézout equation.
def bezout(a, b):
from .NTLArchive import NTLBezoutEquation
return NTLBezoutEquation.bezoutEquation(a, b)
# Returns the special solutions for indefinite binary equation, a*x + b*y = c.
def binary(a, b, c):
from .NTLArchive import NTLBinaryEquation
return NTLBinaryEquation.binaryEquation(a, b, c)
# Returns if an integer is a Carmicheal number.
def carmicheal(N):
from .NTLArchive import NTLCarmichealTest
return NTLCarmichealTest.carmichealTest(N)
# Returns the solutions of a polynomial congruence.
def congsolve(cgcExp, cgcCoe, modulo, **kwargs):
from .NTLArchive import NTLPolynomialCongruence
return NTLPolynomialCongruence.polynomialCongruence(cgcExp, cgcCoe, modulo, **kwargs)
# Returns if a and b are coprime numbers.
def coprime(a, b):
from .NTLArchive import NTLCoprimalityTest
return NTLCoprimalityTest.coprimalityTest(a, b)
# Returns the solutions of a naïve congruence set.
def crt(*args):
from .NTLArchive import NTLChineseRemainderTheorem
return NTLChineseRemainderTheorem.CHNRemainderTheorem(*args)
# Returns the solutions for N|a^2-b^2 while N∤a+b and N∤a-b.
def decomposit(N, **kwargs):
from .NTLArchive import NTLQuadraticFactorisation
return NTLQuadraticFactorisation.quadraticFactorisation(N, **kwargs)
# Returns list of the quotients with extended Euclidean Algorithm.
def eealist(a, b):
from .NTLArchive import NTLEuclideanAlgorithm
return NTLEuclideanAlgorithm.euclideanAlgorithm(a, b)
# Returns Euler function φ(m).
def euler(m):
from .NTLArchive import NTLEulerFunction
return NTLEulerFunction.eulerFunction(m)
# Returns the prime factor list of N.
def factor(N, **kwargs):
from .NTLArchive import NTLPrimeFactorisation
return NTLPrimeFactorisation.primeFactorisation(N, **kwargs)
# Returns the continued fraction of a real number.
def fraction(n, d=None):
from .NTLArchive import NTLContinuedFraction
return NTLContinuedFraction.continuedFraction(n, d)
# Returns the greatest common divisor of a and b.
def gcd(a, b):
from .NTLArchive import NTLGreatestCommonDivisor
return NTLGreatestCommonDivisor.greatestCommonDivisor(a, b)
# Returns if a and b are divisible.
def isdivisible(a, b):
from .NTLArchive import NTLEuclideanDivision
return NTLEuclideanDivision.euclideanDivision(a, b)
# Returns if N is a prime.
def isprime(N):
from .NTLArchive import NTLTrivialDivision
return NTLTrivialDivision.trivialDivision(N)
# Returns the result of Jacobi symbol for (a | m).
def jacobi(a, m):
from .NTLArchive import NTLJacobiSymbol
return NTLJacobiSymbol.jacobiSymbol(a, m)
# Returns the least common multiple of a and b.
def lcm(a, b):
from .NTLArchive import NTLLeastCommonMultiple
return NTLLeastCommonMultiple.leastCommonMultiple(a, b)
# Returns the result of Legendre symbol for (a | p).
def legendre(a, p, **kwargs):
from .NTLArchive import NTLLegendreSymbol
return NTLLegendreSymbol.legendreSymbol(a, p, **kwargs)
# Returns the result of b^e (mod m).
def modulo(b, e, m):
from .NTLArchive import NTLRepetiveSquareModulo
return NTLRepetiveSquareModulo.repetiveSquareModulo(b, e, m)
# Returns the order of an integer (a) for a modulo (m), i.e. ord_m(a).
def ord(m, a):
from .NTLArchive import NTLOrder
return NTLOrder.order(m, a)
# Returns quotient and remainder after polynomial Euclidean division.
def polydiv(dvdExp, dvdCoe, dvsExp, dvsCoe):
from .NTLArchive import NTLPolynomialEuclideanDivision
return NTLPolynomialEuclideanDivision.polyED(dvdExp, dvdCoe, dvsExp, dvsCoe)
# Returns the primitive residue class of an integer m.
def prc(m):
from .NTLArchive import NTLPrimitiveResidueClass
return NTLPrimitiveResidueClass.primitiveResidueClass(m)
# Retern iterator of prime numbers between lower and upper bound with steps.
def prime(upper, lower=None, steps=None):
from .NTLArchive import NTLEratosthenesSieve
return NTLEratosthenesSieve.primerange(upper, lower, steps)
# Returns all prime numbers between lower and upper bound with steps.
def primelist(upper, lower=None):
from .NTLArchive import NTLEratosthenesSieve
return NTLEratosthenesSieve.eratosthenesSieve(upper, lower)
# Returns a pseudo-prime number with certain paterns.
def pseudo(**kwargs):
from .NTLArchive import NTLPseudoPrime
return NTLPseudoPrime.pseudoPrime(**kwargs)
# Returns the solutions of a quadratic equation.
def quadratic(p, **kwargs):
from .NTLArchive import NTLQuadraticEquation
return NTLQuadraticEquation.quadraticEquation(p, **kwargs)
# Returns the primitive root(s) of modulo (m).
def root(m):
from .NTLArchive import NTLPrimitiveRoot
return NTLPrimitiveRoot.primitiveRoot(m)
# Returns the result after congruence simplification.
def simplify(cgcExp, cgcCoe, modulo, **kwargs):
from .NTLArchive import NTLCongruenceSimplification
return NTLCongruenceSimplification.congruenceSimplification(cgcExp, cgcCoe, modulo, **kwargs)