Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Equation solution returns unequal values for supposedly equal variables

Context: The "Classic" riddle here: https://fivethirtyeight.com/features/can-you-crack-the-safe/

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), W X Y Z are areas in square units. I've left out declarations and some definitions/equations to focus on the main issue.

**** tri(l,m,n) = abs((I/4)*(l*conjugate(m) - m*conjugate(l) + m*conjugate(n) \ 
                           - n*conjugate(m) + n*conjugate(l) - l*conjugate(n)))
**** aslice(r,s,t,u,v) = (1/2)*(s-r) - tri(t,u,0) + tri(t,u,v)

**** eq5 = W == aslice(A,B,a,b,p)
eq6 = X == aslice(B,C,b,c,p)
eq7 = Y == aslice(C,D,c,d,p)
eq8 = Z == aslice(D,2*pi,d,a,p)
eq9 =  X == 2*W
eq10 = Y == 3*W
eq11 = Z == 4*W

Out = solve([$eqs], $vars, solution_dict=True)

**** print(CC(W.subs(Out[0])))
**** print(CC(aslice(A,B,a,b,p).subs(Out[0])))
**** print(CC(((1/2)*(B-A) + tri(a,b,p) - tri(a,b,0)).subs(Out[0])))

And the output is this:

0.314159265358979
0.132523633357639
0.132523633357639

Now, based on eq5, the three outputs at the bottom ought to be equal. But the solved-for W (first line) appears to be the area of the circular sector, where aslice() (second line) and its definition (third line) correctly output the area of the actual slice (based on the solved-for variables).

Unfortunately, this means the program is comparing the wrong things in 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?

Equation solution returns unequal values for supposedly equal variables

Context: The "Classic" riddle here: https://fivethirtyeight.com/features/can-you-crack-the-safe/

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), W X Y Z are areas ). As requested in square units. I've left 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 declarations and some definitions/equations to focus on the main issue.

**** tri(l,m,n) = abs((I/4)*(l*conjugate(m) - m*conjugate(l) + m*conjugate(n) \ 
                           - n*conjugate(m) + n*conjugate(l) - l*conjugate(n)))
**** aslice(r,s,t,u,v) = (1/2)*(s-r) - tri(t,u,0) + tri(t,u,v)
= (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 = W == aslice(A,B,a,b,p)
aslice(a,b,p) + (1/2)*(B-A) == (pi/10)
eq6 = X == aslice(B,C,b,c,p)
aslice(b,c,p) + (1/2)*(C-B) == (4*pi/10)
eq7 = Y == aslice(C,D,c,d,p)
aslice(c,d,p) + (1/2)*(D-C) == (3*pi/10)
eq8 = Z == aslice(D,2*pi,d,a,p)
eq9 =  X == 2*W
eq10 = Y == 3*W
eq11 = Z == 4*W
aslice(d,a,p) + (1/2)*(2*pi-D) == (2*pi/10)

Out = solve([$eqs], $vars, 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(W.subs(Out[0])))
**** print(CC(aslice(A,B,a,b,p).subs(Out[0])))
**** print(CC(((1/2)*(B-A) + tri(a,b,p) - tri(a,b,0)).subs(Out[0])))
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:

0.314159265358979
0.132523633357639
0.132523633357639
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 eq5eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10), the three outputs third output at the bottom ought to be equal. But the equal to pi/10 ~= 0.3141592... The solved-for W (first line) appears area, however, is clearly unequal to be the area of the circular sector, where aslice() (second line) and its definition (third line) correctly output the area of the actual slice (based on the solved-for variables).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.)