exact arithmetic on a computerpersweb.wabash.edu/facstaff/turnerw/presentations/...symbolic...

49
Introduction Fundamentals Fast Multiplication Division Polynomial Equations Exact Arithmetic on a Computer Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer Science Wabash College Crawfordsville, IN 47933 Tuesday 21 September 2010 W. J. Turner Exact Arithmetic on a Computer 1/ 23

Upload: others

Post on 01-May-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Exact Arithmetic on a ComputerSymbolic Computation and Computer Algebra

William J. Turner

Department of Mathematics & Computer ScienceWabash College

Crawfordsville, IN 47933

Tuesday 21 September 2010

W. J. Turner Exact Arithmetic on a Computer 1/ 23

Page 2: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Outline

1 IntroductionSymbolic ComputationSymbolic Computation vs. Numerical AnalysisSymbolic Algorithms

2 Fundamental AlgorithmsStoring Integers and PolynomialsClassical Arithmetic Algorithms

3 Fast Multiplication

4 Division

5 Solving Polynomial Equations

W. J. Turner Exact Arithmetic on a Computer 2/ 23

Page 3: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Symbolic Computation

Superset of computer algebra

Symbols or exact arithmetic

Exact finite representation of mathematical structures

Abstract structures (groups, rings, fields, etc.)

Polynomials and power series

Linear algebra

Number theory

Algebraic geometry

Computational group theory

Differential equations

Automated theorem proving

W. J. Turner Exact Arithmetic on a Computer 3/ 23

Page 4: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Computer Algebra Systems

General Purpose Systems

AXIOM, Magma, Maple, Mathematica, REDUCE, SAGE

Special Purpose Systems

CoCoA (Computations in Commutative Algebra)

GAP (Groups, Algorithms, and Programming)

NTL (Number Theory Library)

Singular (polynomial computations)

Theorema (automated theorem proving)

W. J. Turner Exact Arithmetic on a Computer 4/ 23

Page 5: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Computer Algebra Systems

General Purpose Systems

AXIOM, Magma, Maple, Mathematica, REDUCE, SAGE

Special Purpose Systems

CoCoA (Computations in Commutative Algebra)

GAP (Groups, Algorithms, and Programming)

NTL (Number Theory Library)

Singular (polynomial computations)

Theorema (automated theorem proving)

W. J. Turner Exact Arithmetic on a Computer 4/ 23

Page 6: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Long History

Ancient Algorithms

Euclidean Algorithm

Chinese Remainder Algorithm

Isaac Newton’s The Universal Arithmetic (1728)

Systematically discusses rules for manipulating universalmathematical expressions, that is, formulae containing symbolicindeterminates, and algorithms for solving equations built withthese expressions.

W. J. Turner Exact Arithmetic on a Computer 5/ 23

Page 7: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Long History

Ancient Algorithms

Euclidean Algorithm

Chinese Remainder Algorithm

Isaac Newton’s The Universal Arithmetic (1728)

Systematically discusses rules for manipulating universalmathematical expressions, that is, formulae containing symbolicindeterminates, and algorithms for solving equations built withthese expressions.

W. J. Turner Exact Arithmetic on a Computer 5/ 23

Page 8: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Symbolic Computation vs. Numerical Analysis

Numerical Analysis

Floating point numbers (approximate real values)

Find approximation quickly

Error propagation important

Condition NumberStability

Symbolic Computation

Find exact solution quickly

May never approximate

Structure may not have a metric

Algorithms may not be compatible

Numerical algorithms may never find exact solution

Symbolic algorithms may be ill-conditioned or unstable

W. J. Turner Exact Arithmetic on a Computer 6/ 23

Page 9: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Symbolic Computation vs. Numerical Analysis

Numerical Analysis

Floating point numbers (approximate real values)

Find approximation quickly

Error propagation important

Condition NumberStability

Symbolic Computation

Find exact solution quickly

May never approximate

Structure may not have a metric

Algorithms may not be compatible

Numerical algorithms may never find exact solution

Symbolic algorithms may be ill-conditioned or unstable

W. J. Turner Exact Arithmetic on a Computer 6/ 23

Page 10: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Symbolic Computation vs. Numerical Analysis

Numerical Analysis

Floating point numbers (approximate real values)

Find approximation quickly

Error propagation important

Condition NumberStability

Symbolic Computation

Find exact solution quickly

May never approximate

Structure may not have a metric

Algorithms may not be compatible

