Post Reply 
newRPL - Wiki examples for PEEK, POKE and NEWOB commands
09-21-2021, 09:09 PM
Post: #1
newRPL - Wiki examples for PEEK, POKE and NEWOB commands
I'm adding a batch of commands to the wiki and I'd like to include meaningful examples when the command is obscure and rarely used.

PEEK, POKE and NEWOB fall into the description, and I can't come with an example that satisfies me: I could show how PEEK and POKE work on some random memory location, but is there some special address that I could use?

NEWOB is even worse in this respect: the HP50G AUR suggested an example, but the presence of 8 levels of UNDO stack make it not very didactically interesting...

I'm out of ideas, do you have any?
Find all posts by this user
Quote this message in a reply
09-22-2021, 12:31 AM
Post: #2
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-21-2021 09:09 PM)JoJo1973 Wrote:  I'm adding a batch of commands to the wiki and I'd like to include meaningful examples when the command is obscure and rarely used.

PEEK, POKE and NEWOB fall into the description, and I can't come with an example that satisfies me: I could show how PEEK and POKE work on some random memory location, but is there some special address that I could use?

NEWOB is even worse in this respect: the HP50G AUR suggested an example, but the presence of 8 levels of UNDO stack make it not very didactically interesting...

I'm out of ideas, do you have any?

PEEK and POKE are low-level commands, can only be used by "certain people" with "certain knowledge". It's OK if there's no examples, they simply read or write a 32-bit word at a word-aligned ARM address. They aren't meant for the general public, but mainly to aid the developers on hardware debugging. Using "some random address" you will either cause a crash (data abort exception), or corrupt your precious data.

NEWOB is exactly the same as the HP48 command NEWOB. There's one very important use for this command:
Let's say you have a list of 1000 numbers. Using GET to put one of the objects on the stack will place a pointer to the object that's *within the list* on the stack. And for as long as you keep that one number around, you'll keep the entire list eating out your memory.
You can simply use NEWOB after GET to create a stand-alone copy of the number, and the list will be gone in the next garbage collection.
It's an obscure command used by memory-intensive applications.
Another use is for self-modifying objects. On the hp48/49/50 you could modify an object from assembler, so you could create a new copy first, then change it rather than allocating new memory and creating the object from scratch. None of that can happen in newRPL so this use case is not valid.
Find all posts by this user
Quote this message in a reply
09-22-2021, 07:17 AM
Post: #3
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-22-2021 12:31 AM)Claudio L. Wrote:  PEEK and POKE are low-level commands, can only be used by "certain people" with "certain knowledge". It's OK if there's no examples, they simply read or write a 32-bit word at a word-aligned ARM address. They aren't meant for the general public, but mainly to aid the developers on hardware debugging. Using "some random address" you will either cause a crash (data abort exception), or corrupt your precious data.

I'll add a big caveat in the usage section then. Wink

(09-22-2021 12:31 AM)Claudio L. Wrote:  NEWOB is exactly the same as the HP48 command NEWOB. There's one very important use for this command:
Let's say you have a list of 1000 numbers. Using GET to put one of the objects on the stack will place a pointer to the object that's *within the list* on the stack. And for as long as you keep that one number around, you'll keep the entire list eating out your memory.
You can simply use NEWOB after GET to create a stand-alone copy of the number, and the list will be gone in the next garbage collection.
It's an obscure command used by memory-intensive applications.

That's the example from the AUR that I had in mind: I wanted to document this behavior showing how the used memory can be reclaimed after NEWOB is launched, but I suppose that the 1000-items list living in the undo stack hides the effect of the command.

Is there a way to clear or disable the undo stack? If not, I'll stick with a simple description of the process.

Thanks for the insight!
Find all posts by this user
Quote this message in a reply
09-22-2021, 09:01 AM
Post: #4
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-21-2021 09:09 PM)JoJo1973 Wrote:  PEEK, POKE and NEWOB fall into the description, and I can't come with an example that satisfies me: I could show how PEEK and POKE work on some random memory location, but is there some special address that I could use?

I don't know if this is even possible, but: can be poke used to toggle a pixel on the screen?
A satisfying example could be a small program that uses peek and poke to simulate the pixon/pixoff instructions.

