HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge

09272017, 07:33 AM
Post: #1




HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
In this thread
http://www.hpmuseum.org/forum/thread9156.html Joe Horn reminds us of the NEIGHBOR function for the HP 71B. I have a 270.5 Byte programme which for real input returns both the upper & lower neighbours of input on the 50g. Can anyone produce a shorter programme? 

09272017, 07:39 AM
(This post was last modified: 09272017 07:40 AM by Joe Horn.)
Post: #2




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
I'd LOVE to see your program. For years I've been living with this atrocity called NABR. It adds X ULPS onto Y. Example: 5 ENTER 2 NABR > 5.00000000002
<< SWAP DUP XPON SWAP MANT .00000000001 4. ROLL * + SWAP ALOG * >> Fails when Y=0, and gets the wrong answer for 1 ENTER 1 NABR. <0ɸ0> Joe 

09272017, 07:49 AM
(This post was last modified: 09272017 07:51 AM by Gerald H.)
Post: #3




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 07:39 AM)Joe Horn Wrote: I'd LOVE to see your program. For years I've been living with this atrocity called NABR. It adds X ULPS onto Y. Example: 5 ENTER 2 NABR > 5.00000000002 Doesn't work. Edit: Does work. 

09272017, 07:50 AM
Post: #4




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Sorry, works.


09272017, 07:52 AM
Post: #5




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 07:39 AM)Joe Horn Wrote: I'd LOVE to see your program. For years I've been living with this atrocity called NABR. It adds X ULPS onto Y. Example: 5 ENTER 2 NABR > 5.00000000002 Very nice, could be the basis of an answer to my post. 

09272017, 08:06 AM
Post: #6




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 07:52 AM)Gerald H Wrote: Very nice, could be the basis of an answer to my post. After struggling with this, I gave up on it years ago. Please share your program. I'd love to see how you did it! Or is this a kind of minichallenge? If so, I can't wait to see what folks here come up with! <0ɸ0> Joe 

09272017, 09:12 AM
Post: #7




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Yes, I would very much appreciate contributions in the way of programmes or algorithms.
Your programme fails for input 5 3 & will have to grow to accommodate negative reals. I will certainly timely publish my programme but do not expect it to be the shortest. 

09272017, 10:43 AM
(This post was last modified: 09272017 11:25 AM by Werner.)
Post: #8




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
I created this when Joe first mentioned the NEIGHBOR function.
It returns the next number larger than x=s*m*10^n Basically, if x=0, return 1e499 elsif s*m=1, return (s.m + 1e12)*10^n else return (s.m + 1e11)*10^n Code: \<< If I call this program NXT, then NEIGHBOR as defined in the 71 would be Code: \<< IF OVER < THEN +/ NXT +/ ELSE NXT END \>> 

09272017, 11:22 AM
(This post was last modified: 09272017 11:23 AM by pier4r.)
Post: #9




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Nice input Gerald and Joe!
I have a question though. From the other thread Quote:NEIGHBOR(X,Y) [nearest machinerepresentable number to X in the direction of Y] Wouldn't be Y representable by the system already? My doubt lies on the point that that the value given to the function is already a valid value for the system, so there is nothing to search. Would be different with a string in input rather than a number. Wikis are great, Contribute :) 

09272017, 11:51 AM
Post: #10




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 11:22 AM)pier4r Wrote: I have a question though. From the other thread Sorry, but I don't understand your question. The only thing that Y does is tell NEIGHBOR which direction to go. If Y>X, then NEIGHBOR(X,Y) returns the very next number GREATER than X which the HP71 is capable of representing, and if Y<X then it returns the very next number LESS than X. The phrase "machinerepresentable number" means "limited to a 12digit mantissa". The function has nothing to do with strings. Examples: NEIGHBOR(6,9) > 6.00000000001 (the nearest machinerepresentable number above 6) NEIGHBOR(6,2) > 5.99999999999 (the nearest machinerepresentable number below 6) <0ɸ0> Joe 

09272017, 11:53 AM
(This post was last modified: 09282017 05:36 AM by Gerald H.)
Post: #11




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Bravo Werner! I consider your contribution a complete solution & don't expect a shorter version (although "6  6 " is ornate), would however be very pleased to see a more concise programme.
To keep my word & amuse Joe here's my version: Edit: Corrected my programme to give correct result for zero. I have learned much from this thread, eg that .000000000001 is not the nearest representable number to zero. I doubt that, given Werner's programme, anyone will now try this programme but the wrong result irritated me. Code: :: Which does have the advantage of giving no wrong answers, ie for input 9.99999999999E499 1 Joe's returns 9.99999999999E499 & for 9.99999999999E499 9.99999999999E499 Werner's returns 9.99999999999E499 while for 9.99999999999E499 my programme errors. 

09272017, 11:53 AM
Post: #12




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
I can't believe the 50G doesn't have this function.
I'm confident it is present internally somewhere. Pauli 

09272017, 12:24 PM
Post: #13




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Joe: what does NEIGHBOR return if X=Y?
Gerald: (09272017 11:53 AM)Gerald H Wrote: for No, it errors out, as (for now) it considers it has to go up to the next number. I guess your overflow flag is cleared, then it returns 9.99999999999e499 I'd say when X=Y the number should be returned unchanged, so: Code: \<< 

09272017, 01:01 PM
Post: #14




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 12:24 PM)Werner Wrote: Joe: what does NEIGHBOR return if X=Y? Some interesting inputs & outputs on HP71: NEIGHBOR(7,7) > 7 NEIGHBOR(0,0) > 0 NEIGHBOR(0,7) > 0.00000000001E499 = MINREAL (nonnormalized) NEIGHBOR(1,0) > 0.999999999999 (twelve 9's, not just eleven like my buggy program above) <0ɸ0> Joe 

09272017, 01:04 PM
Post: #15




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Thanks, Joe
My program above returns correct results for all of these. The 1e499 is normalized, though ;) Werner 

09272017, 01:40 PM
(This post was last modified: 09272017 01:41 PM by pier4r.)
Post: #16




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
(09272017 11:51 AM)Joe Horn Wrote: Sorry, but I don't understand your question. The only thing that Y does is tell NEIGHBOR which direction to go. If Y>X, then NEIGHBOR(X,Y) returns the very next number GREATER than X which the HP71 is capable of representing, and if Y<X then it returns the very next number LESS than X. The phrase "machinerepresentable number" means "limited to a 12digit mantissa". The function has nothing to do with strings. Ah, ok, then I misunderstood. I thought the right function was like 'Y' is not representable by the system, can you give the closer number to Y, starting from X, that can represent Y? Wikis are great, Contribute :) 

09272017, 03:12 PM
(This post was last modified: 09272017 03:13 PM by David Hayden.)
Post: #17




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Slow and simple, but it works. This just keeps adding or subtracting 10^n for successively larger values of n until X+10^n changes.
Code: @ NEIGHBOR 

09272017, 03:39 PM
Post: #18




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Well done, David.
Gives wrong answer for input 1.E499 6 returns 2.E499 should be 1.00000000001E499 

09282017, 10:15 AM
Post: #19




RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Many thanks for the contributions, I'm very pleased with the resulting programmes.
Please see http://www.hpmuseum.org/forum/thread9180.html which will assist students greatly (I hope). 

« Next Oldest  Next Newest »

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