07-401/Andrei Litvin Poly Solution

From Drorbn
Jump to navigationJump to search

See the "Just for Fun" part of 07-401/Homework Assignment 7

Here is what I have so far in terms of polynomials:

Polynomial with root :

(duh)

Polynomial with root :

(duh as well)

Polynomial with root :

(more interesting!)

Polynomial with root :

(similar to the above)

Polynomial with root :

(just invert the above .. quite the same as the above 2)

Polynomial with root :

(ok .. this is ugly)

Polynomial with root :

(very ugly .. especially considering you are not done yet and the next matrix to compute will be quite large)

This is how far I got so far. The program itself will do any polynomials just fine (I tweaked it a lot to get the final poly, so it may still have some bugs, however it works). The problem is working with such large numbers. The reducing part will multiply with 289 each time a is reduced, so we could potentially get coefficients of the order , which is very large indeed. On my computer, I get about 30% done, when it starts running out of memory and I had to stop. This is why the program just generates the matrices for the last part (and by the way, Maxima crashed when trying to load the matrix to invert, so I will have to find another program that will handle such large sets of data)

Comments by Dror. Great work! Your grade for the class is bounded below by 80; the exams and HW will determine which fraction of the other 20 you will get. To raise your lower bound to 85, you'll have to post the programs (either here, as text files, or elsewhere with a link from here) along with a brief manual page that will allow anybody else to run them. To raise your lower bound to 90, you'll also have to tell me, I don't care how, what is the second largest coefficient that occurs in the solution to the overall problem. The largest is

(223 decimal digits)

Program

A zip file containing the program can be downloaded here (I hope this works .. if not send me an e-mail).

It does require Python (I developed and tested it with version 2.5) and the file you probably want to edit is "test.py" (or you can also create your own program files if you wish).

It starts with a statement of the form "x = Poly()" which by default creates the polynomial "x". The object overloads +,-,* and ** (power),so that you can build your own fancy polynomials (e.g. "x**2 + 4*x + 1" or "(x + 256)*((x**34 + 1)**3) + 1).

After you have built one or more polynomials (the sample starts with simple ones, like "x - 7" and " x- 5), you have an array of functions that you can build new polynomials. These are:

  • "solve_inverse(p)":
    • if then return q, such that
  • "solve_sqrt(p, n)":
    • if , then return q, such that
  • "solve_sum(p1, p2)"
    • if and , then return q, such that
  • "solve_diff(p1, p2)"
    • if and , then return q, such that
  • "solve_prod(p1, p2)"
    • if and , then return q, such that

Now you are ready to do things like:

 from poly import *        # these imports are needed
 from polysolve import *
 
 x = Poly()                # the most basic poly you can get
 
 p1 = solve_sum(x**3 - 3, x**5 - 6)
 p2 = solve_sum(x**2 - 2, x - 1)
 p3 = solve_sum(p1, p2)
 
 print p3