{"id":28727,"date":"2020-10-11T20:59:10","date_gmt":"2020-10-11T18:59:10","guid":{"rendered":"https:\/\/hooxies.nl\/?page_id=28727"},"modified":"2026-11-25T21:07:24","modified_gmt":"2026-11-25T20:07:24","slug":"crt","status":"publish","type":"page","link":"https:\/\/hooxies.nl\/?page_id=28727","title":{"rendered":"CRT"},"content":{"rendered":"<p><b>Display<\/b><br \/>\n<a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-hp41cx.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-hp41cx.png\" alt=\"\" width=\"226\" height=\"104\" \/><\/a> <a rel=\"hp41cxcrt\" href=\"href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/crt-dm41x.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/crt-dm41x.png\" alt=\"\" width=\"174\" height=\"104\" \/><\/a><br \/>\n<em>(HP-41CX, Hewlett Packard 1983 and DM41X, <a href=\"https:\/\/www.swissmicros.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">SwissMicros<\/a> 2020)<\/em><br \/>\n&nbsp;<\/p>\n<p><b>Overview<\/b><br \/>\nThe <tt>CRT<\/tt> program represents a solution to the Chinese Remainder Theorem which <em>states that a linear system of congruence equations with pairwise relatively prime moduli has a unique solution modulo the product of the moduli of the system<\/em>.<br \/>\nPractically, it goes like this. Imagine a basket of eggs for which it is not known how many there are. Too lazy to count all of them one may know that if you take out three at a time, it ends up with two left-over. If one takes out five at a time, three are left-over, and by taking out seven at a time, two are left-over. This is enough information to figure out the least number of eggs that are in the basket. Here we go.<\/p>\n<p>The basis for finding a solution for an integer number X which satisfies the congruences of modulo definitions as explained below.<br \/>\nSuppose that <tt><b>m<\/b><sub>1<\/sub>, <b>m<\/b><sub>2<\/sub>,..,<b>m<\/b><sub>k<\/sub><\/tt> are pairwise relatively prime positive integers, and <tt><b>a<\/b><sub>1<\/sub>, <b>a<\/b><sub>2<\/sub>,..,<b>a<\/b><sub>k<\/sub><\/tt> a series of integers, congruences exist as follows:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> &equiv; <b>a<\/b><sub>i<\/sub> (mod <b>m<\/b><sub>i<\/sub>)&nbsp;&nbsp;<\/tt> for <tt>i=1..k<\/tt> and have a unique solution: <\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>M<\/b> = <b>m<\/b><sub>1<\/sub>&middot;<b>m<\/b><sub>2<\/sub>&middot;..&middot;<b>m<\/b><sub>k<\/sub>&nbsp;&nbsp;<\/tt> which is given by:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> &equiv; <b>a<\/b><sub>1<\/sub><b>M<\/b><sub>1<\/sub><b>y<\/b><sub>1<\/sub> + <b>a<\/b><sub>2<\/sub><b>M<\/b><sub>2<\/sub><b>y<\/b><sub>2<\/sub> + .. + <b>a<\/b><sub>k<\/sub><b>M<\/b><sub>k<\/sub><b>y<\/b><sub>k<\/sub> (mod <b>M<\/b>)&nbsp;&nbsp;&nbsp;<\/tt> with: <\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>M<\/b><sub>i<\/sub> = <b>M<\/b>\/<b>m<\/b><sub>i<\/sub>&nbsp;&nbsp;&nbsp;<\/tt> and <tt>&nbsp;&nbsp;&nbsp;<b>y<\/b><sub>i<\/sub> &equiv; 1\/<b>M<\/b><sub>i<\/sub> (mod <b>m<\/b><sub>i<\/sub>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/tt> for <tt>i=1..k<\/tt><\/p>\n<p>The values &nbsp;&nbsp;<tt><b>y<\/b><sub>i<\/sub>&nbsp;<\/tt> can be found by applying the Extended Euclidean Algorithm.<br \/>\n<br \/>\n&nbsp;<\/p>\n<p><b>Example 1<\/b><br \/>Please note that my default <tt>FIX 5<\/tt> setting which can be replaced by your preferred number of decimals at line 178. An example are the following three congruences:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> &equiv; <b>2<\/b> (mod <b>3<\/b>)<\/tt><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> &equiv; <b>3<\/b> (mod <b>5<\/b>)<\/tt><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> &equiv; <b>2<\/b> (mod <b>7<\/b>)<\/tt><\/p>\n<p>in which <tt><b>M<\/b>=LCM(3,5,7)=105<\/tt> and the value of <tt><b>x<\/b><\/tt> is to be determined.<\/p>\n<p><a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-example1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-example1.png\" alt=\"\" width=\"413\" height=\"372\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Example 2<\/b><br \/>Please note that my default <tt>FIX 5<\/tt> setting which can be replaced by your preferred number of decimals at line 179. An example are the following three congruences:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> = <b> 5<\/b> (mod <b> 7<\/b>)<\/tt><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> = <b> 7<\/b> (mod <b>11<\/b>)<\/tt><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> = <b>14<\/b> (mod <b>31<\/b>)<\/tt><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt><b>x<\/b> = <b> 8<\/b> (mod <b>45<\/b>)<\/tt><\/p>\n<p>in which <tt><b>M<\/b>=LCM(7,11,31,45)=107415<\/tt> and the value of <tt><b>x<\/b><\/tt> is to be determined.<\/p>\n<p><a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-example2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-example2.png\" alt=\"\" width=\"413\" height=\"556\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing<\/b><br \/>\nThe listing of CRT is given below with functions A-E in User Mode.<br \/>\n<a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-program.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-program.png\" alt=\"\" width=\"413\" height=\"556\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags<\/b><br \/>\n<a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-registers.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt-registers.png\" alt=\"\" width=\"413\" height=\"351\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Downloads<\/b><br \/>\nPDF format of program <a rel=\"hp41cxcrt\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2023\/02\/crt.pdf\">CRT<\/a>.<br \/>\nRAW\/TXT format of program <a href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2020\/10\/crt.zip\">CRT<\/a> (in zip file).<br \/>\n&nbsp;<\/p>\n<p><b>References<\/b><br \/>\nMathematical article: <a href=\"http:\/\/www-math.ucdenver.edu\/~wcherowi\/courses\/m5410\/ctccrt.html\" target=\"_blank\" rel=\"noopener noreferrer\">Chinese Remainder Theorem by University of Colorado Denver<\/a>.<br \/>\nInteractive math website: <a href=\"https:\/\/www.cut-the-knot.org\/blue\/chinese.shtml\" target=\"_blank\" rel=\"noopener noreferrer\">Chinese Remainder Theorem by <em>Cut the Knot<\/em><\/a>.<br \/>\n&nbsp;<\/p>\n<div style=\"font-size: 12px;\">This program is copyright and is supplied without representation or warranty of any kind. The author assumes no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof<\/div>\n<p><i>&copy; 1999-2020 by Auke Hoekstra<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-28727","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/28727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28727"}],"version-history":[{"count":1,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/28727\/revisions"}],"predecessor-version":[{"id":57395,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/28727\/revisions\/57395"}],"up":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}