GianLuca
Visit this user's website Find all posts by this user
Quote this message in a reply
09-22-2021, 11:12 PM
Post: #5
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-22-2021 12:31 AM)Claudio L. Wrote:  PEEK and POKE are low-level commands, can only be used by "certain people" with "certain knowledge". It's OK if there's no examples, they simply read or write a 32-bit word at a word-aligned ARM address. They aren't meant for the general public, but mainly to aid the developers on hardware debugging. Using "some random address" you will either cause a crash (data abort exception), or corrupt your precious data.

There's something I don't understand. When you say 32-bit words at word-aligned ARM addresses you mean that e.g. 0 PEEK should read 4 bytes starting at address 0 and 1 PEEK should read 4 bytes starting at address 4 and so on, right?

Because if I've understood the code (big if Wink ), the address should be ANDed with 0xfffffffc, not 0xffffffff, and the same applies for POKE.
Find all posts by this user
Quote this message in a reply
09-22-2021, 11:17 PM
Post: #6
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-22-2021 09:01 AM)gianluca Wrote:  
(09-21-2021 09:09 PM)JoJo1973 Wrote:  PEEK, POKE and NEWOB fall into the description, and I can't come with an example that satisfies me: I could show how PEEK and POKE work on some random memory location, but is there some special address that I could use?

I don't know if this is even possible, but: can be poke used to toggle a pixel on the screen?
A satisfying example could be a small program that uses peek and poke to simulate the pixon/pixoff instructions.

I don't think so, because I suppose the screen is not mapped to a fixed range of memory.

What I had in mind was something such as turning on/off an annunciator or checking its state, but I don't know if this information is stored in a fixed place and/or this place (provided it exists) changes when a new version is built.
Find all posts by this user
Quote this message in a reply
09-23-2021, 03:20 PM
Post: #7
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-22-2021 11:17 PM)JoJo1973 Wrote:  
(09-22-2021 09:01 AM)gianluca Wrote:  I don't know if this is even possible, but: can be poke used to toggle a pixel on the screen?
A satisfying example could be a small program that uses peek and poke to simulate the pixon/pixoff instructions.

I don't think so, because I suppose the screen is not mapped to a fixed range of memory.

What I had in mind was something such as turning on/off an annunciator or checking its state, but I don't know if this information is stored in a fixed place and/or this place (provided it exists) changes when a new version is built.

All is possible: you can turn pixels on and off, turn LEDs on and off, etc. but... it's hardware dependent, so an example that works on the 50g will crash on the Prime, Android or PC.
I'd rather not have examples that are machine-dependent.
Find all posts by this user
Quote this message in a reply
09-24-2021, 01:52 PM
Post: #8
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
I think a more productive contribution to the wiki would be a tutorial with examples on how to use the multiple equation solver, which is very different from the 50g and 99% of users don't even know it's there.
I'd like to see examples, with single and multiple equations, as well as with constraints using inequalities to show how powerful it can be.
Find all posts by this user
Quote this message in a reply
09-24-2021, 01:56 PM
Post: #9
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-22-2021 11:12 PM)JoJo1973 Wrote:  There's something I don't understand. When you say 32-bit words at word-aligned ARM addresses you mean that e.g. 0 PEEK should read 4 bytes starting at address 0 and 1 PEEK should read 4 bytes starting at address 4 and so on, right?

Because if I've understood the code (big if Wink ), the address should be ANDed with 0xfffffffc, not 0xffffffff, and the same applies for POKE.

You are right, it should've been ANDed with 0xfffffffc to protect from user error, but there's no need for safety guards because it's low level, reading from misaligned addresses will throw an exception, no big deal.
I may even remove those 2 commands once development is complete (which is a utopia, of course!!)
Find all posts by this user
Quote this message in a reply
09-25-2021, 05:45 PM
Post: #10
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-24-2021 01:52 PM)Claudio L. Wrote:  I think a more productive contribution to the wiki would be a tutorial with examples on how to use the multiple equation solver, which is very different from the 50g and 99% of users don't even know it's there.
I'd like to see examples, with single and multiple equations, as well as with constraints using inequalities to show how powerful it can be.

