Algebraic
ExtendedEuclideanAlgorithm
extended Euclidean algorithm for polynomials with algebraic number coefficients
Calling Sequence
Parameters
Options
Description
Examples
ExtendedEuclideanAlgorithm(a, b, x, 's', 't', options)
Gcdex(a, b, x, 's', 't', options)
a,b
-
polynomials in x with algebraic number coefficients
x
name
s, t
(optional) unevaluated names
options
(optional) equation(s) of the form keyword = value, where keyword is either 'symbolic', 'makeindependent', or 'characteristic'
If the option 'symbolic'=true is given and a RootOf whose minimal polynomial factors nontrivially is detected, ExtendedEuclideanAlgorithm will reduce it to a RootOf of lower degree by picking one of the factors arbitrarily. This will eliminate the possibility of a "reducible RootOf detected" error. The default is 'symbolic'=false.
If the option characteristic=p is given, where p is a nonnegative integer, the computation is performed over an extension of the ring ℤp of integers modulo p. The default is characteristic=0 and means that the gcd is computed over an extension of the rational numbers.
Note that if p is positive but not a prime, then ℤp is not a field, and the greatest common divisor may not exist or may not be unique. ExtendedEuclideanAlgorithm will attempt to perform the computation anyway. If it does not succeed because it encounters an integer that has no inverse modulo p, it issues the error "zero divisor modulo p detected".
If the option 'makeindependent'=true is given, then ExtendedEuclideanAlgorithm will always try to find a field representation for algebraic numbers in the input, regardless of how many algebraic objects the input contains. If the input contains many RootOfs, then this can be a very expensive calculation. If 'makeindependent'=false is given, then no independence checking is performed. The default is 'makeindependent'=FAIL, in which case algebraic dependencies will only be checked for if there are 4 or fewer algebraic objects in the input.
The ExtendedEuclideanAlgorithm command performs the extended Euclidean algorithm on a and b, polynomials in x. It computes and returns g, the greatest common divisor (gcd) of a and b, which is a monic polynomial in x. Additionally, the parameters `s` and `t`, if included, will be assigned the values of polynomials in x such that a⁢s+b⁢t=g, where degree⁡s,x<degree⁡b,x and degree⁡t,x<degree⁡a,x.
The inputs a and b may contain algebraic number coefficients. These may be represented by radicals or with the RootOf notation (see type,algnum, type,radnum). In general, algebraic numbers will be returned in the same representation as they were received in. Nested radicals and RootOfs are also supported.
Note that ExtendedEuclideanAlgorithm cannot be used to perform the extended Euclidean algorithm on two constants, e.g., in the ring of integers. It returns 1 for the gcd of two nonzero constants. Use the igcdex command to perform the extended Euclidean algorithm on integers.
The arguments a and b must be univariate polynomials in the variable x, which is typically a name. If other names or non-algebraic sub-expressions are included and they cannot be evaluated to algebraic numbers, an "unable to compute gcdex of multivariate polynomials" error will be returned.
x can also be a function such as sin⁡x, in which case it will be frozen and replaced by a new local variable. However, functions that are also of type AlgebraicObject such as sin⁡π3 will be converted to algebraic numbers before proceeding, so they cannot be treated as variables. Proceed with caution when using a function for x, as treating some functions as variables may produce mathematically unsound results.
The inputs a and b can be polynomials disguised as rational functions, in which case they are normalized first using Algebraic[Normal].
The output will be normalized as follows:
All non-constant factors in the output are monic.
The gcd will always be monic, and `s` and `t` will each contain at most two constant factors, only one of which may not be rational.
All factors that are not rational numbers have integer content equal to 1, except possibly if there is only one non-constant factor.
All algebraic numbers occurring in the results are reduced modulo their minimal polynomial (see Reduce), and all arguments of functions, if any, are normalized recursively (see Normal).
If the set of radicals and RootOfs in the inputs cannot be embedded into a field algebraically, the greatest common divisor may not always exist or may not be unique. ExtendedEuclideanAlgorithm will try to find a field representation if there are at most 4 algebraic objects in the input (unless option 'makeindependent' is given; see below), and otherwise attempt to perform the computation anyway. If it does not succeed, it issues the error "reducible RootOf detected", unless the option 'symbolic'=true is given (see below).
These functions do not support input containing floats or radical functions such as x.
with⁡Algebraic:
Introductory examples:
ExtendedEuclideanAlgorithm⁡x3+I,x5−I,x,s1,t1
x−I
s1,t1
−I⁢x3−1,I⁢x
expand⁡x3+I⁢−x3⁢I−1+x5−I⁢x⁢I
r1≔RootOf⁡_Z2−_Z−1
ExtendedEuclideanAlgorithm⁡x2−1−r1,x3−2⁢r1−1,x,s2,t2,s2,t2
x−RootOf⁡_Z2−_Z−1,x⁢RootOf⁡_Z2−_Z−1−2⁢x,−RootOf⁡_Z2−_Z−1+2
The input may contain both radicals and RootOfs, and ExtendedEuclideanAlgorithm will embed the coefficients into an algebraic field, if possible:
ExtendedEuclideanAlgorithm⁡x2+sqrt⁡2⁢x+RootOf⁡_Z2−3,index=1⁢x+sqrt⁡6,x2+sqrt⁡2⁢x,x,s3,t3,s3,t3
x+2,33,−33
ExtendedEuclideanAlgorithm⁡x2+sqrt⁡2⁢x+RootOf⁡_Z2−3⁢x+sqrt⁡6,x2+sqrt⁡2⁢x,x,s3,t3,s3,t3
x+2,RootOf⁡_Z2−33,−RootOf⁡_Z2−33
Nested and mixed radicals and RootOfs are handled as well:
ExtendedEuclideanAlgorithm⁡x3−RootOf⁡_Z2−RootOf⁡_Z2−2,index=1,index=13,x2−sqrt⁡2,x,s4,t4,s4,t4
x−214,22,−2⁢x2
The input must contain univariate polynomials only. Multiple variables are not supported and an error will be returned:
ExtendedEuclideanAlgorithm⁡x2+x⁢y+y2+1,x+y,x
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) unable to compute gcdex of multivariate polynomials
This function does not perform the extended Euclidean algorithm over the integers. Use igcdex for that functionality:
ExtendedEuclideanAlgorithm⁡24,66,x,s5,t5,s5,t5
1,0,166
igcdex⁡24,66,s5,t5,s5,t5
6,3,−1
The input can also be treated as a pair of polynomials in a non-algebraic sub-expression such as sin⁡x, as it will be frozen and temporarily replaced by a new local variable:
ExtendedEuclideanAlgorithm⁡sin⁡x2+3⁢sin⁡x+2,sin⁡x2+4⁢sin⁡x+3,sin⁡x,s7,t7,s7,t7
sin⁡x+1,−1,1
Other non-algebraic sub-expressions can only be included if they can be converted to algebraic numbers:
ExtendedEuclideanAlgorithm⁡x−tan⁡π4,x+exp⁡I⁢π,x,s8,t8,s8,t8
x−1,0,1
ExtendedEuclideanAlgorithm⁡x2−sin⁡y2,x2+2⁢x⁢sin⁡y+sin⁡y2,x
Rational functions are generally not accepted, but polynomials disguised as rational functions are allowed, because they will be simplified by Normal:
ExtendedEuclideanAlgorithm⁡1x,1x2,x
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) polynom(s) in x expected
ExtendedEuclideanAlgorithm⁡x3−x2⁢I−x+Ix−1,x3+x2⁢I−x−Ix−1,x,s9,t9,s9,t9
x+1,I2,−I2
The output will always be fully reduced and normalized (see Reduce, Normal):
ExtendedEuclideanAlgorithm⁡x2−RootOf⁡_Z3−_Z−36,x2+6⁢x+2⁢RootOf⁡_Z3−_Z−3⁢x+RootOf⁡_Z3−_Z−36,x
x+RootOf⁡_Z3−_Z−3+3
Non-algebraic sub-expressions in the input may become algebraic after being recursively normalized:
ExtendedEuclideanAlgorithm⁡x+sin⁡π⁢y−sqrt⁡24⁢y−RootOf⁡_Z2−2,index=1,x+sqrt⁡22,x
x+22
Floats are not accepted:
ExtendedEuclideanAlgorithm⁡x2−x+0.25,x−12,x
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) polynom(s) with radalgnum coefficients expected
Algebraic functions such as x are not accepted:
ExtendedEuclideanAlgorithm⁡x2+2⁢x⁢sqrt⁡x,x+sqrt⁡x,x
When non-indexed RootOfs are given in the input, often the extended Euclidean Algorithm can still be performed and the answer expressed in terms of the input:
ExtendedEuclideanAlgorithm⁡x2−2,x3−RootOf⁡_Z2−8,x,s10,t10,s10,t10
x−RootOf⁡_Z2−82,−x2,12
However, in the following case, ExtendedEuclideanAlgorithm is unable to compute the gcd because it must know whether RootOf⁡_Z2−2 represents 2 or −2 when no index is given. In such a case, it will return a "reducible RootOf detected" error:
ExtendedEuclideanAlgorithm⁡x+sqrt⁡2,x+RootOf⁡_Z2−2,index=1,x,s11,t11,s11,t11
x+2,0,1
ExtendedEuclideanAlgorithm⁡x+sqrt⁡2,x+RootOf⁡_Z2−2,index=2,x,s12,t12,s12,t12
1,24,−24
ExtendedEuclideanAlgorithm⁡x+sqrt⁡2,x+RootOf⁡_Z2−2,x
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) reducible RootOf detected. Substitutions are {RootOf(_Z^2-2) = -RootOf(_Z^2-2,index = 1), RootOf(_Z^2-2) = RootOf(_Z^2-2,index = 1)}
By using option 'symbolic' = true, ExtendedEuclideanAlgorithm can be instructed to automatically select one of the possible substitutions and complete the computation. Here, it picks RootOf⁡_Z2−2=−2:
ExtendedEuclideanAlgorithm⁡x+sqrt⁡2,x+RootOf⁡_Z2−2,x,s13,t13,symbolic=true,s13,t13
Using option 'characteristic', the extended gcd computation can be performed over finite fields:
ExtendedEuclideanAlgorithm⁡x2+5,x2+6⁢x+2,x,s14,t14,characteristic=7,s14,t14
x+3,1,6
ExtendedEuclideanAlgorithm⁡x2+2⁢sqrt⁡5⁢x+5,x2+6,x,s15,t15,characteristic=11,s15,t15
x+5,10⁢5,5
In composite characteristic, the gcd cannot always be computed. ExtendedEuclideanAlgorithm will return an error if it encounters a zero divisor:
ExtendedEuclideanAlgorithm⁡x2+5⁢x+6,x2+3⁢x+2,x,s16,t16,characteristic=9,s16,t16
x+2,5,4
ExtendedEuclideanAlgorithm⁡x2+5⁢x+6,x2+3⁢x+2,x,characteristic=10
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) zero divisor modulo 10 detected
With option 'makeindependent'=true, the input will be checked for algebraic dependencies even if there are more than 4 algebraic objects in the input:
CubeRootOf−4≔RootOf⁡_Z3+4,index=1
CubeRootOf−2≔RootOf⁡_Z3+2,index=1
CubeRootOf2≔RootOf⁡_Z3−2,index=1
CubeRootOf3≔RootOf⁡_Z3−3,index=1
CubeRootOf4≔RootOf⁡_Z3−4,index=1
CubeRootOf6≔RootOf⁡_Z3−6,index=1
ExtendedEuclideanAlgorithm⁡x+CubeRootOf4⁢CubeRootOf−2⁢CubeRootOf3,x+CubeRootOf−4⁢CubeRootOf6,x
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) reducible RootOf detected. Substitutions are {RootOf(_Z^3+4,index = 1) = 1/2*RootOf(_Z^3-4,index = 1)^2*RootOf(_Z^3+2,index = 1), RootOf(_Z^3+4,index = 1) = RootOf(RootOf(_Z^3-4,index = 1)^2*RootOf(_Z^3+2,index = 1)*_Z-2*RootOf(_Z^3-4,index = 1)^2+2*_Z^2+4*RootOf(_Z^3+2,index = 1))}
ExtendedEuclideanAlgorithm⁡x+CubeRootOf4⁢CubeRootOf−2⁢CubeRootOf3,x+CubeRootOf−4⁢CubeRootOf6,x,makeindependent=true
RootOf⁡_Z3+2,index=1⁢RootOf⁡_Z3−6,index=1⁢RootOf⁡_Z3−4,index=122+x
With option 'makeindependent'=false, the input will never be checked for algebraic dependencies:
ExtendedEuclideanAlgorithm⁡x+CubeRootOf2⁢CubeRootOf3,x+CubeRootOf6,x,makeindependent=FAIL
x+RootOf⁡_Z3−6,index=1
ExtendedEuclideanAlgorithm⁡x+CubeRootOf2⁢CubeRootOf3,x+CubeRootOf6,x,makeindependent=false
Error, (in Algebraic:-ExtendedEuclideanAlgorithm) reducible RootOf detected. Substitutions are {RootOf(_Z^3-2,index = 1) = 1/3*RootOf(_Z^3-6,index = 1)*RootOf(_Z^3-3,index = 1)^2, RootOf(_Z^3-2,index = 1) = RootOf(RootOf(_Z^3-6,index = 1)*RootOf(_Z^3-3,index = 1)^2*_Z+RootOf(_Z^3-6,index = 1)^2*RootOf(_Z^3-3,index = 1)+3*_Z^2)}
See Also
Algebraic[GreatestCommonDivisor]
Algebraic[Normal]
evala,Gcdex
Download Help Document