Presentation is loading. Please wait.

Presentation is loading. Please wait.

Richard Fateman CS 282 Lecture 2b1 Basic Domains of Interest used in Computer Algebra Systems Lecture 2b.

Similar presentations


Presentation on theme: "Richard Fateman CS 282 Lecture 2b1 Basic Domains of Interest used in Computer Algebra Systems Lecture 2b."— Presentation transcript:

1 Richard Fateman CS 282 Lecture 2b1 Basic Domains of Interest used in Computer Algebra Systems Lecture 2b

2 Richard Fateman CS 282 Lecture 22 Some ideas just for representing integers Integers are sequences of characters, 0..9. Integers are sequences of words modulo 10 9 which is the largest power of 10 less than 2 31. Integers are sequences of hexadecimal digits. Integers are sequences of 32-bit words. Integers are sequences of 64-bit double-floats (with 8 bits wasted). Sequences are linked lists Sequences are vectors Sequences are stored in sequential disk locations

3 Richard Fateman CS 282 Lecture 23 Aside: using half the bits in a word is common strategy Integers are sequences of 32-bit words, but only the bottom 16 are used: There is some lack of uniformity in architectural support for unsigned 32X32 bit multiply. But 16X16  32 bit is supported, so programs can be portable. Downside: if you multiply two n-bigit numbers in time n 2 then with half-length bigits you need twice as many of them and so you take time (2n) 2, or 4 times slower and 2X the space.

4 Richard Fateman CS 282 Lecture 24 Yet more ideas Integers are stored in redundant form a+b+… Integer are stored modulo set of different primes Integers are stored in p-adic form as a sequence of x mod p, x mod p 2, …

5 Richard Fateman CS 282 Lecture 25 Redundant (big precision) floats Sequences (x n + ….+x 2 +x 1 ) Non-overlapping means each the lsb of x k is more significiant than the msb of x k-1. May be big gaps. Not unique. (binary values..) 1100 + -10.1 = 1001 + 0.1 = 1000+1+0.1 Easy to tell the sign. Look at the leading term. Adding must restore non-overlapping property. Important use by Jonathan Shewchuk (UCB) in geometric predicate calculations.

6 Richard Fateman CS 282 Lecture 26 Modular (mod a set of primes q 1, q 2, …q n ) images unique only within multiple of product of the primes Q = q 1 ¢ q 2 ¢ … ¢ q n. CRA (Chinese Remainder Algorithm) provides a way of going from modular to conventional positional notation, but takes O(n 2 ) in practice. This and its generalizations heavily used in computer algebra systems and this course.

7 Richard Fateman CS 282 Lecture 27 Modular arithmetic is really fast… all the arithmetic can be done without carry, in parallel. Not usually used because (a)You can’t tell for sure if a number is +, -, 0 or Q or 3 Q…. (b) Parallelism is almost always irrelevant  (c)If you must see the answer converted to decimal, the conversion is O(n 2 ) (d)Conversion to decimal may be very common if your application is a bignum calculator.

8 Richard Fateman CS 282 Lecture 28 What’s a p-adic integer? For the moment assume p is a prime number. Consider representing an integer  = a 0 +a 1.p+a 2 ¢ p 2 + … where a i are chosen from integers in the range 0 · a i < p For any finite positive integer , either all the a k are zero in which case  = 0 and ||  || p is 0, or some initial set of the a i are zero. Let a r+1 be the first non-zero term. ||  || p = p -r. This replaces the absolute-value valuation |  | where we consider that x and y are close if x=y mod p k for many values of k=0,1,2,….

9 Richard Fateman CS 282 Lecture 29 p-adic ordering is odd. 14 3-adically is 2*3 0 +1*3 1 +1*3 2 = 2 + 3 + 9 = 14 Which is very close to 5, 3-adically because 5 is 2*3 0 +1*3 1, and they are the same modulo 3 0 and 3 1. ||15-4|| 3 = 3 -1 What about negative numbers? p k -1 is possible, but consider p k -1 = (p-1) ¢ (p k-1 +p k-2 …+p+1)= (p-1)*1+(p-1)*p+(p-1)*p 2 +… so -1 3-adically is 2*3 0 +2*3 1 +…. Infinite number of terms (2,2,2,2,2,….)