I'm collecting examples beginning from this old post

https://www.hpmuseum.org/forum/thread-97...#pid101856

but when I began experimenting I've found some difficulties: for example I can't get to solve this linear system:

a + x - 3 y + z = 2
-5 a + 3 x - 4 y + z = 0
a + 2 y - z = 1
a + 2 x = 12
(courtesy of Wolfram Alpha)

The solution is a=22/17 x=91/17 y=84/17 z=173/17 but MSOLVE can't converge: I've used {0 0 0 0} {12 12 12 12} as searching range and I got {0 0 0 0} and {-2 0 -1 -12} as residuals

If I constrain the four variables to be >0 I get {2.9999... 5.9646... 6.2512... 15.2711...} (I don't include the residuals.

I've also tried inverting the order of the searching range or adding >0 constraints, but to no avail.

A system of three equations fails to converge too, but a 2 equation system seems to work.
Find all posts by this user
Quote this message in a reply
09-27-2021, 01:37 PM
Post: #11
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-25-2021 05:45 PM)JoJo1973 Wrote:  
(09-24-2021 01:52 PM)Claudio L. Wrote:  I think a more productive contribution to the wiki would be a tutorial with examples on how to use the multiple equation solver, which is very different from the 50g and 99% of users don't even know it's there.
I'd like to see examples, with single and multiple equations, as well as with constraints using inequalities to show how powerful it can be.

I'm collecting examples beginning from this old post

https://www.hpmuseum.org/forum/thread-97...#pid101856

but when I began experimenting I've found some difficulties: for example I can't get to solve this linear system:

a + x - 3 y + z = 2
-5 a + 3 x - 4 y + z = 0
a + 2 y - z = 1
a + 2 x = 12
(courtesy of Wolfram Alpha)

The solution is a=22/17 x=91/17 y=84/17 z=173/17 but MSOLVE can't converge: I've used {0 0 0 0} {12 12 12 12} as searching range and I got {0 0 0 0} and {-2 0 -1 -12} as residuals

If I constrain the four variables to be >0 I get {2.9999... 5.9646... 6.2512... 15.2711...} (I don't include the residuals.

I've also tried inverting the order of the searching range or adding >0 constraints, but to no avail.

A system of three equations fails to converge too, but a 2 equation system seems to work.

Interesting, I'm investigating why it does not converge.
Find all posts by this user
Quote this message in a reply
09-28-2021, 09:14 AM
Post: #12
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-27-2021 01:37 PM)Claudio L. Wrote:  
(09-25-2021 05:45 PM)JoJo1973 Wrote:  I'm collecting examples beginning from this old post

https://www.hpmuseum.org/forum/thread-97...#pid101856

but when I began experimenting I've found some difficulties: for example I can't get to solve this linear system:

a + x - 3 y + z = 2
-5 a + 3 x - 4 y + z = 0
a + 2 y - z = 1
a + 2 x = 12
(courtesy of Wolfram Alpha)

The solution is a=22/17 x=91/17 y=84/17 z=173/17 but MSOLVE can't converge: I've used {0 0 0 0} {12 12 12 12} as searching range and I got {0 0 0 0} and {-2 0 -1 -12} as residuals

If I constrain the four variables to be >0 I get {2.9999... 5.9646... 6.2512... 15.2711...} (I don't include the residuals.

I've also tried inverting the order of the searching range or adding >0 constraints, but to no avail.

A system of three equations fails to converge too, but a 2 equation system seems to work.

Interesting, I'm investigating why it does not converge.

Just tested with Solvesys on HP50g (real and Emu48): it converges very quickly
Find all posts by this user
Quote this message in a reply
09-29-2021, 12:34 AM (This post was last modified: 09-29-2021 12:36 AM by Claudio L..)
Post: #13
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-25-2021 05:45 PM)JoJo1973 Wrote:  I'm collecting examples beginning from this old post

https://www.hpmuseum.org/forum/thread-97...#pid101856

but when I began experimenting I've found some difficulties: for example I can't get to solve this linear system:

a + x - 3 y + z = 2
-5 a + 3 x - 4 y + z = 0
a + 2 y - z = 1
a + 2 x = 12
(courtesy of Wolfram Alpha)

