WP-34S (Prime Number Test) question



#5

I looked into how the Prime? test works, and essentially it takes
the integer part of the X register IP(X) then tests that value for
primality. If instead it took the RND(X) before doing the primality test then numbers with tiny rounding errors would still
accurately indicate the expected primality.

For example if you take the number 79 and divide it by 3 then multiply it by 3, you get a number with a tiny rounding error
in the 16th digit. On the display (even fix 11, or all 11) it appears to be 79 exactly. If you display the whole number with
(f <) it shows 78.99999999999999.

So the primality test (h test prime?) clips it down to 78 and shows false. If the RND(X) were applied to the number prior to testing for
primality, then the result will always reflect the primality of the
number shown on the display. What do you think?


Edited: 20 Oct 2013, 3:06 p.m.


#6

All numerical functions always work with the exact, unrounded argument in (usually) X. And I think it's fine this way.

Consider your example with the 78,99999999999999 that is displayed as 79 since you do not see the last four digits. Now subtract 79 from this. Should the 34s display zero? Of course it shouldn't. And that's why it shouldn't claim 78,99999999999999 is prime either, or maybe even INT(x) = 79 just because that's what you see in the display.

Dieter


#7

That is not exactly true. For instance the Even? and Odd? tests
show false for numbers like 78.1 and 79.1, although the underlying
integer 78 and 79 are Even and Odd respectively. These tests distinguish between whole numbers and fractional numbers, but the Prime number test does not, and when it converts a non-whole to an integer it does it in a way that is less representative of the displayed number than it could be. In my humble opinion.


#8

Quote:
For instance the Even? and Odd? tests show false for numbers like 78.1 and 79.1, although the underlying integer 78 and 79 are Even and Odd respectively

Yes, that's the way these functions are supposed to work. Take a look at the manual (IOP):
EVEN?    Checks if x is integer and even
ODD? Checks if x is integer and odd
Thus any non-integer will return "false" here.

Compare this with what the manual states for the PRIME? function:

PRIME?   Checks if the absolute value of the integer part of x is prime.
That's why 78,9999... tests false. The integer part of x is 78, and 78 is not prime.

So PRIME? tests if the integer part of x (!) is prime, while ODD? and EVEN? first test if x is an integer at all, and only if it is, they test if this integer is odd resp. even.

So yes, you are right: not all functions work on the full-precision value of X. Some ignore the sign and fractional part of X, such as the PRIME? function. But they do not round to the next integer either.

Dieter


Edited: 20 Oct 2013, 5:32 p.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  [WP-34S] Unfortunate key damage with update to V3 :( svisvanatha 5 434 12-10-2013, 11:37 PM
Last Post: Les Bell
  WP-34S (Emulator Program Load/Save) Barry Mead 1 242 12-09-2013, 05:29 PM
Last Post: Marcus von Cube, Germany
  DIY HP 30b WP 34s serial flash/programming cable Richard Wahl 2 357 12-04-2013, 11:14 AM
Last Post: Barry Mead
  HP Prime Matrix TERRIBLE bug and question uklo 19 923 11-25-2013, 12:10 PM
Last Post: Mic
  A fast Bernoulli Number method for the HP Prime Namir 16 783 11-22-2013, 04:46 PM
Last Post: Namir
  HP Prime - vector question bluesun08 3 221 11-18-2013, 07:26 PM
Last Post: Han
  Question about transfering programs to the HP Prime Namir 10 553 11-17-2013, 04:01 PM
Last Post: Namir
  Complex Number Entry on Prime Jeff O. 19 894 11-16-2013, 12:34 PM
Last Post: Jeff O.
  [HP Prime] Calculating Prandtl Number with Units (bug found in USIMPLIFY) Timothy Roche 1 190 11-13-2013, 04:07 PM
Last Post: cyrille de Brébisson
  HP Prime: Converting number to Sci notation and back BruceTTT 1 194 11-12-2013, 02:11 AM
Last Post: Phil Wipf

Forum Jump: