# Revision history [back]

I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration:

sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2)
sage: n = 720

sage: for a,b in xmrange([n,n]):
sage:     if f(a,b) == 2*n:
sage:         print a,b
7 9
9 7


I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration:

sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2)
sage: n = 720

sage: for a,b in xmrange([n,n]):
sage:     if f(a,b) == 2*n:
sage:         print a,b
7 9
9 7


And actually you can be more restrictive and ask a and b to be less that something of the order of sqrt(n) (instead of n).

I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration:

sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2)
sage: n = 720

sage: for a,b in xmrange([n,n]):
sage:     if f(a,b) == 2*n:
sage:         print a,b
7 9
9 7


And actually you can be more restrictive and ask a and b to be less that something of the order of sqrt(n)sqrt(2*n) (instead of n).

):

sage: bound = floor(sqrt(2*n))
sage: for a,b in xmrange([bound,bound]):
sage:     if f(a,b) == 2*n:
sage:         print a,b
7 9
9 7


Hence, you get all answers in time $O(n)$ instead of $O(n^2)$. Why not solving directly your equation ? Unfortunately, it seems that the solver is not able to solve the diophantine equation f(a,b) == 2*n directly:

sage: var('a','b')
(a, b)
sage: solve([f(a,b) == 2*n ], a, b)
([a == -1/2*(4*b + sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1), a == -1/2*(4*b - sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1)],
[1, 1])


But you can still use Sage solver when a is fixed:

sage: var('b')
b
sage: assume(b, 'integer')
sage: assume(b >= 0)

sage: for a in xrange(bound):
sage:     sol = solve([f(a,b) == 2*n],b)
sage:     if len(sol) != 0:
sage:         print a, sol[0].rhs()
sage:
7 9
9 7


Now you get an answer in time $0(sqrt(n))$.

I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration:

sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2)
sage: n = 720

sage: for a,b in xmrange([n,n]):
sage:     if f(a,b) == 2*n:
sage:         print a,b
7 9
9 7


