Post Reply 
Prime Factors in the ALPHA REG.
12-05-2015, 09:19 AM
Post: #1
Prime Factors in the ALPHA REG.
Hi,

I am think have found what I was wanted to find, that it is :

To see in first line of display : PRIME FACTORS in good mathematic presentation
TO see in 2nd line of display : The integer wich is PRIME FACTORED.

I reach do this this night, but it is not runing well as far.
If I reach good I will put in forum.

I put a result in attachement.

Gérard.
Find all posts by this user
Quote this message in a reply
12-05-2015, 12:46 PM (This post was last modified: 12-05-2015 12:48 PM by ggauny@live.fr.)
Post: #2
RE: Prime Factors in the ALPHA REG.
Hi,

The difficulty is to translate the codes to input in ALPHA REGISTER. A way to do this is go in base HEX, for instance the exponant sign is 5E in the array of code characters in manual, 2 is 32 in array which is HEXA, SPACE is 06 in the array, so I go HEXA I put the code hexa of what I want, for example :

2^2[space]

I do 32 x->a 5e x->a 32 x->a, it is "2^2" in alpha register.
Of course I have made a routine for translate what I need ! numbers 2 to 9 (it is sufficient I think), and ^, ., SPACE, after I display alpha register and I have my result.

Gérard.
Find all posts by this user
Quote this message in a reply
12-08-2015, 09:23 PM (This post was last modified: 12-09-2015 12:49 PM by Dieter.)
Post: #3
RE: Prime Factors in the ALPHA REG.
(12-05-2015 12:46 PM)ggauny@live.fr Wrote:  The difficulty is to translate the codes to input in ALPHA REGISTER.

Why should one want to do this?
Codes? Why do you want to use codes ?-)

(12-05-2015 12:46 PM)ggauny@live.fr Wrote:  A way to do this is go in base HEX, for instance the exponant sign is 5E in the array of code characters in manual, 2 is 32 in array which is HEXA, SPACE is 06 in the array, so I go HEXA I put the code hexa of what I want, for example :

2^2[space]

I do 32 x->a 5e x->a 32 x->a, it is "2^2" in alpha register.
Of course I have made a routine for translate what I need ! numbers 2 to 9 (it is sufficient I think), and ^, ., SPACE, after I display alpha register and I have my result.

Maybe I do not understand why you want to use such a complicated method. But why don't you just directly append the characters and numbers you want? Let's assume the factor is in register 1 and the exponent in register 2, why don't you simply do it this way:

Code:
αIP 01
"^"
αIP 02

Remember: unlike the HP41, there is no "append" character on the 34s. Every alpha entry is automatically appended to the existing alpha string. So you always have to use CLα if you want to start a new alpha string.

The exponent character "^" is in the alpha calatog at [f] [→], a space is [h] [0] (=PSE) and a multiplication symbol is also available at [f] [x]. However, I did not find a centered dot like "·". Walter?

Anyway, the 34s alpha display is of not much use here as the number of displayed characters is very limited. Unlike the HP41, the display does not scroll.

Dieter
Find all posts by this user
Quote this message in a reply
12-09-2015, 07:22 AM
Post: #4
RE: Prime Factors in the ALPHA REG.
(12-08-2015 09:23 PM)Dieter Wrote:  However, I did not find a centered dot like "·". Walter?

There is no center dot provided on the WP 34S - there will be one on the WP 43S.

d:-)
Find all posts by this user
Quote this message in a reply
12-09-2015, 01:05 PM (This post was last modified: 12-09-2015 01:33 PM by Dieter.)
Post: #5
RE: Prime Factors in the ALPHA REG.
(12-08-2015 09:23 PM)Dieter Wrote:  Anyway, the 34s alpha display is of not much use here as the number of displayed characters is very limited. Unlike the HP41, the display does not scroll.