Numerical algorithms may never find exact solution

Symbolic algorithms may be ill-conditioned or unstable

W. J. Turner Exact Arithmetic on a Computer 6/ 23

Page 11: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Infinite Mathematical Structure

General Approach

Computer has finite memory

Cannot compute exactly over reals, rationals, integers, etc.

Compute bound M on desired solution

Solve via modular algorithms & reconstruct solution

Chinese Remainder AlgorithmHensel LiftingRational Number Reconstruction

Selecting the Modulus

Big Prime Method: m = p

Small Prime Method: m =∏

i pi

Small Prime Power Method: m = p`

W. J. Turner Exact Arithmetic on a Computer 7/ 23

Page 12: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Infinite Mathematical Structure

General Approach

Computer has finite memory

Cannot compute exactly over reals, rationals, integers, etc.

Compute bound M on desired solution

Solve via modular algorithms & reconstruct solution

Chinese Remainder AlgorithmHensel LiftingRational Number Reconstruction

Selecting the Modulus

Big Prime Method: m = p

Small Prime Method: m =∏

i pi

Small Prime Power Method: m = p`

W. J. Turner Exact Arithmetic on a Computer 7/ 23

Page 13: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Storing Integers and Polynomials

Polynomials

Polynomials R[x ] over ring R (e.g., Zm)

a = anxn + an−1x

n−1 + · · ·+ a1x + a0 ∈ R[x ]

store degree n and coefficients ai for i = 0, 1, 2, . . . , n

Integers

Radix r ∈ N>1

a = anrn + an−1r

n−1 + · · ·+ a1r + a0 ∈ Z0 ≤ ai < r for i = 0, 1, 2, . . . , n.

store size n and digits ai for i = 0, 1, 2, . . . , n

W. J. Turner Exact Arithmetic on a Computer 8/ 23

Page 14: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Storing Integers and Polynomials

Polynomials

Polynomials R[x ] over ring R (e.g., Zm)

a = anxn + an−1x

n−1 + · · ·+ a1x + a0 ∈ R[x ]

store degree n and coefficients ai for i = 0, 1, 2, . . . , n

Integers

Radix r ∈ N>1

a = anrn + an−1r

n−1 + · · ·+ a1r + a0 ∈ Z0 ≤ ai < r for i = 0, 1, 2, . . . , n.

store size n and digits ai for i = 0, 1, 2, . . . , n

W. J. Turner Exact Arithmetic on a Computer 8/ 23

Page 15: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Addition Algorithm

Polynomials

a =n∑

i=0

aixi and b =

m∑i=0

bixi ∈ R[x ]

Assume n = m : c =n∑

i=0

ci = a + b =n∑

i=0

(ai + bi )xi

Algorithm

for i = 0, 1, 2, . . . n doci ← ai + bi

end for

Complexity

O(n) ring operations

W. J. Turner Exact Arithmetic on a Computer 9/ 23

Page 16: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Addition Algorithm

Polynomials

a =n∑

i=0

aixi and b =

m∑i=0

bixi ∈ R[x ]

Assume n = m : c =n∑

i=0

ci = a + b =n∑

i=0

(ai + bi )xi

Algorithm

for i = 0, 1, 2, . . . n doci ← ai + bi

end for

Complexity

O(n) ring operations

W. J. Turner Exact Arithmetic on a Computer 9/ 23

Page 17: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Addition Algorithm

Polynomials

a =n∑

i=0

aixi and b =

m∑i=0

bixi ∈ R[x ]

Assume n = m : c =n∑

i=0

ci = a + b =n∑

i=0

(ai + bi )xi

Algorithm

for i = 0, 1, 2, . . . n doci ← ai + bi

end for

Complexity

O(n) ring operations

W. J. Turner Exact Arithmetic on a Computer 9/ 23

Page 18: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Addition Algorithm

Integer Algorithm

c0 ← 0for i = 0, 1, 2, . . . n do

ci ← ai + bi + ciif ci ≥ r thenci ← ci − rci+1 ← 1

elseci+1 ← 0

end ifend for

Complexity

O(n) word operations

W. J. Turner Exact Arithmetic on a Computer 10/ 23

Page 19: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Addition Algorithm

Integer Algorithm

c0 ← 0for i = 0, 1, 2, . . . n do

ci ← ai + bi + ciif ci ≥ r thenci ← ci − rci+1 ← 1

elseci+1 ← 0

end ifend for

Complexity

O(n) word operations