10 Richard Fateman CS 282 Lecture 210 How to multiply p-adically (a,b,c) (d,e,f)  Compute a*d, a*e, a*f; add columns b*d, b*e; b*f c*d, c*e, c*f Add modulo p, p 2, p 3 … with a carry.

11 Richard Fateman CS 282 Lecture 211 How to multiply p-adically approximately (a,b,c …) (d,e,f …)  Compute a*d, a*e, a*f; add columns b*d, b*e; b*f c*d, c*e, c*f Add modulo p, p 2, p 3 … with a carry. Dropping off extra terms is like 3.14159 vs 3.14, but with respect to p-adic distances. Ignore these

12 Richard Fateman CS 282 Lecture 212 What other p-adic numbers are there?? -1/2 3-adically.. is 1*3 0+ 1*3 1 +1*3 2 = (1,1,1,1,1…). Proof: Multiply by 2, which is (2,0,0,0,….) to get (2,2,2,2…) which is -1 What about p 7 ? (a 0 +3*a 1 +…) 2 -7=0 (mod 3 i+1 ) Mod 3 0, a 0 2 -7=0 so a 0 is 1 or –1. Let’s choose 1. Next solve (1+3*a 1 +…) 2 -7=0 (mod 3 1 ) = 1+2*3*a 1 –7 =0 so a 1 =1 Eventually, p 7 = (1,1,1,2,…)

13 Richard Fateman CS 282 Lecture 213 What does this buy us?? Not a great deal for integers, but… We’ll use p-adic representation where p is not a number, but an indeterminate (say x), or a polynomial (x^2-3). Or a polynomial in several variables (x+y+1). If we compute a gcd of 2 polynomials p-adically approximately to high enough degree, we will know the exact GCD. If we can do this computation faster than other means, we have a winner. (This is the case.)

14 Richard Fateman CS 282 Lecture 214 Multiplication, usual representation Extremely well studied. The usual method takes O(n 2 ), Karatsuba style O(n 1.585 ) or FFT style O(n log n). These will be studied in the context of multiplying polynomials. Note that 345 can be mapped to p(x)=3x 2 +4x+5 where p(10) is 345. Except for the “carry”, the operation is the same.

15 Richard Fateman CS 282 Lecture 215 Integer Division This is too tedious to present in a lecture. Techniques for guessing the next big digit (bigit) of a quotient within +1 are available For exact division, consider Newton iteration is an alternative FFT / fast multiplication helps

16 Richard Fateman CS 282 Lecture 216 GCD Euclid’s algorithm is O(n 2 log n) but is hard to beat in practice, though see analysis of HGCD (Yap) for an O(n log 2 n) algorithm.. HGCD is portrayed as a winner for polynomials, but only by complexity analysts who (especially in this case) assume that – certain costs are constant when in fact they grow exponentially. –Multiplication cost n log n when, for relevant cases n 2 algorithms are much faster than the n log n ones

17 Richard Fateman CS 282 Lecture 217 Reminder… A Ring R is Euclidean If there is a function 

18 Richard Fateman CS 282 Lecture 218 Shows the tendency to obfuscate… What Rings do we use, and what is  ? For integers, absolute value | | =  For p-adic numbers, || || p norm For polynomials in x, degree in x = 

19 Richard Fateman CS 282 Lecture 219 Where next? We could spend a semester on integer arithmetic, but this does not accomplish any higher goals of CAS We can proceed to build models of real numbers by approximation (e.g. as limit of rational intervals). We may return to this.. We proceed to polynomials, typically with integer coefficients or finite field coeffs.