Output on a single line may be shortened by using the ² and ³ characters. Which can be done in a dedicated output routine. But even this way results with more than 10 or 11 characters can not be displayed – everything beyond that simply is not shown. This may be solved by removing the first characters until the output line does not exceed this limit:

Code:
αLENG
#010
-
x>0?
αSL→X

A more sophisticated version may remove the first characters until it comes across a "×":

Code:
  2^5×5^3×7
→ …5^3×7×41

These problems with single-line output are the reason why I prefer the following method:

Code:
492000 XEQ"PRF"
                2^5
       [R/S]    ×3
       [R/S]    ×5^3
       [R/S]    ×41

Simple and straightforward. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
12-09-2015, 02:33 PM
Post: #6
RE: Prime Factors in the ALPHA REG.
(12-09-2015 01:05 PM)Dieter Wrote:  Simple and straightforward. ;-)
But what if the number itself is a prime with more than 11 digits, e.g. 100000000003?
You can't completely show it in the alpha display, so if you really want to get prime factor with their exponent, then I guess the only way would be to display the prime factor in X and then exponent in alpha.

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-09-2015, 06:29 PM
Post: #7
RE: Prime Factors in the ALPHA REG.
(12-09-2015 02:33 PM)fhub Wrote:  But what if (...)
You can't (...)

Yes, you can't. Choose any method, and there will be a limit where it doesn't work.
One more reason to return the prime factors one at a time (via R/S).
Or use a printer.

Apropos: the 34s seems to behave differenlty compared to the 41-series (and maybe also the 42s) in that the VIEW commands (including AVIEW resp. VIEWα and VWα+) do not print, so that a separate print command is required if output should also appear on the printer. The [printer]? test command does not help much here as it does not test whether a printer is connected and ready or not. There is no equivalent to the 41/42 flags 21 and 55. Maybe all this can be improved in, err... "future projects". ;-)

Dieter
Find all posts by this user
Quote this message in a reply
12-09-2015, 06:32 PM (This post was last modified: 12-09-2015 06:33 PM by fhub.)
Post: #8
RE: Prime Factors in the ALPHA REG.
(12-09-2015 06:29 PM)Dieter Wrote:  Yes, you can't. Choose any method, and there will be a limit where it doesn't work.
One more reason to return the prime factors one at a time (via R/S).
Yes, here's the way I would do it (separated primefactors in X and exponents in alpha), thus no limit to 11 digits -
it's just a modification of my old 'PF' in the WP34s library:
Code:

/*
  Prime Factorization:  list of 'true' prime factors (1<pf<n)

  Input:  X:n (positive integer)
  Output: X:pf1 (primefactor1) Alpha:^ex1 (exponent1)
   [R/S]  X:pf2 (primefactor2) Alpha:^ex2 (exponent2)
   [R/S]  .....
   [R/S]  n
  Used:   XYZT
*/

0001 LBL'PF'
0002 LocR 004
0003 INT?
0004 x<1?
0005 RTN
0006 STO .00
0007 2
0008 RCL Y
0009 [sqrt]
0010 IP
0011 STO .03
0012 DROP
0013 x>? .03
0014 SKIP 013
0015 [cmplx]ENTER
0016 MOD
0017 x=0?
0018 SKIP 005
0019 DROP
0020 INC X
0021 EVEN?
0022 INC X
0023 BACK 010
0024 DROP
0025 XEQ 00
0026 STO/ Y
0027 BACK 019
0028 DROP
0029 XEQ 00
0030 CLSTK
0031 RCL .00
0032 LBL 00
0033 x[!=]? .01
0034 SKIP 002
0035 INC .02
0036 SKIP 011
0037 # 001
0038 RCL Y
0039 [cmplx]x[<->] .01
0040 x=0?
0041 SKIP 005
0042 CL[alpha]
0043 [alpha] ^
0044 [alpha]IP Y
0045 PROMPT
0046 CL[alpha]
0047 [cmplx]DROP
0048 END

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-09-2015, 07:33 PM
Post: #9
RE: Prime Factors in the ALPHA REG.
(12-09-2015 06:29 PM)Dieter Wrote:  The [printer]? test command does not help much here as it does not test whether a printer is connected and ready or not. There is no equivalent to the 41/42 flags 21 and 55. Maybe all this can be improved in, err... "future projects". ;-)

