Equation solution returns unequal values for supposedly equal variables

asked 2022-10-07 06:22:55 +0200

Eric Snyder gravatar image

updated 2022-10-08 03:44:38 +0200

Context: The "Classic" riddle here: https://fivethirtyeight.com/features/...

Input code. There's quite a bit going on here, but the asterisks mark the most important lines. B C D are angles in radians, b c d are the corresponding complex coordinates on the unit circle (A=0 and a=1). As requested in a comment below, this is complete code; though some definitions and quantities have changed, the issue remains.

B, C, D, b, c, d, p = var('B C D b c d p')

def aslice(t,u,v):
    out = (I/4)*(u*conjugate(v) - v*conjugate(u) + v*conjugate(t) - t*conjugate(v))
    return out

A = 0
a = 1

eq1 = b == exp(B*I)
eq2 = c == exp(C*I)
eq3 = d == exp(D*I)

eq4 = p == (a*c*(b+d) - b*d*(a+c))/(a*c-b*d)

**** eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10)
eq6 = aslice(b,c,p) + (1/2)*(C-B) == (4*pi/10)
eq7 = aslice(c,d,p) + (1/2)*(D-C) == (3*pi/10)
eq8 = aslice(d,a,p) + (1/2)*(2*pi-D) == (2*pi/10)

Out = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8], B, C, D, b, c, d, p, solution_dict=True)
Out2 = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8], B, C, D, b, c, d, p)

print(Out2[0][0], Out2[0][1], Out2[0][2])

print(CC(p.subs(Out[0])), '\n')
**** print(CC((aslice(a,b,p) + (1/2)*(B-A)).subs(Out[0])))
print(CC((aslice(b,c,p) + (1/2)*(C-B)).subs(Out[0])))
print(CC((aslice(c,d,p) + (1/2)*(D-C)).subs(Out[0])))
print(CC((aslice(d,a,p) + (1/2)*(2*pi-D)).subs(Out[0])))

And the output is this:

B == 1/5*pi C == pi D == 8/5*pi
0.618033988749895 - 2.77555756156289e-17*I 

0.132523633357639 + 2.77555756156289e-17*I
1.43827269343726 - 2.77555756156289e-17*I
1.23637042222317 - 6.93889390390723e-18*I
0.334425904571722 + 6.93889390390723e-18*I

Now, based on eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10), the third output at the bottom ought to be equal to pi/10 ~= 0.3141592... The solved-for area, however, is clearly unequal to this.

Unfortunately, this means the program is comparing the wrong things in eq5, eq6, eq7, eq8, so the solution is not much of a solution at all. I'm not sure what could be causing this issue, though. Any thoughts?

(For the record the correct solution would have on the top line: B ~= 0.8936, C = pi, D ~= 4.6857; neither B nor D is a pretty fraction of pi.)

edit retag flag offensive close merge delete

Comments

Alas, that didn't change anything. I was thinking that might be a thing, but the definitions of functions for symbolics suggested it need not be.

Eric Snyder gravatar imageEric Snyder ( 2022-10-08 02:57:12 +0200 )edit

Then please provide a complete code example illustrating the issue.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-10-08 03:21:10 +0200 )edit

Edited to give complete code as requested.

Eric Snyder gravatar imageEric Snyder ( 2022-10-08 03:45:16 +0200 )edit