I rewrote my eval function to evaluate the polynomial using 1x^0 + 2x^1 +
3x^2 + 4x^3. It produced the same values that I had before. I had
originally used the polynomial equation listed in the handout: A(x0) = a0 +
x0(a1 + x0(a2 + · · · + x0(an?2 + x0(an?1)) · · · )). I'm not sure which is
more efficient. Any guesses?
Here are my solutions using the 1x^0 + 2x^1 + 3x^2 + 4x^3 method:
Example From examples.txt:
-----------------------------------
Polynomial> eval [1,2,1,0] 2 17
9
Other Test Examples:
-----------------------------------
Polynomial> eval [1,2,3,4] 2 15
4
Polynomial> eval [1,2,3,4] 2 17
15
Polynomial> eval [2,3,0,9] 2 17
12
Polynomial> eval [2,3,0,9] 2 7
3
Post by Ryan HenryPost by Beau OsbornePolynomial> eval [1,2,3,4] 2 15
11
Polynomial> eval [1,2,3,4] 2 17
9
Polynomial> eval [2,3,0,9] 2 17
3
Polynomial> eval [2,3,0,9] 2 7
2
Polynomial>
x^3 + 2x^2 + 3x +4 evaluated at 2 with a modulus of 15
You're evaluating the polynomial backwards. It is 1x^0 + 2x^1 + 3x^2 +
4x^3.
Post by Beau Osborne(8 mod 15) + (8 mod 15) + (6 mod 15) + (4 mod 15)
8 + 8 + 6 + 4 = 26
26 mod 15 = 11
Then again mine could be toast.
Matt
Post by Beau OsborneCan someone verify that these are the correct outputs for the function eval?
Polynomial> eval [1,2,3,4] 2 15
4
Polynomial> eval [1,2,3,4] 2 17
15
Polynomial> eval [2,3,0,9] 2 17
12
Polynomial> eval [2,3,0,9] 2 7
3