Sorry, but the IR printer cannot talk back to the calculator so there is no chance to check if the printer is ready. The [printer]? test command just tells whether the correct firmware for printing is installed.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
12-09-2015, 08:10 PM
Post: #10
RE: Prime Factors in the ALPHA REG.
Please allow me to quote the entry for ⎙? in the IOP of the manual:
Quote:Tests if a quartz crystal and the necessary firmware are installed for printing. I.e. ⎙? will return true if XTAL? returns true and calc_ir.bin (or calc_ir_full.bin) is loaded. The IR diode must be checked visually.
HTH

d:-)
Find all posts by this user
Quote this message in a reply
12-09-2015, 09:33 PM
Post: #11
RE: Prime Factors in the ALPHA REG.
(12-09-2015 08:10 PM)walter b Wrote:  Please allow me to quote the entry for ⎙? in the IOP of the manual:

Walter, I know very well what the [printer]? test does – and what it doesn't. That's exactly my point:
There is no way of checking whether a printer is connected and ready or not.

Dieter
Find all posts by this user
Quote this message in a reply
12-10-2015, 07:48 AM
Post: #12
RE: Prime Factors in the ALPHA REG.
Fine. We can agree on that.

d:-)
Find all posts by this user
Quote this message in a reply
12-10-2015, 11:06 AM
Post: #13
RE: Prime Factors in the ALPHA REG.
(12-09-2015 09:33 PM)Dieter Wrote:  There is no way of checking whether a printer is connected and ready or not.

And we have no chance to change that without different printer hardware.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
12-10-2015, 05:24 PM (This post was last modified: 12-10-2015 05:40 PM by Dieter.)
Post: #14
RE: Prime Factors in the ALPHA REG.
(12-09-2015 06:32 PM)fhub Wrote:  Yes, here's the way I would do it (separated primefactors in X and exponents in alpha), thus no limit to 11 digits -

Right, now the limit is at 12 digits.

OK, unless you use the functions to view all mantissa digits.
But if this is allowed you can just as well view the complete alpha string. ;-)

BTW, is there a special reason why in this thread noone ever mentioned the NEXTP function to obtain the next divisor? Instead the programs simply test all odd divisors. #-)

I have modified your program accordingly, and it still works fine. Just a bit faster.

Dieter
Find all posts by this user
Quote this message in a reply
12-10-2015, 05:35 PM
Post: #15
RE: Prime Factors in the ALPHA REG.
(12-10-2015 11:06 AM)Marcus von Cube Wrote:  
(12-09-2015 09:33 PM)Dieter Wrote:  There is no way of checking whether a printer is connected and ready or not.

And we have no chance to change that without different printer hardware.

Yes, I see the hardware limits.

Do you see any chance to overcome this problem, e.g. for the 43s project?
Is there a way to connect a different kind of printer?

Dieter
Find all posts by this user
Quote this message in a reply
12-10-2015, 05:43 PM
Post: #16
RE: Prime Factors in the ALPHA REG.
(12-10-2015 05:24 PM)Dieter Wrote:  BTW, is there a special reason why in this thread noone ever mentioned the NEXTP function to obtain the next divisor? Instead the programs simply test all odd divisors. #-)

I have modified your program accordingly, and it still works fine. Just a bit faster.
I remember that long time ago a member here mentioned, that NEXTP (which is still in my original version in the WP34s library) would be MUCH slower (on a real calc) than simply using INC, so I've changed this for the current version.
It's strange that you state it would be faster!?

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-10-2015, 06:12 PM
Post: #17
RE: Prime Factors in the ALPHA REG.
(12-10-2015 05:35 PM)Dieter Wrote:  Do you see any chance to overcome this problem, e.g. for the 43s project?
Is there a way to connect a different kind of printer?

