{"id":59,"date":"2016-10-28T23:40:48","date_gmt":"2016-10-28T23:40:48","guid":{"rendered":"https:\/\/petermc.net\/blog\/?p=59"},"modified":"2016-10-28T23:40:48","modified_gmt":"2016-10-28T23:40:48","slug":"single-variable-polynomial-division-in-sage","status":"publish","type":"post","link":"https:\/\/petermc.net\/blog\/2016\/10\/28\/single-variable-polynomial-division-in-sage\/","title":{"rendered":"Single variable polynomial division in sage"},"content":{"rendered":"<p>As far as I can tell, this isn&#8217;t done purely within sage, and requires a call to maxima.<\/p>\n<p>If you want to divide the polynomial <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"a\" class=\"latex\" \/> by <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"b\" class=\"latex\" \/> to produce a quotient and remainder, the code is.<br \/>\n<code><br \/>\na.maxima_methods().divide(b)<br \/>\n<\/code><br \/>\nThe first element of the output is the quotient and the second is the remainder.<\/p>\n<p>So for example<br \/>\n<code><br \/>\nsage: R=QQ['x']<br \/>\nsage: a=x^210-1<br \/>\nsage: b=R.cyclotomic_polynomial(210)*(x-1)<br \/>\nsage: q,r=a.maxima_methods().divide(b)<br \/>\nsage: q<br \/>\nx^161 + 2*x^160 + 2*x^159 + x^158 - x^156 - x^155 - x^154 - x^153 - x^152 + x^150 + 2*x^149 + 2*x^148 + 2*x^147 + 2*x^146 + 2*x^145 + x^144 - x^142 - x^141 + x^139 + x^138 + x^137 + x^136 + x^135 + x^134 + x^133 + x^132 + x^131 + x^130 + x^129 + x^128 + x^127 + 2*x^126 + 3*x^125 + 3*x^124 + 2*x^123 + x^122 + x^116 + 2*x^115 + 3*x^114 + 3*x^113 + 3*x^112 + 3*x^111 + 3*x^110 + 2*x^109 + x^108 + x^105 + 2*x^104 + 2*x^103 + 2*x^102 + 2*x^101 + 2*x^100 + 2*x^99 + 2*x^98 + 2*x^97 + 2*x^96 + 2*x^95 + 2*x^94 + 2*x^93 + 2*x^92 + 2*x^91 + 2*x^90 + 2*x^89 + 2*x^88 + 2*x^87 + 2*x^86 + 2*x^85 + 2*x^84 + 2*x^83 + 2*x^82 + 2*x^81 + 2*x^80 + 2*x^79 + 2*x^78 + 2*x^77 + 2*x^76 + 2*x^75 + 2*x^74 + 2*x^73 + 2*x^72 + 2*x^71 + 2*x^70 + 2*x^69 + 2*x^68 + 2*x^67 + 2*x^66 + 2*x^65 + 2*x^64 + 2*x^63 + 2*x^62 + 2*x^61 + 2*x^60 + 2*x^59 + 2*x^58 + 2*x^57 + x^56 + x^53 + 2*x^52 + 3*x^51 + 3*x^50 + 3*x^49 + 3*x^48 + 3*x^47 + 2*x^46 + x^45 + x^39 + 2*x^38 + 3*x^37 + 3*x^36 + 2*x^35 + x^34 + x^33 + x^32 + x^31 + x^30 + x^29 + x^28 + x^27 + x^26 + x^25 + x^24 + x^23 + x^22 - x^20 - x^19 + x^17 + 2*x^16 + 2*x^15 + 2*x^14 + 2*x^13 + 2*x^12 + x^11 - x^9 - x^8 - x^7 - x^6 - x^5 + x^3 + 2*x^2 + 2*x + 1<br \/>\nsage: r<br \/>\n0<br \/>\n<\/code><\/p>\n<p>hat tip: <a href=\"https:\/\/ask.sagemath.org\/question\/9974\/polynomial-division-command\/\">this question<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As far as I can tell, this isn&#8217;t done purely within sage, and requires a call to maxima. If you want to divide the polynomial by to produce a quotient and remainder, the code is. a.maxima_methods().divide(b) The first element of &hellip; <a href=\"https:\/\/petermc.net\/blog\/2016\/10\/28\/single-variable-polynomial-division-in-sage\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6,8],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-maths","category-sage"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7V6a7-X","_links":{"self":[{"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":2,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":61,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions\/61"}],"wp:attachment":[{"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/petermc.net\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}