Basic Algorithms In Computer Algebra Kaiserslautern SS 2011 Prof. Dr. Wolfram Decker 2. Mai 2011
References Cohen, H.: A Course in Computational Algebraic Number Theory. Springer, 1993. Cox, D.; Little, J.; O Shea, D.: Ideals, Varieties, and Algorithms. Springer, 2007. Forster, O.: Algorithmische Zahlentheorie, Vieweg, 1996. Gerhard, J.; von zur Gathen, J.: Modern Computer Algebra. Cambridge Press, 2003. Greuel, F.-M.; Pfister, G.: A Singular introduction to Commutative Algebra. 2nd ed., Springer, 2007. Kaplan, M.: Computer Algebra. Springer, 2008. Knuth, D.E.: The Art of Computer Programming. Volumes 1,2,3. Addison-Wesley, 1998. Lidl, H.; Niederreiter, H.: Introduction to Finite Fields. Cambridge University Press, 1986. PYTHON documentation, 2011. http://www.python.org/ SINGULAR 3-1-3 Online Manual, 2011. http://www.singular.uni-kl.de/ 3
0 Introduction Computer algebra is a discipline between mathematics and computer science which deals with designing, analyzing, implementing, and applying algebraic algorithms. We comment on this in more detail in what follows. 0.1 Application Areas Computer algebra is interdisciplinary in nature, with links to quite a number of areas in mathematics, with applications in mathematics, other branches of science, and engineering: Through computer algebra methods, a number of mathematical disciplines become accessible to experiments. This is in particular true for various parts of algebra, number theory, and geometry. See http://www.claymath.org/millennium/birch and Swinnerton-Dyer Conjecture/ for a famous conjecture in number theory which is based on computer experiments. Algebraic algorithms open up new ways of computing in classical application areas of mathematics in science (physics, chemistry, biology). A pioneering and prominent example is work by Veltman and t Hooft who won a Nobel price in physics in 1999 (awarded for having placed particle physics theory on a firmer mathematical foundation ). Modern application areas of mathematics such as cryptography, coding theory, CAD, robotics, algebraic statistics, and algebraic biology heavily rely on computer algebra. 0.2 Implementations There is a large variety of computer algebra systems suiting different needs. See http://orms.mfo.de/ and the slides from the first lecture of this course at http://www.mathematik.uni-kl.de/ decker/lehre/ss11/pramasymbol/index.html. The practical sessions accompanying the course feature the modern programming language Python (see http://www.python.org/) and the computer algebra system Singular (see http://www.singular.uni-kl.de/). 5
0 INTRODUCTION 0.3 Analyzing Algorithms One way of measuring the efficiency of an algorithm is to give assymptotic bounds on its running time which depend on the size of the input. For this, we will use the big-oh notation. 0.4 Designing Algorithms When designing algorithms, we will describe them in a somewhat informal way which makes use of the structural conventions of a programming language. We refer to such a description as pseudocode. Here is a classical example which should be familiar from the beginner s course Algebraische Strukturen: Algorithm 1 Euclid s Algorithm Input: m, n R, n 0, where R is an Euclidean domain Output: gcd(m, n) a := m, b := n while (b 0) do r := rem(a, b) // division with remainder a := b, b := r a := n(a) // normal form return (a) Some comments on this are in order. In any Euclidean domain R, with Euclidean function v, if a, b R with b 0, and if we write a = q b + r, with r = 0 or v(r) < v(b), quo(a, b) = q and rem(a, b) = r for the quotient q and the remainder r, respectively. Note, however, that q and r need not be unique. If R = Z, with v given by the absolute value, uniqueness is achieved by the additional requirement that r 0. In the case where R = K[x] is the polynomial ring over a field K, with v given by the degree, q and r are unique without further requirement. Remark 0.5. If R is any integral domain, and if a greatest common divisor c of two elements a, b R exists, all such divisors are obtained by multyplying c with a unit of R. That is, the greatest common divisors form an equivalence class under being associated (see the first sheet of exercises). In this lecture, we always assume that in each such equivalence class a normal form is selected. If the class is represented by a R, we write n(a) for the normal form. Here, we set n(0) = 0 and n(1) = 1 (the normal form of the units in R), and require that n(a b) = n(a) n(b). If a 0, then a = u(a) n(a) for a uniquely determined unit u(a) R. By convention, u(0) = 0. Given two elements a, b R for which greatest common divisors exist, gcd(a, b) will denote the greatest common divisor in normal form. Similarly, for the least common multiple lcm(a, b). In 6
0.4 DESIGNING ALGORITHMS a unique factorization domain (UFD), greatest common divisors and lowest common multiples always exist, as we know from the course Algebraische Strukturen. Basic examples of UFDs are principal ideal domains such as Z and K[x]. Recall that every Euclideam domain is a principal ideal domain. Example 0.6. forms. (i) In Z, only ±1 are units. We choose the integers 0 as normal (ii) In a field K, all nonzero elements are units. Their normal form is, thus, 1. (iii) Given any ring R in which normal forms are distinguished, the normal forms in the polynomial ring R[x] are the polynomials whose leading coefficients are normal forms in R. If R = K is a field, we get the monic polynomials. Now, we give an example of Euclid s algorithm at work: Example 0.7. In Z, we have gcd(18, 30) = 6: r a b 18 30 18 30 18 12 18 12 6 12 6 0 6 0 The computation of greatest common divisors in Z[x] can, in principle, be reduced to that in Q[x] using Gauss lemma (we will see this later). A problem with this approach is intermediate coefficient swell, see the slide from the second lecture of the course at http://www.mathematik.uni-kl.de/ decker/lehre/ss11/pramasymbol/index.html. Modular algorithms provide a solution to this problem. Their basic idea is to reduce the given polynomials modulo one (or several) prime numbers, compute their greatest common divisors in the corresponding prime fields Z/pZ, and lift the results to Z[x] (for example, by Chinese remaindering). To demonstrate the general use of modular computations, we give two examples from elementary number theory: Example 0.8. We show that the equation x 2 + y 2 = 4z + 3 has no integer solutions. The idea is to reduce the equation modulo 4: x 2 + y 2 = 3. In Z/4Z = {0, 1, 2, 3}, only 0, 1 are squares: a 0 1 2 3 a 2 0 1 0 1 Hence, the possible values for x 2 + y 2 in Z/4Z are 0, 1, 2, but not 3. 7
0 INTRODUCTION Example 0.9. In 1732, Euler proved that the 5th Fermat number F 5 = 2 25 + 1 is not prime. In fact, Euler showed that 641 is a factor of F 5. His idea was to show that F 5 modulo 641 is zero. For this, we first write 641 = 640 + 1 = 5 2 7 + 1 641 = 625 + 16 = 5 4 + 2 4 Then and This implies and, thus, 5 2 7 = 640 1 mod 641, hence 5 4 2 28 1 mod 641, 5 4 2 4 mod 641. 1 5 4 2 28 2 4 2 28 = 2 32 mod 641 F 5 = 2 32 + 1 0 mod 641. 0.10 What are Algebraic Algorithms? Algebraic algorithms deal with algebraic objects, make us of algebraic methods, and are based on algebraic theorems. Objects are represented exactly and calculations are carried through exactly (no approximation is applied at any step). 0.11 What is an Algorithm? An algorithm is a set of instructions for solving a particular problem in finitely many, well defined steps. Starting from a given input, the instructions describe a computation which eventually will produce an output and terminate. The transition from one step to the next one is not necessarily deterministic: probabilistic algorithms incorporate random input, which may lead to random performance and random output. 0.12 A First Motivating Example: The RSA Cryptosystem Cryptology is the science of secure communication. Its basic scenario is: 8
0.12 A FIRST MOTIVATING EXAMPLE: THE RSA CRYPTOSYSTEM Eve eavesdropper m e s s a g e Bob sender Alice receiver Its basic idea is to encrypt the message: sender PSfrag replacements key K algorithm encryption ε transmitted ciphertext plaintext receiver key L PSfrag replacements transmitted cipher text algorithm decryption δ decrypted text In a symmetric cryptosystem, K = L. Example 0.13 (Caesar Shift). Replace each letter of the plain text by a fixed number of positions down the alphabet. For instance: To decrypt, reverse the shift. A B C X Y Z shift 3 D E F A B C 9
0 INTRODUCTION Example 0.14. The German Enigma is an electro-mechanical rotor machine which was used for the encryption and decryption of secret messages during World War II. See http://www.youtube.com/watch?v=dnbsnde1ika for a demonstration. A major problem coming with symmetric cryptosystems is the initial exchange of one or more keys. Modern public key cryptosystems are asymmetric and avoid, thus, this problem: Alice creates both a public key and an associated private key, and publishes the public key. Bob uses the public key to encrypt his plain text, and Alice her private key to decrypt the transmitted cypher text. Example 0.15 (RSA Cryptosystem). Two basic facts and one conjecture prepare the way: Fact 1: It is easy to find a random prime number of a given size. We can use modern probabilistic algorithms. Fact 2: Multiplying large numbers is easy. There are many efficient ways for multiplication. Conjecture 3: Given a large integer, it is hard to find its prime factors. Algorithms for factorizing are still expensive. Based on all this, Alice proceeds as follows: 1. Generate two large, roughly equal random primes p q (1024 bits each). 2. Compute the modulus N = p q. 3. Select a (small) public exponent e satisfying gcd(e, (p 1)(q 1)) = 1. 4. Use the extended Euclidean algorithm to compute a private exponent d satisfying de 1 mod (p 1)(q 1). 5. Publish (N, e) as the public key and hide (N, d) as the private key. Before exchanging messages, Bob and Alice agree on a way of encoding pieces of text as integers between 0 and N 1 (long messages are broken into pieces). Using, say A 0, B 1,, Z 25 and the 26 -ary number system, CAESAR is encoded as 2 26 0 + 0 26 1 + 4 26 2 + 18 26 3 + 0 26 4 + 17 26 5 = 202 302 466. Then Bob encrypts a piece of text x as ε(x) := y := x e (using repeated squaring). Alice decrypts y as δ(y) := y d mod N mod N (also using repeated squaring). This makes sense since (as we will see in the exercises). δ(y) = x 10
0.17 A SECOND MOTIVATING EXAMPLE: ROBOTICS Remark 0.16. Among others, the RSA system can be used to solve the initial key exchange problem for a modern, computer based symmetric cryptosystem such as AES. See http://de.wikipedia.org/wiki/pretty Good Privacy and http://de.wikipedia.org/wiki/advanced Encryption Standard. 0.17 A Second Motivating Example: Robotics The inverse kinematic problem is to find all joint angles that place the hand of a robot in a desired position. Example 0.18 (A Planar Robot). Consider the following robot arm which only moves in the plane: θ 2 length l 2 length l 3 θ 3 PSfrag replacements θ 1 length l 1 If (a, b) is the point to be reached by the robot s hand, the corresponding angles satisfy the polynomial system of equations below (to simplify the system, we ignore the orientation of the hand, that is, the angle θ 3 ): where a = l 3 (c 1 c 2 s 1 s 2 ) + l 2 c 1, b = l 3 (c 1 s 2 + c 2 s 1 + l 2 s 1, 0 = c 2 1 + s2 1 1, 0 = c 2 2 + s2 2 1, c i = cos θ 1, s i = sin θ 1. Computing a Gröbner Basis as in the Singular example on the slides from the first lecture, we get an equivalent system which can be easily solved for the c i and s i (to simplify the presentation of the result, we suppose that l 2 = l 3 = 1). 11
0 INTRODUCTION See Cox, Little, and O Shea for details. c 2 a2 +b 2 2 2, s 2 + a2 +b 2 a s 1 a2 b+b 3 2a, c 1 + b a s 1 a2 +b 2 2a, s 2 1 + a2 b+b 3 (a 2 +b 2 ) s 1 + (a2 +b 2 ) 2 4a 2 4(a 2 +b 2 ). We refer to the homepage of Charles Wampler (see http://www.nd.edu/ cwample1/) for movies featuring Robonaut2 and for the slides from a lecture on Kinematics and Numerical Algebraic Geometry which in particular include a discussion of possible robot joints. 12