And actually you can be more restrictive and ask a and b to be less that something of the order of sqrt(2*n)than floor(sqrt(2*n)) (instead of n):

 sage: bound = floor(sqrt(2*n)) sage: for a,b in xmrange([bound,bound]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 Hence, you get all answers in time $O(n)$ instead of $O(n^2)$. Why But why not solving directly your equation ? Unfortunately, it seems that the solver is not able to solve the diophantine equation f(a,b) == 2*n directly: sage: var('a','b') (a, b) sage: solve([f(a,b) == 2*n ], a, b) ([a == -1/2*(4*b + sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1), a == -1/2*(4*b - sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1)], [1, 1]) But you can still use Sage solver when a is fixed: sage: var('b') b sage: assume(b, 'integer') sage: assume(b >= 0) sage: for a in xrange(bound): sage: sol = solve([f(a,b) == 2*n],b) sage: if len(sol) != 0: sage: print a, sol[0].rhs() sage: 7 9 9 7 Now Now, you get an answer in time $0(sqrt(n))$. $0(\sqrt(n))$, which is not satisfactory, but not that bad. That said, since the solver is quite slow, the multiplicative constant in the complexity is quite huge and the previous method is faster for small n (this is clear for n =6216 : 42.7ms vs 1.11s). This last method becomes faster only later (this is clear for n =9933 : 8.79s vs 1.41s). 

 5 No.5 Revision updated 2013-05-23 18:34:57 +0100 I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration: sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2) sage: n = 720 sage: for a,b in xmrange([n,n]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 And actually you can be more restrictive and ask a and b to be less than floor(sqrt(2*n)) (instead of n): sage: bound = floor(sqrt(2*n)) sage: for a,b in xmrange([bound,bound]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 Hence, you get all answers in time $O(n)$ instead of $O(n^2)$. But why not solving directly your equation ? Unfortunately, it seems that the solver is not able to solve the diophantine equation f(a,b) == 2*n directly: sage: var('a','b') (a, b) sage: solve([f(a,b) == 2*n ], a, b) ([a == -1/2*(4*b + sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1), a == -1/2*(4*b - sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1)], [1, 1]) But you can still use Sage solver when a is fixed: sage: var('b') b sage: assume(b, 'integer') sage: assume(b >= 0) sage: for a in xrange(bound): sage: sol = solve([f(a,b) == 2*n],b) sage: if len(sol) != 0: sage: print a, sol[0].rhs() sage: 7 9 9 7 Now, you get an answer in time $0(\sqrt(n))$, which is not satisfactory, but not that bad. That said, since the solver is quite slow, the multiplicative constant in the complexity is quite huge and the previous method is faster for small n (this is clear for n =6216n=6216 : 42.7ms 42.7ms vs 1.11s). 1.11s). This last method becomes faster only later (this is clear for n =9933n=9933 : 8.79s 8.79s vs 1.41s). 1.41s). 6 No.6 Revision updated 2013-05-23 18:45:12 +0100 I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration: sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2) sage: n = 720 sage: for a,b in xmrange([n,n]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 And actually you can be more restrictive and ask a and b to be less than floor(sqrt(2*n)) (instead of n): sage: bound = floor(sqrt(2*n)) sage: for a,b in xmrange([bound,bound]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 Hence, you get all answers in time $O(n)$ instead of $O(n^2)$. But why not solving directly your equation ? Unfortunately, it seems that the solver is not able to solve the diophantine equation f(a,b) == 2*n directly: sage: var('a','b') (a, b) sage: solve([f(a,b) == 2*n ], a, b) ([a == -1/2*(4*b + sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1), a == -1/2*(4*b - sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1)], [1, 1]) But you can still use Sage solver when a is fixed: sage: var('b') b sage: assume(b, 'integer') sage: assume(b >= 0) sage: for a in xrange(bound): sage: sol = solve([f(a,b) == 2*n],b) sage: if len(sol) != 0: sage: print a, sol[0].rhs() sage: 7 9 9 7 Now, you get an answer in time $0(\sqrt(n))$, which is not satisfactory, but not that bad. That said, since the solver is quite slow, the multiplicative constant in the complexity is quite huge and the previous method is faster for small n (this is clear for n=6216 : 42.7ms vs 1.11s). This last method becomes faster only later (this is clear for n=9933n=3065451 : 8.79s94.43s vs 1.41s29.77s). 7 No.7 Revision updated 2013-05-24 06:51:30 +0100 I am not sure i understand your question correctly. If you want to iterate over the pairs of integers, you can have a look at multidimensional enumeration: sage: f = lambda a,b : (a+1)*(b+1)*(a+b+2) sage: n = 720 sage: for a,b in xmrange([n,n]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 And actually you can be more restrictive and ask a and b to be less than floor(sqrt(2*n)) (instead of n): sage: bound = floor(sqrt(2*n)) sage: for a,b in xmrange([bound,bound]): sage: if f(a,b) == 2*n: sage: print a,b 7 9 9 7 Hence, you get all answers in time $O(n)$ instead of $O(n^2)$. But why not solving directly your equation ? Unfortunately, it seems that the solver is not able to solve the diophantine equation f(a,b) == 2*n directly: sage: var('a','b') (a, b) sage: solve([f(a,b) == 2*n ], a, b) ([a == -1/2*(4*b + sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1), a == -1/2*(4*b - sqrt(b^4 + 4*b^3 + 6*b^2 + 5764*b + 5761) + b^2 + 3)/(b + 1)], [1, 1]) But you can still use Sage solver when a is fixed: sage: var('b') b sage: assume(b, 'integer') sage: assume(b >= 0) sage: for a in xrange(bound): sage: sol = solve([f(a,b) == 2*n],b) sage: if len(sol) != 0: sage: print a, sol[0].rhs() sage: 7 9 9 7 Now, you get an answer in time $0(\sqrt(n))$, $O(\sqrt{n})$, which is not satisfactory, completely satisfactory (one could expect a polynomial in $\log(n)$), but not that bad. That said, since the solver is quite slow, the multiplicative constant in the complexity is quite huge and the previous method is faster for small n (this is clear for n=6216 : 42.7ms vs 1.11s). This The last method becomes faster only later (this is clear for n=3065451 : 94.43s vs 29.77s). 


 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]); }