I don't know if the new hardware will support Bluetooth or USB OTG. If not, I don't see a chance.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
12-10-2015, 06:25 PM
Post: #18
RE: Prime Factors in the ALPHA REG.
(12-10-2015 05:43 PM)fhub Wrote:  
(12-10-2015 05:24 PM)Dieter Wrote:  BTW, is there a special reason why in this thread noone ever mentioned the NEXTP function to obtain the next divisor? Instead the programs simply test all odd divisors. #-)

I have modified your program accordingly, and it still works fine. Just a bit faster.
I remember that long time ago a member here mentioned, that NEXTP (which is still in my original version in the WP34s library) would be MUCH slower (on a real calc) than simply using INC, so I've changed this for the current version.
It's strange that you state it would be faster!?

Ok, I've now checked both versions with the emulator, I've used the biggest 12-digit primenumber 999999999989:
the new version (with INC X, EVEN?, INC X) needs about 5 secs and the old version (with NEXTP) needs about 50 secs, i.e. it is 10-times slower!
(I don't think this would be much different on a real WP34s)

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-10-2015, 06:45 PM (This post was last modified: 12-10-2015 06:46 PM by Dieter.)
Post: #19
RE: Prime Factors in the ALPHA REG.
(12-10-2015 06:25 PM)fhub Wrote:  Ok, I've now checked both versions with the emulator,

I did so with some moderate 5...8-digit primes on "real hardware".
But the results are comparable:

Indeed the simple INC method is much faster than NEXTP. For instance factoring 1234577 (=1x1234577 ;-)) takes about 15 vs. less than 2 seconds. I don't know how I got to my previous conclusion that NEXTP was faster – sorry, my fault.

Dieter
Find all posts by this user
Quote this message in a reply
12-18-2015, 02:03 PM
Post: #20
RE: Prime Factors in the ALPHA REG.
(12-08-2015 09:23 PM)Dieter Wrote:  
(12-05-2015 12:46 PM)ggauny@live.fr Wrote:  The difficulty is to translate the codes to input in ALPHA REGISTER.

Why should one want to do this?
Codes? Why do you want to use codes ?-)

(12-05-2015 12:46 PM)ggauny@live.fr Wrote:  A way to do this is go in base HEX, for instance the exponant sign is 5E in the array of code characters in manual, 2 is 32 in array which is HEXA, SPACE is 06 in the array, so I go HEXA I put the code hexa of what I want, for example :

2^2[space]

I do 32 x->a 5e x->a 32 x->a, it is "2^2" in alpha register.
Of course I have made a routine for translate what I need ! numbers 2 to 9 (it is sufficient I think), and ^, ., SPACE, after I display alpha register and I have my result.

Maybe I do not understand why you want to use such a complicated method. But why don't you just directly append the characters and numbers you want? Let's assume the factor is in register 1 and the exponent in register 2, why don't you simply do it this way:

Code:
αIP 01
"^"
αIP 02

Remember: unlike the HP41, there is no "append" character on the 34s. Every alpha entry is automatically appended to the existing alpha string. So you always have to use CLα if you want to start a new alpha string.

The exponent character "^" is in the alpha calatog at [f] [→], a space is [h] [0] (=PSE) and a multiplication symbol is also available at [f] [x]. However, I did not find a centered dot like "·". Walter?

Anyway, the 34s alpha display is of not much use here as the number of displayed characters is very limited. Unlike the HP41, the display does not scroll.

Dieter

Hi Dieter my friend,
Now at home I am able to reply, I have do this because Walter in manual say, characters are in internal codes, so of course it is complicated and health stoped my research. I had look "append" but I know it is not.

At hospital, I have programed all codes for characters, but you seem saying it is not usefull.

I am happy to retrieved you all !

Gérard.
Find all posts by this user
Quote this message in a reply
Post Reply 




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