W. J. Turner Exact Arithmetic on a Computer 10/ 23

Page 20: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Multiplication Algorithm

Polynomial Algorithm

Require: a =∑n

i=0 aixi and b =

∑mi=0 bix

i

for k = 0, 1, 2, . . . n + m dock ← 0for i = max{0, k −m}, . . . ,min{n, k} dock ← ck + aibk−i

end forend for

Complexity

O(mn) ring operations

n = m =⇒ O(n2) ring operations

W. J. Turner Exact Arithmetic on a Computer 11/ 23

Page 21: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Multiplication Algorithm

Polynomial Algorithm

Require: a =∑n

i=0 aixi and b =

∑mi=0 bix

i

for k = 0, 1, 2, . . . n + m dock ← 0for i = max{0, k −m}, . . . ,min{n, k} dock ← ck + aibk−i

end forend for

Complexity

O(mn) ring operations

n = m =⇒ O(n2) ring operations

W. J. Turner Exact Arithmetic on a Computer 11/ 23

Page 22: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Multiplication Algorithm

Another Organization

Require: a =∑n

i=0 aixi and b =

∑mi=0 bix

i

for i = 0, 1, 2, . . . n dodi ← aix

i b { x i just shifts ai by i places }end forreturn c ←

∑ni=0 di

Integer Algorithm

Require: a = (−1)s∑n

i=0 ai ri and b = (−1)t

∑mi=0 bi r

i

for i = 0, 1, 2, . . . n dodi ← ai r

i |b| { r i just shifts ai by i places }end forreturn c ← (−1)s+t

∑ni=0 di

W. J. Turner Exact Arithmetic on a Computer 12/ 23

Page 23: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Multiplication Algorithm

Another Organization

Require: a =∑n

i=0 aixi and b =

∑mi=0 bix

i

for i = 0, 1, 2, . . . n dodi ← aix

i b { x i just shifts ai by i places }end forreturn c ←

∑ni=0 di

Integer Algorithm

Require: a = (−1)s∑n

i=0 ai ri and b = (−1)t

∑mi=0 bi r

i

for i = 0, 1, 2, . . . n dodi ← ai r

i |b| { r i just shifts ai by i places }end forreturn c ← (−1)s+t

∑ni=0 di

W. J. Turner Exact Arithmetic on a Computer 12/ 23

Page 24: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Classical Division with Remainder Algorithm

Polynomial Synthetic Division Algorithm

Require: a =∑n

i=0 aixi and b =

∑mi=0 bix

i where bm is a unitand n ≥ m ≥ 0

Ensure: a = qb + r and deg r < mr ← a and u ← b−1m

for i = n −m, n −m − 1, . . . 0 doif deg r = m + i thenqi ← lc(r)u {Leading coefficient of r}r ← r − qix

ibelseqi ← 0

end ifend forreturn q ←

∑n−mi=0 qix

i and r

W. J. Turner Exact Arithmetic on a Computer 13/ 23

Page 25: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

Roots of Unity

Let R be a ring, n ∈ N>1, and ω ∈ R.

ω is an nth root of unity if ωn = 1.

ω is a primitive nth root of unity if 1 ≤ k < n =⇒ ωk 6= 1.

Discrete Fourrier Transform

DFTω : Rn → Rn, f 7→(f (1), f (ω), f (ω2), . . . , f (ωn−1)

)deg(f ) < nω is primitive nth root of unity

Fast Fourrier Transform (FFT)

Can compute DFT recursively for n = 2k

O(n log n) ring operations

W. J. Turner Exact Arithmetic on a Computer 14/ 23

Page 26: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

Roots of Unity

Let R be a ring, n ∈ N>1, and ω ∈ R.

ω is an nth root of unity if ωn = 1.

ω is a primitive nth root of unity if 1 ≤ k < n =⇒ ωk 6= 1.

Discrete Fourrier Transform

DFTω : Rn → Rn, f 7→(f (1), f (ω), f (ω2), . . . , f (ωn−1)

)deg(f ) < nω is primitive nth root of unity

Fast Fourrier Transform (FFT)

Can compute DFT recursively for n = 2k

O(n log n) ring operations

W. J. Turner Exact Arithmetic on a Computer 14/ 23

Page 27: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

Roots of Unity

Let R be a ring, n ∈ N>1, and ω ∈ R.

ω is an nth root of unity if ωn = 1.

ω is a primitive nth root of unity if 1 ≤ k < n =⇒ ωk 6= 1.

