Discussion:
Examples of EVAL
(too old to reply)
Beau Osborne
2005-04-28 13:56:42 UTC
Permalink
Can 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
Matt Compton
2005-04-28 17:20:32 UTC
Permalink
Here's what I got:

Polynomial> 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>

If you work it out:

x^3 + 2x^2 + 3x +4 evaluated at 2 with a modulus of 15

(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 Osborne
Can 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
Ryan Henry
2005-04-28 17:27:20 UTC
Permalink
Post by Beau Osborne
Polynomial> 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 Osborne
Can 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
Beau Osborne
2005-04-28 19:59:34 UTC
Permalink
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 Henry
Post by Beau Osborne
Polynomial> 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 Osborne
Can 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
David Zhao
2005-04-28 21:07:34 UTC
Permalink
I'm fairly certain that the recursive definition is more efficient.

David
Post by Beau Osborne
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?
-----------------------------------
Polynomial> eval [1,2,1,0] 2 17
9
-----------------------------------
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
Ryan
2005-04-29 03:57:49 UTC
Permalink
Post by Beau Osborne
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?
I was replying to Matt's post, not yours. I got the same values as you
did.
Post by Beau Osborne
-----------------------------------
Polynomial> eval [1,2,1,0] 2 17
9
-----------------------------------
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 Henry
Post by Beau Osborne
Polynomial> 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 Osborne
Can 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
bushk
2005-04-29 04:05:17 UTC
Permalink
Main> eval [1,2,3,4] 2 15
4
Main> eval [1,2,3,4] 2 17
15
Main> eval [2,3,0,9] 2 17
12
Main> eval [2,3,0,9] 2 7
3

...confirming Beau Osbornes results.

David Zhao, who cares about efficency, it's pretty! and that's all
that matters.
Post by Beau Osborne
Polynomial> 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
(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 Osborne
Can 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
David Zhao
2005-04-29 17:14:55 UTC
Permalink
But it's pretty because it's efficient.

David
Post by bushk
David Zhao, who cares about efficency, it's pretty! and that's all
that matters.
k
bushk
2005-04-29 22:33:03 UTC
Permalink
in this case, perhaps. but not generally. often we turn beauty into
chaos, all in the name of efficiency. :)
Post by David Zhao
But it's pretty because it's efficient.
David
Post by bushk
David Zhao, who cares about efficency, it's pretty! and that's all
that matters.
k
Lilian
2005-04-29 00:21:58 UTC
Permalink
I got the same outputs too with my 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
Post by Beau Osborne
Can 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
Loading...