The solution is a=22/17 x=91/17 y=84/17 z=173/17 but MSOLVE can't converge: I've used {0 0 0 0} {12 12 12 12} as searching range and I got {0 0 0 0} and {-2 0 -1 -12} as residuals

If I constrain the four variables to be >0 I get {2.9999... 5.9646... 6.2512... 15.2711...} (I don't include the residuals.

I've also tried inverting the order of the searching range or adding >0 constraints, but to no avail.

A system of three equations fails to converge too, but a 2 equation system seems to work.

Fixed. I'll see if I can release an update on all ROMs over the weekend so you can start playing with it some more. There was an arbitrary constant in the method that decides how far you go down the gradient and a bug left it too large, so it was throwing the algorithm way off by suggesting a point far from the area being investigated.
Now it converges nicely for your example. Never fails regardless of input, as it should be on a linear system with a unique solution, I threw in a couple of squares and cubes to make it nonlinear and it converged quick too to a valid solution but I did not investigate different inputs to make it converge to other solutions, let's leave it at "it probably works".

I started writing one example at the wiki, but it's so bad that I'd be glad if you take over that writeup altogether. Feel free to replace it completely.

There's one thing I'm not happy about my MES: it doesn't work with units yet but I plan to make it so. Hopefully without making it horribly slow (it's not exactly fast right now but it's one of the more reliable methods out there nowadays).
Find all posts by this user
Quote this message in a reply
09-29-2021, 06:40 AM
Post: #14
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
(09-29-2021 12:34 AM)Claudio L. Wrote:  
(09-25-2021 05:45 PM)JoJo1973 Wrote:  I'm collecting examples beginning from this old post

https://www.hpmuseum.org/forum/thread-97...#pid101856

but when I began experimenting I've found some difficulties: for example I can't get to solve this linear system:

a + x - 3 y + z = 2
-5 a + 3 x - 4 y + z = 0
a + 2 y - z = 1
a + 2 x = 12
(courtesy of Wolfram Alpha)

The solution is a=22/17 x=91/17 y=84/17 z=173/17 but MSOLVE can't converge: I've used {0 0 0 0} {12 12 12 12} as searching range and I got {0 0 0 0} and {-2 0 -1 -12} as residuals

If I constrain the four variables to be >0 I get {2.9999... 5.9646... 6.2512... 15.2711...} (I don't include the residuals.

I've also tried inverting the order of the searching range or adding >0 constraints, but to no avail.

A system of three equations fails to converge too, but a 2 equation system seems to work.

Fixed. I'll see if I can release an update on all ROMs over the weekend so you can start playing with it some more. There was an arbitrary constant in the method that decides how far you go down the gradient and a bug left it too large, so it was throwing the algorithm way off by suggesting a point far from the area being investigated.
Now it converges nicely for your example. Never fails regardless of input, as it should be on a linear system with a unique solution, I threw in a couple of squares and cubes to make it nonlinear and it converged quick too to a valid solution but I did not investigate different inputs to make it converge to other solutions, let's leave it at "it probably works".

I started writing one example at the wiki, but it's so bad that I'd be glad if you take over that writeup altogether. Feel free to replace it completely.

There's one thing I'm not happy about my MES: it doesn't work with units yet but I plan to make it so. Hopefully without making it horribly slow (it's not exactly fast right now but it's one of the more reliable methods out there nowadays).

Cool! I'm almost done with a piece about the numerical integrator, MSOLVE will be next!
Find all posts by this user
Quote this message in a reply
10-01-2021, 01:50 PM
Post: #15
RE: newRPL - Wiki examples for PEEK, POKE and NEWOB commands
I moved the MSOLVE draft to a new chapter dedicated to numerical applications and added an 80% done article about numerical integration - it just lacks more examples - after showing the strength of the algorithm I want to add a few cases that push the envelope (not the Simpson's in particular, but something that gives a very broad introduction to the sad reality that no algorithm is good for any conceivable case).

Basically:

* improper integrals of the two kinds
* removable discontinuities
* strongly oscillating functions e.g. sin(1/x)

After that, I'll do the same for MSOLVE.
Find all posts by this user
Quote this message in a reply
Post Reply 




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