Discrete Fourrier Transform

DFTω : Rn → Rn, f 7→(f (1), f (ω), f (ω2), . . . , f (ωn−1)

)deg(f ) < nω is primitive nth root of unity

Fast Fourrier Transform (FFT)

Can compute DFT recursively for n = 2k

O(n log n) ring operations

W. J. Turner Exact Arithmetic on a Computer 14/ 23

Page 28: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

DFT and Multiplication

If deg(f ) + deg(g) < n, then DFTω(f g) = DFTω(f ) · DFTω(g).

Fast Multiplication Algorithm

Require: deg(f ), deg(g) < nk ← dlog2(2n)eω ← primitive 2kth root of unity in Rα← DFTω(f ) and β ← DFTω(g) {via FFT}γ ← α · β {pointwise multiplication}return DFT−1ω (γ) = 1

n DFTω−1(γ)

Complexity

O(n log n) ring operations

O(n log n loglog n) ring operations if must extend ring

W. J. Turner Exact Arithmetic on a Computer 15/ 23

Page 29: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

DFT and Multiplication

If deg(f ) + deg(g) < n, then DFTω(f g) = DFTω(f ) · DFTω(g).

Fast Multiplication Algorithm

Require: deg(f ), deg(g) < nk ← dlog2(2n)eω ← primitive 2kth root of unity in Rα← DFTω(f ) and β ← DFTω(g) {via FFT}γ ← α · β {pointwise multiplication}return DFT−1ω (γ) = 1

n DFTω−1(γ)

Complexity

O(n log n) ring operations

O(n log n loglog n) ring operations if must extend ring

W. J. Turner Exact Arithmetic on a Computer 15/ 23

Page 30: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Multiplication

DFT and Multiplication

If deg(f ) + deg(g) < n, then DFTω(f g) = DFTω(f ) · DFTω(g).

Fast Multiplication Algorithm

Require: deg(f ), deg(g) < nk ← dlog2(2n)eω ← primitive 2kth root of unity in Rα← DFTω(f ) and β ← DFTω(g) {via FFT}γ ← α · β {pointwise multiplication}return DFT−1ω (γ) = 1

n DFTω−1(γ)

Complexity

O(n log n) ring operations

O(n log n loglog n) ring operations if must extend ring

W. J. Turner Exact Arithmetic on a Computer 15/ 23

Page 31: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Division

Polynomial Reversal

The reversal of a polynomial a =∑n

i=0 aixi is

revk(a) = xka

(1

x

)When k = n, rev(a) = revn(a) reverses the coefficients of a.

Reversals and Division

If deg(a) = n, deg(b) = m, and b(0) = 1, then deg(r) < m sorevm−1(r) is a polynomial and

revn(a) = revm(b) revn−m(q) + xn−m+1 revm−1(r)≡ revm(b) revn−m(q) (mod xn−m+1)

revn−m(q) = revn(a) revm(b)−1 mod xn−m+1

W. J. Turner Exact Arithmetic on a Computer 16/ 23

Page 32: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Division

Polynomial Reversal

The reversal of a polynomial a =∑n

i=0 aixi is

revk(a) = xka

(1

x

)When k = n, rev(a) = revn(a) reverses the coefficients of a.

Reversals and Division

If deg(a) = n, deg(b) = m, and b(0) = 1, then deg(r) < m sorevm−1(r) is a polynomial and

revn(a) = revm(b) revn−m(q) + xn−m+1 revm−1(r)≡ revm(b) revn−m(q) (mod xn−m+1)

revn−m(q) = revn(a) revm(b)−1 mod xn−m+1

W. J. Turner Exact Arithmetic on a Computer 16/ 23

Page 33: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Division

Polynomial Reversal

The reversal of a polynomial a =∑n

i=0 aixi is

revk(a) = xka

(1

x

)When k = n, rev(a) = revn(a) reverses the coefficients of a.

Reversals and Division

If deg(a) = n, deg(b) = m, and b(0) = 1, then deg(r) < m sorevm−1(r) is a polynomial and

revn(a) = revm(b) revn−m(q) + xn−m+1 revm−1(r)≡ revm(b) revn−m(q) (mod xn−m+1)

revn−m(q) = revn(a) revm(b)−1 mod xn−m+1

W. J. Turner Exact Arithmetic on a Computer 16/ 23

Page 34: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Newton Iteration

Newton’s Iteration from Calculus

