# Revision history [back]

### 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.) 





 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license. about | faq | help | privacy policy | terms of service Powered by Askbot version 0.7.59 Please note: Askbot requires javascript to work properly, please enable javascript in your browser, here is how //IE fix to hide the red margin var noscript = document.getElementsByTagName('noscript')[0]; noscript.style.padding = '0px'; noscript.style.backgroundColor = 'transparent'; askbot['urls']['mark_read_message'] = '/s/messages/markread/'; askbot['urls']['get_tags_by_wildcard'] = '/s/get-tags-by-wildcard/'; askbot['urls']['get_tag_list'] = '/s/get-tag-list/'; askbot['urls']['follow_user'] = '/followit/follow/user/{{userId}}/'; askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{userId}}/'; askbot['urls']['user_signin'] = '/account/signin/'; askbot['urls']['getEditor'] = '/s/get-editor/'; askbot['urls']['apiGetQuestions'] = '/s/api/get_questions/'; askbot['urls']['ask'] = '/questions/ask/'; askbot['urls']['questions'] = '/questions/'; askbot['settings']['groupsEnabled'] = false; askbot['settings']['static_url'] = '/m/'; askbot['settings']['minSearchWordLength'] = 4; askbot['settings']['mathjaxEnabled'] = true; askbot['settings']['sharingSuffixText'] = ''; askbot['settings']['errorPlacement'] = 'after-label'; askbot['data']['maxCommentLength'] = 800; askbot['settings']['editorType'] = 'markdown'; askbot['settings']['commentsEditorType'] = 'rich\u002Dtext'; askbot['messages']['askYourQuestion'] = 'Ask Your Question'; askbot['messages']['acceptOwnAnswer'] = 'accept or unaccept your own answer'; askbot['messages']['followQuestions'] = 'follow questions'; askbot['settings']['allowedUploadFileTypes'] = [ "jpg", "jpeg", "gif", "bmp", "png", "tiff" ]; askbot['data']['haveFlashNotifications'] = true; askbot['data']['activeTab'] = 'questions'; askbot['settings']['csrfCookieName'] = 'asksage_csrf'; askbot['data']['searchUrl'] = ''; /*<![CDATA[*/ $('.mceStatusbar').remove();//a hack to remove the tinyMCE status bar$(document).ready(function(){ // focus input on the search bar endcomment var activeTab = askbot['data']['activeTab']; if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) { var searchInput = $('#keywords'); } else if (activeTab === 'ask') { var searchInput =$('#id_title'); } else { var searchInput = undefined; animateHashes(); } var wasScrolled = $('#scroll-mem').val(); if (searchInput && !wasScrolled) { searchInput.focus(); putCursorAtEnd(searchInput); } var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']); var haveUserProfilePage =$('body').hasClass('user-profile-page'); if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput && searchInput.length) { var search = new FullTextSearch(); askbot['controllers'] = askbot['controllers'] || {}; askbot['controllers']['fullTextSearch'] = search; search.setSearchUrl(askbot['data']['searchUrl']); if (activeTab === 'ask') { search.setAskButtonEnabled(false); } search.decorate(searchInput); } else if (activeTab === 'tags') { var search = new TagSearch(); search.decorate(searchInput); } if (askbot['data']['userIsAdminOrMod']) { $('body').addClass('admin'); } if (askbot['settings']['groupsEnabled']) { askbot['urls']['add_group'] = "/s/add-group/"; var group_dropdown = new GroupDropdown();$('.groups-dropdown').append(group_dropdown.getElement()); } var userRep = $('#userToolsNav .reputation'); if (userRep.length) { var showPermsTrigger = new ShowPermsTrigger(); showPermsTrigger.decorate(userRep); } }); if (askbot['data']['haveFlashNotifications']) {$('#validate_email_alert').click(function(){notify.close(true)}) notify.show(); } var langNav = $('.lang-nav'); if (langNav.length) { var nav = new LangNav(); nav.decorate(langNav); } /*]]>*/ if (typeof MathJax != 'undefined') { MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], tex2jax: {inlineMath: [["$","$"],["\$","\$"]]} }); } else { console.log('Could not load MathJax'); } //todo - take this out into .js file$(document).ready(function(){ $('div.revision div[id^=rev-header-]').bind('click', function(){ var revId = this.id.substr(11); toggleRev(revId); }); lanai.highlightSyntax(); }); function toggleRev(id) { var arrow =$("#rev-arrow-" + id); var visible = arrow.attr("src").indexOf("hide") > -1; if (visible) { var image_path = '/m/default/media/images/expander-arrow-show.gif?v=19'; } else { var image_path = '/m/default/media/images/expander-arrow-hide.gif?v=19'; } image_path = image_path + "?v=19"; arrow.attr("src", image_path); \$("#rev-body-" + id).slideToggle("fast"); } for (url_name in askbot['urls']){ askbot['urls'][url_name] = cleanUrl(askbot['urls'][url_name]); }