Looking for a Primitive Roots program
|
08-27-2015, 04:58 AM
Post: #1
|
|||
|
|||
Looking for a Primitive Roots program
Has anybody written an HP Prime CAS program that inputs an integer (not necessarily a prime) and outputs the complete list of its primitive roots? For example, an input of 311 should yield a list of the 120 integers which are primitive roots of 311. Info regarding "primitive roots" (a concept used in Number Theory) can be found here: http://mathworld.wolfram.com/PrimitiveRoot.html
A brute-force search algorithm would be too slow for large inputs. It is much faster to perform an intelligent search for any one primitive root, then use that one to find all the rest. For testing purposes, here are all 120 primitive roots of 311: {17 19 22 23 29 31 33 34 37 38 43 44 55 57 58 59 62 66 69 71 74 76 82 85 88 92 93 97 99 101 102 103 110 111 114 115 118 119 122 123 124 129 131 132 133 136 138 145 148 149 151 152 153 154 155 161 164 167 170 172 174 176 177 181 183 184 186 191 194 199 202 203 204 205 207 211 213 215 217 221 227 230 231 232 233 236 238 239 241 244 246 247 248 251 255 257 258 261 263 266 269 271 272 276 281 283 284 285 286 290 295 297 299 301 302 303 306 307 308 309} Thanks in advance! <0|ɸ|0> -Joe- |
|||
08-27-2015, 05:48 AM
Post: #2
|
|||
|
|||
RE: Looking for a Primitive Roots program
Look at this website for a C program then translate to Prime.
http://e-maxx-eng.github.io/algebra/primitive-root.html Colm |
|||
08-27-2015, 01:45 PM
Post: #3
|
|||
|
|||
RE: Looking for a Primitive Roots program
(08-27-2015 05:48 AM)douganc Wrote: Look at this website for a C program then translate to Prime. Thanks. Almost makes me wish I knew both C and PPL well enough to perform that translation. <0|ɸ|0> -Joe- |
|||
08-31-2015, 02:19 PM
Post: #4
|
|||
|
|||
RE: Looking for a Primitive Roots program
Below is a primitive roots program, for prime numbers only, that I was working on a while ago but had to put it aside because real work got in the way. I recall that somewhere above around 1000 it started giving incorrect answers; I'm not sure why.
Code: #cas |
|||
08-31-2015, 02:37 PM
Post: #5
|
|||
|
|||
RE: Looking for a Primitive Roots program
Below a programme for the 50G.
Stack 541 0 returns the prime & first primitive root > 0 541 2 running the programme again returns 541 10 as 10 is the next primitive root > 2 & so on. Code:
|
|||
08-31-2015, 03:29 PM
Post: #6
|
|||
|
|||
RE: Looking for a Primitive Roots program
(08-31-2015 02:19 PM)roadrunner Wrote: Wouldn't the built-in powmod function be much faster? <0|ɸ|0> -Joe- |
|||
08-31-2015, 06:02 PM
Post: #7
|
|||
|
|||
RE: Looking for a Primitive Roots program
(08-31-2015 03:29 PM)Joe Horn Wrote: Wouldn't the built-in powmod function be much faster?There's a powmod function??? Go figure. Thanks for your help Joe. I made that change and it seems to have ended the issues I was having with large values of p. Below is revision A; it seems to be working correctly with large values of p as long as the emulator doesn't run out of memory at p=20000 or so. Code: #pragma mode( separator(.,;) integer(h32)) Thanks again!! road |
|||
09-02-2015, 03:27 AM
Post: #8
|
|||
|
|||
RE: Looking for a Primitive Roots program
(08-31-2015 06:02 PM)roadrunner Wrote: Below is revision A; it seems to be working correctly with large values of p as long as the emulator doesn't run out of memory at p=20000 or so. Awesome! Many thanks! <0|ɸ|0> -Joe- |
|||
09-02-2015, 10:43 PM
Post: #9
|
|||
|
|||
RE: Looking for a Primitive Roots program
Well, as I yesterday had started to write that program as a CAS-program, I finished it today and want to give it as another example which is much shorter and needs one loop less, as it uses more of the built-in list capabilities, so it should be much faster, but I haven't checked that
Code:
Arno |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)