ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 08 Oct 2022 03:45:16 +0200Equation solution returns unequal values for supposedly equal variableshttps://ask.sagemath.org/question/64342/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`). 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.)Fri, 07 Oct 2022 06:22:55 +0200https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/Comment by Eric Snyder for <p>Context: The "Classic" riddle here: <a href="https://fivethirtyeight.com/features/can-you-crack-the-safe/">https://fivethirtyeight.com/features/...</a></p>
<p>Input code. There's quite a bit going on here, but the asterisks mark the most important lines. <code>B C D</code> are angles in radians, <code>b c d</code> are the corresponding complex coordinates on the unit circle (<code>A=0</code> and <code>a=1</code>). As requested in a comment below, this is complete code; though some definitions and quantities have changed, the issue remains.</p>
<pre><code>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])))
</code></pre>
<p>And the output is this:</p>
<pre><code>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
</code></pre>
<p>Now, based on <code>eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10)</code>, 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.</p>
<p>Unfortunately, this means the program is comparing the wrong things in <code>eq5, eq6, eq7, eq8</code>, so the solution is not much of a solution at all. I'm not sure what could be causing this issue, though. Any thoughts?</p>
<p>(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.)</p>
https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64353#post-id-64353Edited to give complete code as requested.Sat, 08 Oct 2022 03:45:16 +0200https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64353#post-id-64353Comment by Max Alekseyev for <p>Context: The "Classic" riddle here: <a href="https://fivethirtyeight.com/features/can-you-crack-the-safe/">https://fivethirtyeight.com/features/...</a></p>
<p>Input code. There's quite a bit going on here, but the asterisks mark the most important lines. <code>B C D</code> are angles in radians, <code>b c d</code> are the corresponding complex coordinates on the unit circle (<code>A=0</code> and <code>a=1</code>). As requested in a comment below, this is complete code; though some definitions and quantities have changed, the issue remains.</p>
<pre><code>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])))
</code></pre>
<p>And the output is this:</p>
<pre><code>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
</code></pre>
<p>Now, based on <code>eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10)</code>, 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.</p>
<p>Unfortunately, this means the program is comparing the wrong things in <code>eq5, eq6, eq7, eq8</code>, so the solution is not much of a solution at all. I'm not sure what could be causing this issue, though. Any thoughts?</p>
<p>(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.)</p>
https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64352#post-id-64352Then please provide a complete code example illustrating the issue.Sat, 08 Oct 2022 03:21:10 +0200https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64352#post-id-64352Comment by Eric Snyder for <p>Context: The "Classic" riddle here: <a href="https://fivethirtyeight.com/features/can-you-crack-the-safe/">https://fivethirtyeight.com/features/...</a></p>
<p>Input code. There's quite a bit going on here, but the asterisks mark the most important lines. <code>B C D</code> are angles in radians, <code>b c d</code> are the corresponding complex coordinates on the unit circle (<code>A=0</code> and <code>a=1</code>). As requested in a comment below, this is complete code; though some definitions and quantities have changed, the issue remains.</p>
<pre><code>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])))
</code></pre>
<p>And the output is this:</p>
<pre><code>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
</code></pre>
<p>Now, based on <code>eq5 = aslice(a,b,p) + (1/2)*(B-A) == (pi/10)</code>, 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.</p>
<p>Unfortunately, this means the program is comparing the wrong things in <code>eq5, eq6, eq7, eq8</code>, so the solution is not much of a solution at all. I'm not sure what could be causing this issue, though. Any thoughts?</p>
<p>(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.)</p>
https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64351#post-id-64351Alas, 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.Sat, 08 Oct 2022 02:57:12 +0200https://ask.sagemath.org/question/64342/equation-solution-returns-unequal-values-for-supposedly-equal-variables/?comment=64351#post-id-64351