Require: φ(y), initial estimate y0, and tolerance τEnsure: |φ(y)| < τk ← 0while |φ(yk)| ≥ τ do

yk+1 ← yk −φ(yk)

φ′(yk)= yk − φ(yk)

(φ′(yk)

)−1end whilereturn y ← yk

W. J. Turner Exact Arithmetic on a Computer 17/ 23

Page 35: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Algebra—Not Analysis

Formal Derivative

Let R be a ring (commutative, with 1). For φ =∑n

i=0 φiyi ∈ D[y ],

where D is a ring, we define the formal derivative of φ by

φ′ =n∑

i=0

iφiyi−1

Approximations

Given a modulus m, measure how well b approximates a by thehighest power of m such that a ≡ b (mod m).

Example

Let m = 2. Then 9 is a better approximation for 17 than 15because 9 ≡ 17 (mod 23) but 15 6≡ 17 (mod 23).

W. J. Turner Exact Arithmetic on a Computer 18/ 23

Page 36: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Algebra—Not Analysis

Formal Derivative

Let R be a ring (commutative, with 1). For φ =∑n

i=0 φiyi ∈ D[y ],

where D is a ring, we define the formal derivative of φ by

φ′ =n∑

i=0

iφiyi−1

Approximations

Given a modulus m, measure how well b approximates a by thehighest power of m such that a ≡ b (mod m).

Example

Let m = 2. Then 9 is a better approximation for 17 than 15because 9 ≡ 17 (mod 23) but 15 6≡ 17 (mod 23).

W. J. Turner Exact Arithmetic on a Computer 18/ 23

Page 37: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Algebra—Not Analysis

Formal Derivative

Let R be a ring (commutative, with 1). For φ =∑n

i=0 φiyi ∈ D[y ],

where D is a ring, we define the formal derivative of φ by

φ′ =n∑

i=0

iφiyi−1

Approximations

Given a modulus m, measure how well b approximates a by thehighest power of m such that a ≡ b (mod m).

Example

Let m = 2. Then 9 is a better approximation for 17 than 15because 9 ≡ 17 (mod 23) but 15 6≡ 17 (mod 23).

W. J. Turner Exact Arithmetic on a Computer 18/ 23

Page 38: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Choosing the Function

Given f ∈ R[x ] = D, want φ ∈ D[y ] such that φ(f −1) = 0.

Must be invertible

Update φ (φ′)−1 without division

The Function

φ(y) =1

y− f

φ′(y) = − 1

y2

φ(y)(φ′(y)

)−1= −y + fy2

y − φ(y)(φ′(y)

)−1= 2y − fy2

W. J. Turner Exact Arithmetic on a Computer 19/ 23

Page 39: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Choosing the Function

Given f ∈ R[x ] = D, want φ ∈ D[y ] such that φ(f −1) = 0.

Must be invertible

Update φ (φ′)−1 without division

The Function

φ(y) =1

y− f

φ′(y) = − 1

y2

φ(y)(φ′(y)

)−1= −y + fy2

y − φ(y)(φ′(y)

)−1= 2y − fy2

W. J. Turner Exact Arithmetic on a Computer 19/ 23

Page 40: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Choosing the Function

Given f ∈ R[x ] = D, want φ ∈ D[y ] such that φ(f −1) = 0.

Must be invertible

Update φ (φ′)−1 without division

The Function

φ(y) =1

y− f

φ′(y) = − 1

y2

φ(y)(φ′(y)

)−1= −y + fy2

y − φ(y)(φ′(y)

)−1= 2y − fy2

W. J. Turner Exact Arithmetic on a Computer 19/ 23

Page 41: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Choosing the Function

Given f ∈ R[x ] = D, want φ ∈ D[y ] such that φ(f −1) = 0.

Must be invertible

Update φ (φ′)−1 without division

The Function

φ(y) =1

y− f

φ′(y) = − 1

y2

φ(y)(φ′(y)

)−1= −y + fy2

y − φ(y)(φ′(y)

)−1= 2y − fy2

W. J. Turner Exact Arithmetic on a Computer 19/ 23

Page 42: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Choosing the Function

Given f ∈ R[x ] = D, want φ ∈ D[y ] such that φ(f −1) = 0.

Must be invertible

Update φ (φ′)−1 without division

The Function

φ(y) =1

y− f

φ′(y) = − 1

y2

φ(y)(φ′(y)

)−1= −y + fy2

y − φ(y)(φ′(y)

)−1= 2y − fy2

