{"id":57429,"date":"2026-11-25T20:43:01","date_gmt":"2026-11-25T19:43:01","guid":{"rendered":"https:\/\/hooxies.nl\/?page_id=57429"},"modified":"2026-11-26T21:28:58","modified_gmt":"2026-11-26T20:28:58","slug":"pieppiex","status":"publish","type":"page","link":"https:\/\/hooxies.nl\/?page_id=57429","title":{"rendered":"PIEP+PIEX"},"content":{"rendered":"<p><b>Display<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-hp41cx.jpg\"><img decoding=\"async\" style=\"cursor:pointer; cursor:hand;width: 226px; height: 104px;\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-hp41cx.jpg\" border=\"0\" \/><\/a> <a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-dm41x.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-dm41x.jpg\" alt=\"\" width=\"173\" 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 \/>\nTwo programs calculate &pi; (pi) to N decimals with the series of Leonhard Euler (1755): <tt>PIEP<\/tt> and <tt>PIEX<\/tt>. Both store 10 decimals (two groups of 5) in every data register, like <tt>PIMP<\/tt>, but they need only one multi-precision number instead of two, so about twice as many decimals fit in the same memory. <tt>PIEP<\/tt> uses main memory only; <tt>PIEX<\/tt> also puts the part of the number that does not fit in main memory in an X-memory data file, which allows thousands of decimals. Both programs set the SIZE themselves, show the maximum number of decimals when the memory is too small, measure the calculation time with the stopwatch and show &pi; 10 decimals per line. The formulas used are:<br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;&pi; = 2 + 1\/3&middot;(2 + 2\/5&middot;(2 + 3\/7&middot;(2 + 4\/9&middot;(2 + &hellip;))))<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;&pi;\/2 = 1 + 1\/3 + 1&middot;2\/(3&middot;5) + 1&middot;2&middot;3\/(3&middot;5&middot;7) + &hellip;<\/tt><\/p>\n<p>The series is evaluated from the inside out (Horner form): starting with the deepest term, the number is multiplied by k\/(2k+1) and 2 is added, for k = K down to 1. Every term adds about one bit, so K &asymp; 3.32&middot;N terms are needed. Both programs use the built-in X-Functions (PSIZE, SIZE?) and Time functions (SETSW, RUNSW, STOPSW, RCLSW, ATIME24) of the HP-41CX and DM41X; <tt>PIEX<\/tt> also uses the X-memory functions (EMROOM, PURFL, CRFLD, SEEKPT, GETRX, SAVERX, GETX). More about the method: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Spigot_algorithm\" rel=\"noopener noreferrer\" target=\"_blank\">Spigot algorithm<\/a> (Wikipedia), <a href=\"https:\/\/mathworld.wolfram.com\/PiFormulas.html\" rel=\"noopener noreferrer\" target=\"_blank\">Pi Formulas<\/a> (Wolfram MathWorld) and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Leonhard_Euler\" rel=\"noopener noreferrer\" target=\"_blank\">Leonhard Euler<\/a> (Wikipedia).<br \/>\n&nbsp;<\/p>\n<p><b>Description<\/b><br \/>\n<tt>PIEP<\/tt> keeps one multi-precision number Y in the data registers, packed with two groups of 5 decimals per register (R = hi&middot;100&nbsp;000 + lo) as in <tt>PIMP<\/tt>. It needs n = INT((N+9)\/10)+2 registers (SIZE = n+12); the first register holds the integer part and the last one is a guard register, and N is rounded up to a multiple of 10. Y starts at 2; then for k = K down to 1 the program computes Y = 2 + k&middot;Y\/(2k+1) in one pass from left to right (LBL 03): every register is unpacked, multiplied by k and divided by 2k+1 group by group with the remainder carried to the next group, so all intermediate values stay below 10<sup>10<\/sup> and remain exact. The groups are kept in a &ldquo;balanced&rdquo; form and a small carry goes to the register on the left. A later term only influences about N &minus; 0.301&middot;k decimals, so the passes for large k stop early; this halves the run time. Finally one pass from right to left (MOD 10<sup>10<\/sup>) turns Y into normal digits, the time is shown and &pi; is displayed 10 decimals per line.<br \/>\n&nbsp;<br \/>\n<tt>PIEX<\/tt> does the same calculation, but first takes the largest SIZE that fits. The first M registers of Y stay in main memory; the rest is kept in the X-memory data file &ldquo;PIX&rdquo; (an old file is purged first and the new file stays until the next run). Each pass works through the file in blocks of 20 records: SEEKPT and GETRX read a block into a buffer, the block is calculated and SAVERX writes it back. The buffer keeps the last register of the previous block, so the carry to the left also works across block boundaries. <tt>PIEX<\/tt> needs at least SIZE 44 (R00&ndash;R21, the buffer and two registers of Y); with less main memory it shows MAX=0. The maximum number of decimals depends on the free X-memory (EMROOM); the method itself is exact up to about 9&nbsp;000 decimals, because (2k+1)&middot;100&nbsp;000 must stay below 10<sup>10<\/sup>.<br \/>\n&nbsp;<\/p>\n<p><b>Metrics<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-metrics.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-metrics.jpg\" alt=\"\" width=\"413\" height=\"111\" \/><\/a><br \/>\nAll times are estimates (&asymp;) from the number of program steps, which grows with N<sup>2<\/sup>. The V41 at top speed and maximum turbo runs about 200 program steps per second (measured with <tt>PIM<\/tt> and <tt>PIMP<\/tt>) and a real HP-41CX about 8, so the HP-41CX times are estimated as 25 times the V41 times. The Euler series needs about 3.3 terms per decimal, so <tt>PIEP<\/tt> and <tt>PIEX<\/tt> are slower than <tt>PIMP<\/tt> for the same N, but much more decimals fit in memory. The <tt>PIEX<\/tt> maximum on the V41 and DM41X assumes 600 registers of X-memory (as an HP-41CX with two Extended Memory modules); an HP-41CX without modules has 124 registers of X-memory, which gives 2900 decimals. The DM41X runs faster than the HP-41CX, but its times have not been measured yet.<br \/>\n&nbsp;<\/p>\n<p><b>Example (1)<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-examples.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-examples.jpg\" alt=\"\" width=\"413\" height=\"245\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Example (2)<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-examples.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-examples.jpg\" alt=\"\" width=\"413\" height=\"258\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing (PIEP)<\/b><br \/>\nThe listing of <tt>PIEP<\/tt> is given below. The decimals are calculated first; the time is measured with the stopwatch. Only the global label <tt>PIEP<\/tt> is used.<br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-program-6.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-program-6.jpg\" alt=\"\" width=\"413\" height=\"358\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing (PIEX)<\/b><br \/>\nThe listing of <tt>PIEX<\/tt> is given below. The decimals are calculated first; the time is measured with the stopwatch. Only the global label <tt>PIEX<\/tt> is used.<br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-program-8.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-program-8.jpg\" alt=\"\" width=\"413\" height=\"370\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags (PIEP)<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-registers.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep-registers.jpg\" alt=\"\" width=\"413\" height=\"255\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags (PIEX)<\/b><br \/>\n<a rel=\"hp-41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-registers.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piex-registers.jpg\" alt=\"\" width=\"413\" height=\"388\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Downloads<\/b><br \/>\nPDF format of programs <a rel=\"41cx_piep\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep.pdf\">PIEP+PIEX<\/a>.<br \/>\nRAW\/TXT format of programs <a href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/piep.zip\">PIEP+PIEX<\/a> (in zip file).<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; 2006-2026 by Auke Hoekstra<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display (HP-41CX, Hewlett Packard 1983 and DM41X, SwissMicros 2020) &nbsp; Overview Two programs calculate &pi; (pi) to N decimals with the series of Leonhard Euler (1755): PIEP and PIEX. Both store 10 decimals (two groups of 5) in every data register, like PIMP, but they need only one multi-precision number instead of two, so about [&hellip;]<\/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-57429","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57429","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=57429"}],"version-history":[{"count":3,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57429\/revisions"}],"predecessor-version":[{"id":57595,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57429\/revisions\/57595"}],"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=57429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}