20 Richard Fateman CS 282 Lecture 220 Interlude, regarding your homework (the last problem) Usual representation in Lisp is trivial. 3*x^2+4 is something like (+ (* 3 (^ x 2) 4) In Lisp, * is a symbol. Times is a symbol..

21 Richard Fateman CS 282 Lecture 221 Trivial parts.. Given a, b, a program to produce a product is (defun prod(a b)(list ‘* a b)) ;common lisp syntax (define (prod a b)(list ‘* a b)) ;scheme syntax function make_prod(a:tree,b:tree):tree var temp:^tree; {hm, something like this..} begin temp:= new(tree); temp^.head:= asterisk; temp^.left:=a; temp^.right:=b, make_prod:=temp end {Pascal?? Similarly for C, Java, …}

22 Richard Fateman CS 282 Lecture 222 Harder parts.. If you need to know that (* x 0), (+ x (* -1 x)) and 0 are the same, how much work must you do? (Schwartz-Zippel polynomial identity testing)

23 Richard Fateman CS 282 Lecture 223 Reminder: The Usual Coefficients Z: natural numbers (ring, integers, +-* not closed under division!) Z p :integers modulo p, p a prime usually. Q: rational numbers (a field). What is the difference between 3/4 and 6/8? R: real includes irrationals p 2,transcendentals (e,  ) {mention continued fracs, intervals} C: complex –approximation –special case of algebraic extension –Analysis: functions of a complex variable

24 Richard Fateman CS 282 Lecture 224 Preview: Extensions if x is an indeterminate, and if D is a domain, we can talk about D[x], polynomials in x with coefficients in D or D(x) ratios of polys in x. Or D[[x]] : (truncated) power series in x over D. Or Matrices over D.

25 Richard Fateman CS 282 Lecture 225 Beware of notation A particular polynomial expression might be referred to as p(x), which notation is also used to denote a function or mapping p:D 1  D 2 or a function application if x is not an indeterminate but a element in a field as p(3). Confused? The notation is unfortunate. Not confused? You are probably used to it.

26 Richard Fateman CS 282 Lecture 226 Aside 2.1: canonical forms vs. mathematical equivalence Mathematically, we don’t distinguish between two equivalent elements in Z(x), say 1/(x+1) and (x-1)/(x 2 -1). Computationally these can be distinguished, and generally they must be distinguished. Often we must compute a canonical form for an expression by finding a particular “simplest” form in an equivalence class.

27 Richard Fateman CS 282 Lecture 227 Aside 2.2: Simplification is almost everything in this business.. Trivial reduction. All computational problems in computer algebra can be reduced to simplification: simplify (ProblemStatement) to CanonicalSolution

28 Richard Fateman CS 282 Lecture 228 Aside 2.3: Computer representation and canonical forms A computer might distinguish between two strings “abc” and “abc” if they are stored in different locations in memory. Or might not. Usually it is advantageous to store an object only once in memory, but not always. (Should we store 43 just once? How about 3.141592654 ? How about ax 2 +bx+c?)

29 Richard Fateman CS 282 Lecture 229 Back to extensions if r is a root of an irreducible polynomial p, that is, p(r)=0, we will also talk about a ring or field extended by r: Q[r]. E.g. p(r)=r 2 -1=0 means r = p (-1) or i, and we have just constructed the complex rationals Q[r]. Z[i] is called “Gaussian integers" The set of elements a+bi, with a, b, integers. Q[i] would allow rational a, b. (remember rationalizing denominators?) Given such a field, you can extend it again. IF you want to represent Q extended by sqrt(2), and then THAT extended by sqrt(3), you can do so. Don't extend it again by sqrt(6). (why?)

30 Richard Fateman CS 282 Lecture 230 More on extensions In nice cases (primitive element), algebraic arithmetic can be done by "reducing" modulo r. This is accomplished by dividing by p(r) and discarding the remainder: if E = a+b*p(r) then E ´ a You may need reminders of shortcuts. e.g. remainder of p(x) / (x-a) is the same as substituting a for x in p. (other terms we will use on occasion: Euclidean domains, unique factorization domains, ideals, differential fields, algebraic curves. We’ll motivate them when needed)

31 Richard Fateman CS 282 Lecture 231 Other extensions Differential fields have what amounts to log() and exp() extensions. And an operation of differentiation such that D(exp(x)) = exp(x), D(log(x)) =1/x. Exp and log can be nested, and you can make trig functions:

32 Richard Fateman CS 282 Lecture 232 There’s more… Other kinds of symbolic computation Whole careers have been made out of other kinds of symbolic computation: theorem proving, string manipulation, group representations, geometric computation, type theory/programming language representations, etc. (J. Symbolic Computation publishes broadly…) We will not probably not get to any of these areas in this course, although I could be swayed by student interest… also projects involving these topics are generally appropriate.


Download ppt "Richard Fateman CS 282 Lecture 2b1 Basic Domains of Interest used in Computer Algebra Systems Lecture 2b."

Similar presentations


Ads by Google