W. J. Turner Exact Arithmetic on a Computer 19/ 23

Page 43: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Inversion Algorithm

Require: f ∈ R[x ] with f (0) = 1 and ` ∈ NEnsure: g ∈ R[x ] with fg ≡ 1 (mod x`)g0 ← 1r ← dlog2 `efor i = 1, . . . , r do

gi ←(2gi−1 − f g2

i−1)

rem x2i { truncates polynomial }

end forreturn gr

Complexity

3M(`) + ` = O(M(`)) ring operations

M(`) is multiplication time

W. J. Turner Exact Arithmetic on a Computer 20/ 23

Page 44: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Inversion Using Newton Iteration

Inversion Algorithm

Require: f ∈ R[x ] with f (0) = 1 and ` ∈ NEnsure: g ∈ R[x ] with fg ≡ 1 (mod x`)g0 ← 1r ← dlog2 `efor i = 1, . . . , r do

gi ←(2gi−1 − f g2

i−1)

rem x2i { truncates polynomial }

end forreturn gr

Complexity

3M(`) + ` = O(M(`)) ring operations

M(`) is multiplication time

W. J. Turner Exact Arithmetic on a Computer 20/ 23

Page 45: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Division with Remainder

Fast Division Algorithm

Require: a, b ∈ R[x ] where b 6= 0 is monic.Ensure: q, r ∈ R[x ] such that a = qb + r and deg r < deg b

if deg a < deg b thenreturn q ← 0 and r ← a

end ifm← deg a− deg bc ← (revdeg b(b))−1 mod xm+1 { Newton Iteration }q∗ ← revdeg a(a) c rem xm+1 { truncates polynomial }return q ← revm(q∗) and r ← a− b q

Complexity

3M(m) + M(n) + O(n) ring operations

deg b = n and deg a = m + n

W. J. Turner Exact Arithmetic on a Computer 21/ 23

Page 46: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Fast Division with Remainder

Fast Division Algorithm

Require: a, b ∈ R[x ] where b 6= 0 is monic.Ensure: q, r ∈ R[x ] such that a = qb + r and deg r < deg b

if deg a < deg b thenreturn q ← 0 and r ← a

end ifm← deg a− deg bc ← (revdeg b(b))−1 mod xm+1 { Newton Iteration }q∗ ← revdeg a(a) c rem xm+1 { truncates polynomial }return q ← revm(q∗) and r ← a− b q

Complexity

3M(m) + M(n) + O(n) ring operations

deg b = n and deg a = m + n

W. J. Turner Exact Arithmetic on a Computer 21/ 23

Page 47: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Generalized Newton Iteration

Newton Iteration

Require: φ ∈ D[y ], p ∈ R, ` ∈ N>0, g0 ∈ R with φ(g0) ≡ 0(mod p) and φ′(g0) invertible modulo p, and s0 such thats0φ′(g0) ≡ 1 (mod p)

Ensure: g ∈ R with φ(g) ≡ 0 (mod pl) and g ≡ g0 (mod p)r ← dlog2 `efor i = 1, . . . , r − 1 do

gi ← (gi−1 − φ(gi−1) si−1) mod p2i

si ←(2si−1 − φ′(gi ) s2i−1

)mod p2

i

end forreturn g ← gr−1 − φ(gr−1) sr−1 mod pl

W. J. Turner Exact Arithmetic on a Computer 22/ 23

Page 48: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Complexity

Polynomial Ring

(3n + 3/2)M(`) + O(n`) when

D = R[x ]

p = x

` = 2k

degy φ = n and degx φ < `

Integers

O(nM(` log p)) word operations when

R = Z0 < g0 < p

deg φ = n

|φi | < pl for i = 0, 1, . . . , n

W. J. Turner Exact Arithmetic on a Computer 23/ 23

Page 49: Exact Arithmetic on a Computerpersweb.wabash.edu/facstaff/turnerw/presentations/...Symbolic Computation and Computer Algebra William J. Turner Department of Mathematics & Computer

Introduction Fundamentals Fast Multiplication Division Polynomial Equations

Complexity

Polynomial Ring

(3n + 3/2)M(`) + O(n`) when

D = R[x ]

p = x

` = 2k

degy φ = n and degx φ < `

Integers

O(nM(` log p)) word operations when

R = Z0 < g0 < p

deg φ = n

|φi | < pl for i = 0, 1, . . . , n

W. J. Turner Exact Arithmetic on a Computer 23/ 23