ffa_ch19_peh_tuni... 1 (----------------------------------------------------------------------------)
ffa_ch19_peh_tuni... 2 (----------------------------------------------------------------------------)
ffa_ch19_peh_tuni... 3 (- Demo Tape for 'Peh'; produces the largest primorial that fits in Width. -)
ffa_ch19_peh_tuni... 4 (- -)
ffa_ch19_peh_tuni... 5 (- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) -)
ffa_ch19_peh_tuni... 6 (- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -)
ffa_ch19_peh_tuni... 7 (- -)
ffa_ch19_peh_tuni... 8 (- You do not have, nor can you ever acquire the right to use, copy or -)
ffa_ch19_peh_tuni... 9 (- distribute this software ; Should you use this software for any purpose, -)
ffa_ch19_peh_tuni... 10 (- or copy and distribute it to anyone or in any manner, you are breaking -)
ffa_ch19_peh_tuni... 11 (- the laws of whatever soi-disant jurisdiction, and you promise to -)
ffa_ch19_peh_tuni... 12 (- continue doing so for the indefinite future. In any case, please -)
ffa_ch19_peh_tuni... 13 (- always : read and understand any software ; verify any PGP signatures -)
ffa_ch19_peh_tuni... 14 (- that you use - for any purpose. -)
ffa_ch19_peh_tuni... 15 (- -)
ffa_ch19_peh_tuni... 16 (- See also http://trilema.com/2015/a-new-software-licensing-paradigm . -)
ffa_ch19_peh_tuni... 17 (----------------------------------------------------------------------------)
ffa_ch19_peh_tuni... 18 (----------------------------------------------------------------------------)
ffa_ch19_peh_tuni... 19
ffa_ch19_peh_tuni... 20 (------------------------------ Main Program : ------------------------------)
ffa_ch19_peh_tuni... 21
ffa_ch19_peh_tuni... 22 ( p is the 'primorial accumulator', and q is the current 'potential prime'. )
ffa_ch19_peh_tuni... 23
ffa_ch19_peh_tuni... 24 ( p is initialized to the product of the first two primes, 2 and 3 : )
ffa_ch19_peh_tuni... 25 .6 $p
ffa_ch19_peh_tuni... 26
ffa_ch19_peh_tuni... 27 ( q is initialized to 5, i.e. the first prime that is not 2 or 3 :)
ffa_ch19_peh_tuni... 28 .5 $q
ffa_ch19_peh_tuni... 29
ffa_ch19_peh_tuni... 30 ( Begin a loop: )
ffa_ch19_peh_tuni... 31 :
ffa_ch19_peh_tuni... 32
ffa_ch19_peh_tuni... 33 ( Determine GCD(p, q) : )
ffa_ch19_peh_tuni... 34 p q G
ffa_ch19_peh_tuni... 35
ffa_ch19_peh_tuni... 36 ( If GCD(p, q) WAS equal to 1, we know that q is a new prime : )
ffa_ch19_peh_tuni... 37 .1 =
ffa_ch19_peh_tuni... 38 {
ffa_ch19_peh_tuni... 39 ( Find the product pq.
ffa_ch19_peh_tuni... 40 The UPPER FZ of this product will land on top of stack,
ffa_ch19_peh_tuni... 41 and the LOWER FZ will lie immediately under it : )
ffa_ch19_peh_tuni... 42 p q *
ffa_ch19_peh_tuni... 43
ffa_ch19_peh_tuni... 44 ( If the UPPER FZ of the product pq was NOT equal to 0...
ffa_ch19_peh_tuni... 45 ... then we have overflowed our Width, and must stop: )
ffa_ch19_peh_tuni... 46 {
ffa_ch19_peh_tuni... 47 ( Drop the LOWER FZ of the product pq, because
ffa_ch19_peh_tuni... 48 we have overflowed Width and cannot use it : )
ffa_ch19_peh_tuni... 49 _
ffa_ch19_peh_tuni... 50
ffa_ch19_peh_tuni... 51 ( Leave a 0 on the stack, to trigger termination : )
ffa_ch19_peh_tuni... 52 .0
ffa_ch19_peh_tuni... 53
ffa_ch19_peh_tuni... 54 ( At this point, we have the largest primorial
ffa_ch19_peh_tuni... 55 that can fit in our FZ Width, and we are done. )
ffa_ch19_peh_tuni... 56 }
ffa_ch19_peh_tuni... 57
ffa_ch19_peh_tuni... 58 ( If the UPPER FZ of the product pq WAS equal to 0...
ffa_ch19_peh_tuni... 59 ... then we have NOT overflowed our Width, and continue: )
ffa_ch19_peh_tuni... 60 {
ffa_ch19_peh_tuni... 61 ( Store the LOWER FZ of the product pq to p :)
ffa_ch19_peh_tuni... 62 $p
ffa_ch19_peh_tuni... 63
ffa_ch19_peh_tuni... 64 ( Leave a 1 on the stack, to trigger continuation : )
ffa_ch19_peh_tuni... 65 .1
ffa_ch19_peh_tuni... 66
ffa_ch19_peh_tuni... 67 ( At this point, pq is the primorial up to and
ffa_ch19_peh_tuni... 68 inclusive of q, and we keep going. )
ffa_ch19_peh_tuni... 69 }_
ffa_ch19_peh_tuni... 70 }
ffa_ch19_peh_tuni... 71
ffa_ch19_peh_tuni... 72 ( If GCD(p, q) WAS NOT equal to 1, we know that q is NOT a prime : )
ffa_ch19_peh_tuni... 73 {
ffa_ch19_peh_tuni... 74 ( Leave a 1 on the stack, to signal continuation : )
ffa_ch19_peh_tuni... 75 .1
ffa_ch19_peh_tuni... 76 }_
ffa_ch19_peh_tuni... 77
ffa_ch19_peh_tuni... 78
ffa_ch19_peh_tuni... 79 ( After either of the above cases, we must:
ffa_ch19_peh_tuni... 80 q := q + 2,
ffa_ch19_peh_tuni... 81 given as any possible next prime after the current q must be odd : )
ffa_ch19_peh_tuni... 82 q .2 + $q
ffa_ch19_peh_tuni... 83
ffa_ch19_peh_tuni... 84 ( If we have a 1, cycle the loop; otherwise, we have the Primorial, in p,
ffa_ch19_peh_tuni... 85 and must output it and terminate the Tape : )
ffa_ch19_peh_tuni... 86 ,
ffa_ch19_peh_tuni... 87
ffa_ch19_peh_tuni... 88 ( Emit a Peh Tape which defines the constant 'Primorial' : )
ffa_ch19_peh_tuni... 89 [@Primorial@ ( Regs : none )
ffa_ch19_peh_tuni... 90 .]
ffa_ch19_peh_tuni... 91 p#
ffa_ch19_peh_tuni... 92 [;
ffa_ch19_peh_tuni... 93 ]
ffa_ch19_peh_tuni... 94
ffa_ch19_peh_tuni... 95 ( Now, terminate with a 'Yes' Verdict, as we have succeeded : )
ffa_ch19_peh_tuni... 96 QY
ffa_ch19_peh_tuni... 97
ffa_ch19_peh_tuni... 98 (--------------------------------~~The End~~---------------------------------)