Post Reply 
WP 34S Partition of Integers Programme & a Possible OS Bug
05-08-2014, 10:53 AM
Post: #1
WP 34S Partition of Integers Programme & a Possible OS Bug
The programme PRT returns the number of integer partitions on stack level X for the input integer on stack level X; QRT similarly returns the number of partitions into distinct parts.

1 LBL 'PRT'
2 CF 01
3 SKIP 002
4 LBL 'QRT'
5 SF 01
6 DECM
7 DBLON
8 RAD
9 STO 00
10 # 024
11 1/X
12 FC? 01
13 +/-
14 +
15 STO 06
16 FS? 01
17 SKIP 011
18 √
19 1
20 .
21 5
22 1/X
23 √
24 STO 08
25 *
26 # π
27 *
28 STO 07
29 CLx
30 STO 01
31 1
32 STO 02
33 FIX 00
34 RCL 02
35 STO 03
36 CLx
37 STO 04
38 RCL 02
39 RCL 03
40 GCD
41 x≠1?
42 SKIP 033
43 RCL 02
44 x<>Y
45 -
46 x≠0?
47 SKIP 016
48 STO 05
49 CLx
50 LBL 00
51 RCL 03
52 RCL* 05
53 RCL/ 02
54 FP
55 RCL 05
56 RCL/ 02
57 # 1/2
58 STO- Z
59 -
60 *
61 +
62 DSE 05
63 GTO 00
64 4
65 1/X
66 +
67 RCL 00
68 STO+ X
69 RCL* 03
70 RCL/ 02
71 -
72 # π
73 *
74 COS
75 STO+ 04
76 DSE 03
77 BACK 039
78 FS? 01
79 SKIP 030
80 RCL 07
81 RCL/ 02
82 e^x
83 ENTER
84 ENTER
85 1/X
86 STO- Z
87 +
88 RCL* 08
89 RCL 06
90 STO/ Z
91 /
92 # π
93 *
94 RCL/ 02
95 x<>Y
96 RCL 06
97 √
98 /
99 -
100 RCL 02
101 √
102 *
103 # π
104 4
105 *
106 /
107 ENTER
108 INC 02
109 SKIP 035
110 RCL 06
111 # π
112 RCL/ 02
113 x^2
114 *
115 # 012
116 /
117 STO 03
118 CLx
119 1
120 ENTER
121 STO 05
122 ENTER
123 x<>Z
124 RCL* 03
125 RCL 05
126 STO/ Y
127 1
128 +
129 STO 05
130 /
131 STO+ Y
132 x<>Z
133 x≠? Y
134 BACK 011
135 # π
136 RCL/ 02
137 x^2
138 *
139 2
140 STO+ 02
141 6
142 *
143 /
144 STO Y
145 RCL* 04
146 RCL+ 01
147 STO 01
148 STO+ Y
149 ROUND
150 x<>Y
151 ROUND
152 x≠? Y
153 BACK 119
154 ALL 00
155 END

I attempted to replace line 63 with "BACK 012" & delete line 50 but the programme then either mis-functioned or produced wrong answers - assistance on this point would be appreciated.
All improvements welcome.
Find all posts by this user
Quote this message in a reply
05-08-2014, 11:07 AM
Post: #2
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
(05-08-2014 10:53 AM)Gerald H Wrote:  I attempted to replace line 63 with "BACK 012" & delete line 50 but the programme then either mis-functioned or produced wrong answers - assistance on this point would be appreciated.

Try single stepping the program over the BACK instruction to see where it ends up -- you can switch between program and run modes freely to help see what is going on.

Better still, don't use BACK and SKIP -- they save the instruction for the label, however they make programs far less maintainable and they don't provide a noticeable performance benefit and they make programs far less maintainable. The 34S isn't short of numeric labels.

That rant all said, I'm pretty sure BACK does function correctly. At least it has done in the past Smile


