(----------------------------------------------------------------------------) (----------------------------------------------------------------------------) (- Demo Tape for 'Peh'; produces the largest primorial that fits in Width. -) (- -) (- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) -) (- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -) (- -) (- You do not have, nor can you ever acquire the right to use, copy or -) (- distribute this software ; Should you use this software for any purpose, -) (- or copy and distribute it to anyone or in any manner, you are breaking -) (- the laws of whatever soi-disant jurisdiction, and you promise to -) (- continue doing so for the indefinite future. In any case, please -) (- always : read and understand any software ; verify any PGP signatures -) (- that you use - for any purpose. -) (- -) (- See also http://trilema.com/2015/a-new-software-licensing-paradigm . -) (----------------------------------------------------------------------------) (----------------------------------------------------------------------------) (------------------------------ Main Program : ------------------------------) ( p is the 'primorial accumulator', and q is the current 'potential prime'. ) ( p is initialized to the product of the first two primes, 2 and 3 : ) .6 $p ( q is initialized to 5, i.e. the first prime that is not 2 or 3 :) .5 $q ( Begin a loop: ) : ( Determine GCD(p, q) : ) p q G ( If GCD(p, q) WAS equal to 1, we know that q is a new prime : ) .1 = { ( Find the product pq. The UPPER FZ of this product will land on top of stack, and the LOWER FZ will lie immediately under it : ) p q * ( If the UPPER FZ of the product pq was NOT equal to 0... ... then we have overflowed our Width, and must stop: ) { ( Drop the LOWER FZ of the product pq, because we have overflowed Width and cannot use it : ) _ ( Leave a 0 on the stack, to trigger termination : ) .0 ( At this point, we have the largest primorial that can fit in our FZ Width, and we are done. ) } ( If the UPPER FZ of the product pq WAS equal to 0... ... then we have NOT overflowed our Width, and continue: ) { ( Store the LOWER FZ of the product pq to p :) $p ( Leave a 1 on the stack, to trigger continuation : ) .1 ( At this point, pq is the primorial up to and inclusive of q, and we keep going. ) }_ } ( If GCD(p, q) WAS NOT equal to 1, we know that q is NOT a prime : ) { ( Leave a 1 on the stack, to signal continuation : ) .1 }_ ( After either of the above cases, we must: q := q + 2, given as any possible next prime after the current q must be odd : ) q .2 + $q ( If we have a 1, cycle the loop; otherwise, we have the Primorial, in p, and must output it and terminate the Tape : ) , ( Emit a Peh Tape which defines the constant 'Primorial' : ) [@Primorial@ ( Regs : none ) .] p# [; ] ( Now, terminate with a 'Yes' Verdict, as we have succeeded : ) QY (--------------------------------~~The End~~---------------------------------)