- Pauli
Find all posts by this user
Quote this message in a reply
05-08-2014, 11:22 AM
Post: #3
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
Thank you.
I would not recommend the use of BACK & SKIP in a programming language but disagree concerning performance effects. My Pollard's Rho programme takes about half the time of that required in the version using labels & GTOs.
Incidentally, all other SKIPs & BACKs the removed label fell in were adjusted to allow for the removal of one line.
Find all posts by this user
Quote this message in a reply
05-08-2014, 11:47 AM
Post: #4
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
(05-08-2014 11:22 AM)Gerald H Wrote:  I would not recommend the use of BACK & SKIP in a programming language but disagree concerning performance effects. My Pollard's Rho programme takes about half the time of that required in the version using labels & GTOs.

Such a large performance change is quite a surprise, I've never noticed much of a difference. The Pollard Rho factorisation code looks to be stack and register manipulations predominately which might explain some of this -- those are reasonably fast. The arithmetic register operations will likely be fairly slow. The *mod is specially coded and avoids the carry and overflow calculations which are surprisingly significant. The interpreter overhead is pretty large too.


What does # n do in this program?


- Pauli
Find all posts by this user
Quote this message in a reply
05-08-2014, 04:24 PM (This post was last modified: 05-08-2014 04:26 PM by Gerald H.)
Post: #5
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
It's not # n but # pi.
Find all posts by this user
Quote this message in a reply
05-08-2014, 09:52 PM
Post: #6
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
(05-08-2014 04:24 PM)Gerald H Wrote:  It's not # n but # pi.

Talk about blindness Sad

Thanks for the clarification.


Pauli
Find all posts by this user
Quote this message in a reply
05-18-2014, 04:33 PM
Post: #7
RE: WP 34S Partition of Integers Programme & a Possible OS Bug
I have now realized my error & withdraw the aspersions I cast on the OS. Here is the programme using only BACKs & SKIPs & no LBLs or GTOs:

1 LBL 'PRT'
2 CF 01
3 SKIP 002
4 LBL 'QRT'
5 SF 01
6 DECM
7 DBLON
8 RAD
9 STO 09
10 # 024
11 1/X
12 FC? 01
13 +/-
14 +
15 STO 06
16 FS? 01
17 SKIP 011
18 √
19 1
20 .
21 5
22 1/X
23 √
24 STO 08
25 *
26 # π
27 *
28 STO 07
29 CLx
30 STO 10
31 1
32 STO 02
33 FIX 00
34 RCL 02
35 STO 03
36 CLx
37 STO 04
38 RCL 02
39 RCL 03
40 GCD
41 x≠1?
42 SKIP 031
43 RCL 02
44 DEC X
45 x=0?
46 SKIP 015
47 STO 05
48 0
49 RCL 03
50 RCL* 05
51 RCL/ 02
52 FP
53 RCL 05
54 RCL/ 02
55 # 1/2
56 STO- Z
57 -
58 *
59 +
60 DSE 05
61 BACK 012
62 4
63 1/X
64 +
65 RCL 09
66 STO+ X
67 RCL* 03
68 RCL/ 02
69 -
70 # π
71 *
72 COS
73 STO+ 04
74 DSE 03
75 BACK 037
76 FS? 01
77 SKIP 030
78 RCL 07
79 RCL/ 02
80 e^x
81 ENTER
82 ENTER
83 1/X
84 STO- Z
85 +
86 RCL* 08
87 RCL 06
88 STO/ Z
89 /
90 # π
91 *
92 RCL/ 02
93 x<>Y
94 RCL 06
95 √
96 /
97 -
98 RCL 02
99 √
100 *
101 # π
102 4
103 *
104 /
105 ENTER
106 INC 02
107 SKIP 035
108 RCL 06
109 # π
110 RCL/ 02
111 x^2
112 *
113 # 012
114 /
115 STO 03
116 CLx
117 1
118 ENTER
119 STO 05
120 ENTER
121 x<>Z
122 RCL* 03
123 RCL 05
124 STO/ Y
125 1
126 +
127 STO 05
128 /
129 STO+ Y
130 x<>Z
131 x≠? Y
132 BACK 011
133 # π
134 RCL/ 02
135 x^2
136 *
137 2
138 STO+ 02
139 6
140 *
141 /
142 STO Y
143 RCL* 04
144 RCL+ 10
145 STO 10
146 STO+ Y
147 ROUND
148 x<>Y
149 ROUND
150 x≠? Y
151 BACK 117
152 ALL 00
153 END

A very nice calculator for programming. Bravo!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)