New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse Polish Notation (RPN) input #35

Open
jerr0328 opened this Issue Aug 30, 2017 · 46 comments

Comments

Projects
None yet
@jerr0328

jerr0328 commented Aug 30, 2017

A nice feature would be to have RPN mode. It's not a popular feature in calculators nowadays, but it can be very useful in understand how stacks work and how early calculators would work.

@artaxxx artaxxx added the enhancement label Aug 31, 2017

@ch-nry

This comment has been minimized.

ch-nry commented Nov 18, 2017

+1 : RPN is the only way I use calculators!

@bwaels

This comment has been minimized.

bwaels commented Dec 8, 2017

tribute to HP calculators . The yellow keys ae a reference yet

@fabuffet

This comment has been minimized.

fabuffet commented Apr 17, 2018

Rpn seams so natural and logical once you have understood how it works. I find it hard to use something else now.

@mchobby

This comment has been minimized.

mchobby commented Apr 24, 2018

I still use my HP48Gx with RPN (in Belgium).
I cannot imagine use something else than RPN... it is so efficient.

@fabuffet

This comment has been minimized.

fabuffet commented Apr 25, 2018

I'm still using it too. The numworks with rpn would be a real treat.

@AshleyF

This comment has been minimized.

AshleyF commented Apr 25, 2018

+1 RPN is a must

@Ecco

This comment has been minimized.

Contributor

Ecco commented Apr 30, 2018

We're all in favor of adding RPN (even though, let's be honest, it quite doesn't appeal to newcomers). That being said, the problem is that RPN is stack-based, and we couldn't figure out how to get it to play well with the rest of the user interface.

Question to the RPN gurus out there: how would you fit an RPN entry mode in, say, the "Functions" app?

@Ecco Ecco changed the title from RPN Mode calculation to Add Reverse Polish Notation input (RPN) Apr 30, 2018

@Ecco Ecco changed the title from Add Reverse Polish Notation input (RPN) to Reverse Polish Notation (RPN) input Apr 30, 2018

@boricj

This comment has been minimized.

Contributor

boricj commented Apr 30, 2018

It doesn't need to be RPN-aware everywhere. I think most people yearning for RPN would be perfectly happy with just a RPN toggle setting that affects only the Calculation app.

@AshleyF

This comment has been minimized.

AshleyF commented Apr 30, 2018

Agree. I'd be thrilled to see it in the Calculation app alone.

For the Functions app, technically, a "function" would be a "truncated" stack expression with missing parameters or perhaps with an initial x in place.

Example f(x) = x * x would be f(x) = dup * or maybe f(x) = x dup *
Example g(x) = 1 / x would be g(x) = 1 swap / or maybe g(x) = x 1 swap /

Note that x is always to the far left (or truncated). Swaps rots and dups are required to reorder or reference multiple times.

Not sure which keys would become dup, swap, etc. Parenthesis are not needed, so maybe overloaded? HP-35 got by with just x↔y (swap), R↓ (rot) and ENTER to dup.

@ch-nry

This comment has been minimized.

ch-nry commented May 1, 2018

Having a RPN_calculation app is fine for me.

To control the stack, you need ENTER, SWAP, DUP, DROP, and PICK.
PASTE and CLEAR can be used for DUP and DROP.
EXE for ENTER, arrow (to go on the stack) and ENTER for PICK, and a parenthesis for SWAP. You can even use the other parenthesis for OVER. (i.e: dup argument 2)

@Ecco

This comment has been minimized.

Contributor

Ecco commented May 1, 2018

Having a RPN_calculation app is fine for me.

I'd be thrilled to see it in the Calculation app alone.

I guess an easy solution would indeed be to add a new, RPN-only calculation app. It wouldn't feel very well integrated though.

@UDXS

This comment has been minimized.

UDXS commented May 2, 2018

Could it be possible to have an RPN app that is able to convert the expressions back to normal for use in functions and others automatically. Like an "Export Expression" button so that there is some level of integration.

@Ecco

This comment has been minimized.

Contributor

Ecco commented May 2, 2018

Well an RPN app could definitely leverage the clipboard (copy and paste) to interact with other apps. That being said, I'm still not very happy with the idea of having a separate app just for entering expressions.

@UDXS

This comment has been minimized.

UDXS commented May 2, 2018

Clipboard would be a good idea. It wouldn't be just for entering expressions. It would be like the Calculation app. Otherwise, I think it's a good compromise for something that won't be used very much.

@boricj

This comment has been minimized.

Contributor

boricj commented May 2, 2018

I think the kind of people that truly want a real graphical RPN calculator would rather use a HP 48/49/50 oldie than a NumWorks calculator. My father used a HP 15C until recently when he switched to the HP 35S and I swear he'd still use his HP 35 if it still worked. He just loves RPN and HP calculator keyboards that much.

@Ecco The NumWorks hardware and software is just not targeted at people demanding HP-grade calculators, so I would not worry too much about deeply integrating RPN into the calculator for the time being. Let's do a RPN calculation app first (even if just a third-party one) and see if people asking for RPN are happy with it. We can always figure out something better later on if enough people want more.

@UDXS

This comment has been minimized.

UDXS commented May 3, 2018

You could try making an emulator for the older calculators. It'd be interesting.

@boricj

This comment has been minimized.

Contributor

boricj commented May 3, 2018

@UDXS Those already exist (Free42, newRPL) and they have ports to either original or look-alike HP calculators. One certainly could port them to the NumWorks calculator (beware though, Free42 is licensed under the GPL so we can't mix in epsilon's code for porting).

@0b101

This comment has been minimized.

Contributor

0b101 commented Jun 19, 2018

What about an option in settings that changes the way the Calculation app behaves (Algebraic vs RPN)? It would decrease the amount of storage needed to implement RPN.

@garycmartin

This comment has been minimized.

garycmartin commented Aug 21, 2018

Not sure if there's progress on any official support, but here's a python RPN script I've been tinkering with over the last few days.

https://workshop.numworks.com/python/garycmartin/rpn

Not exactly an integrated or robust solution, but nice to use python to experiment with some RPN calculations. There's plenty more that could be added but trying to keep an eye on memory... V0.3 supports pi, e, rnd, !, *, +, -, /, acos, asin, atan, cos, deg, log, log10, pow, rad, recip, sin, sqr, sqrt and tan. Type ? for a list of operators, clr to clear the stack, swap to swap the two most recent stack items, roll to roll the stack, drop to drop the last stack item, and q to quit.

Example:

> 3 sqr 4 sqr + 5 sqr - 2 3 * 4 * / acos deg
[90.0]
> 4 sqr 5 sqr + 3 sqr - 2 4 * 5 * / acos deg
[90.0, 36.86989764584401]
> 5 sqr 3 sqr + 4 sqr - 2 5 * 3 * / acos deg
[90.0, 36.86989764584401, 53.13010235415599]
> +
[90.0, 90.0]
> +
[180.0]
@boricj

This comment has been minimized.

Contributor

boricj commented Sep 1, 2018

I got bored and made an RPN app for the NumWorks. It's quite basic and a bit rough around the edges for now, but it's a real native third-party app. I need fans of RPN to check it out to see if it actually works properly in real life.

I also need to gauge interest for this. I've spent my entire Saturday afternoon and evening into this PoC and I want to know if there's a real interest for this before I continue.

https://github.com/boricj/numworks-rpn

@wawachief

This comment has been minimized.

wawachief commented Sep 5, 2018

@boricj, you are a genius. Please, get bored more often :)
I tried your proof of concept and it looks very promising. I installed the rpn app among the other apps so I can still use my numworks as usal while testing your rpn app. To do that, I edited the file build/config.mak and added rpn to the EPSILON_APPS definition. Maybe this could be added to the readme ?

img_0265
img_0266

I found a problem using the rpn app : when the stack is full (more than 5 elements), I can't input more numbers, the EXE key is no longer working. Bay the way, is it RPN or RPL ? hp42 or HP48 like ?

Thank you for this initiative !

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 5, 2018

@wawachief You don't need to modify config.mk to add apps, just redefine EPSILON_APPS on the command line as shown on the README. Do a make info to see a list of useful variables you can override. For the stack, it's limited to 5 elements because more would not fit on the screen and I haven't implemented scrolling yet. The limit can be increased once this is fixed, but gracefully handling a full stack has a couple of nasty issues.

The app is just an immediate RPN frontend for poincare and it is not programmable (nor can poincare express programs in its current form). But there's a lot of room for improvement nevertheless since most poincare features aren't accessible yet within this app.

@wawachief

This comment has been minimized.

wawachief commented Sep 5, 2018

Thank you @boricj for your answer. I've seen the EPSILON_APPS= option in your README file, but as it is, you only have RPN and settings on the calculator, which is quite disturbing when you first look at your calculator after flashing the firmware. Maybe, adding to the readme a complete set of apps into the EPSILON_APPS option would be easier for those who would like to test the rpn app among the other apps.

5 elements in the stack is more than enough. 4 (XYZT) would be fine, and would not require any scrolling. For the stack display, I am used to see the X register on the bottom of the screen.

I've noticed that The e^x key returns e and does not compute the exponential of the X register.
I've noticed too that the log key computes the Y base logarithm of X and not the decimal logarithm. Now that I know it, it is not a problem.
I searched for the +/- key but didn't find it. Is it implemented yet ?

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 5, 2018

I'll amend the README next time I'll work on this. The whole third-party app mechanism needs to be properly documented, but sadly NumWorks's technical documentation does not explain this and https://en.wikibooks.org/wiki/Unofficial_Guide_To_Expanding_Your_Numworks is thoroughly obsolete...

The handled keys are currently raw mappings to single poincare primitives, which explain most idiosyncrasies you've encountered (and the fact that there's no toolbox for now). The +/- key is not implemented yet, I guess I should map it to ,. As you've noticed, there's a lot of room for improvements.

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 6, 2018

I've updated the RPN app. I've modified the stack handling to be closer to old HP calculators (or at least as much as I could recall) and made numerous other improvements. It's still bare-bones, but it's actually usable now.

@wawachief

This comment has been minimized.

wawachief commented Sep 7, 2018

Thank you ! This update makes the rpn app totally usable. I will use it as my default calc app on the numworks :)

@JensGrabner

This comment has been minimized.

JensGrabner commented Sep 8, 2018

From this one givs a emulator writen in the Programming Language Paskal.
The calculator here: http://mk.semico.ru/vid161.htm
The Emulator here: https://sourceforge.net/projects/emkatic/
Is this possible for this Hardware ?

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 9, 2018

@JensGrabner I'm having a hard time finding information about the MK-161 in a language I can understand, but from what I gathered a custom firmware could reimplement it on the NumWorks calculator with room to spare. The emulator is extremely Windows-specific and can't be ported though. Please note that I only intend to create an immediate RPN frontend for poincare with my app, so extending the feature set or emulating other calculators is out of the scope of this particular issue.

@JensGrabner

This comment has been minimized.

JensGrabner commented Sep 9, 2018

Thanks -- i think, it is the same with this project - https://commerce.hpcalc.org/34s.php

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 15, 2018

I've cleaned up the app a bit, implemented stack scrolling/picking and bumped the stack size to 16 elements. The RPN app actually feels like a proper NumWorks app and while there's still things left to be implemented it should be good enough for everyday usage.

@Ecco Please consider closing this issue, as unless people want the RPN app built-in this issue has been fixed. Everyone else, I'd suggest you add yourself as a watcher of my repo if you want to keep track of improvements. Until there's a better place to discuss about the app, we should probably keep discussing it here.

@adriweb

This comment has been minimized.

Contributor

adriweb commented Sep 15, 2018

Wouldn't it be possible for the NumWorks team to merge your app but not build it by default?

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 15, 2018

@adriweb It's possible, but that would hinder development since the NumWorks team would need to review and merge all future commits instead of me directly pushing on my own repo. Unless they want to integrate and maintain it in the official firmware, it probably won't happen.

@adriweb

This comment has been minimized.

Contributor

adriweb commented Sep 15, 2018

Well yes, I was thinking that it would/could eventually be mainlined.
Another "solution" would be a submodule - and the NW team would update it from time to time when they are happy with the state at a certain time.

@boricj

This comment has been minimized.

Contributor

boricj commented Sep 15, 2018

Submodules would make sense only if NumWorks add custom firmware creation to the workshop, with submodules acting as a curated set of apps to pick from. Submodules are notoriously difficult for Git newbies to grok, let's not complicate things unless we need to.

@ch-nry

This comment has been minimized.

ch-nry commented Sep 20, 2018

thanks boricj for this work,
I'm overbuzzy for the moment, but 'ill buy a numworks calculator as soon as possible to test this app.
I'll report on your github if I have problem.

@augustz

This comment has been minimized.

augustz commented Sep 24, 2018

I’ll also be buying a calculator to give this a shot

@boricj

This comment has been minimized.

Contributor

boricj commented Oct 24, 2018

As a heads-up, the RPN app was fixed on master thanks to @qguv. I've left a precompiled ROM on TI-Planet (https://tiplanet.org/forum/viewtopic.php?f=102&t=21808&p=236212#p236212) with the latest epsilon master if you want to try it out.

@ch-nry

This comment has been minimized.

ch-nry commented Nov 9, 2018

Thanks for this binary.
I just received my calculator and I made the automatic update (I had to install chromium on my computer, I'm not glad about that). Anyway, the update did not ask for a specific file. So I don't know how to use this ROM. I tried to install the SDK, but it is only available for windows or osX (I'm on linux). What should I do now?
Please forgive me and point me to the right place if this is not the best place to ask for help.

@boricj

This comment has been minimized.

Contributor

boricj commented Nov 9, 2018

The automatic update from NumWorks will only install the latest official stable version. To flash a specific ROM file, the easiest way is to use https://devanlai.github.io/webdfu/dfu-util/. Plug in the calculator to the computer with a USB cable and push the reset button through the pinhole on the back to enter recovery, which is effectively unbrickable by design.

The SDK can easily be installed on Linux and I actually use Linux when developing for the NumWorks calculator. The SDK manual installation instructions is tailored for Debian (https://www.numworks.com/resources/engineering/software/sdk/other/), but other distributions should work as long as they are recent and can provide the dependencies.

On the matter of places to ask for help, while I don't have an account on Reddit the main NumWorks forum is at https://www.reddit.com/r/numworks/. There's also TI-Planet, where I left the ROM, which does accept English posts alongside the French language and is where most major community projects are announced or covered, like zardam's NES emulator port, my HP Prime port of epsilon or my turtle module implementation for Python.

@ch-nry

This comment has been minimized.

ch-nry commented Nov 10, 2018

Thanks for all this informations,
Installing the ROM when without any problem.

I read the SDK installing page to fast and did not spot the linux instruction (I read "virtual OS" instead of "virtually any operating system"), thanks for pointing it. I can now compile the ROM.

So, I tested the RPN app. It is very nice. I will use it as my default calculator. However I have few comment and propositions.

  • duplicating a "undef" crash the app and reboot the calculator.
  • the ! is not an operator : it is possible to type 3!, but not 3 EXE and then ! EXE
  • there is no "nth root" function
  • there is no UNDO function
  • the x10^x key should be use as an operator when the prompt is empty (as 10^X)
  • I would prefer having the -X function on shift -, better than alpha -
  • I miss the 1/X function, can it be add to the shift / (or alpha /)
  • Rot N can be usefull (N being the last value in the stack)

So a key mapping proposition :
EXE : dup
shift EXE : over
Ans : undo
) : swap
( : rot
shift ( : rot N
shift - : -X
shift % : 1/x
shift . : nth root

When editing the stack (using the UP/Down arrow), EXE is used as PICK : it's a great feature. can the DROP be also implemented? (to remove any element in the stack)

When switching the calculator off and on again in the RPN app, the display is a bit corrupted (on the top if the stack is empty, and near the cursor)

Anyway, thanks a lot for this app, I'll use it a lot.

@boricj

This comment has been minimized.

Contributor

boricj commented Nov 10, 2018

The current architecture of the RPN app has a couple of issues I need to sort out before making improvements to it (the latest fixes to get it running on master are especially nasty workarounds). Most notably, I must write a RPN parser (while reusing the existing poincare lexer) and a RPN serializer to really take this to the next level.

@ch-nry

This comment has been minimized.

ch-nry commented Nov 11, 2018

This look like a huge work. I hope it is still on your todo list.
thanks

@boricj

This comment has been minimized.

Contributor

boricj commented Nov 11, 2018

After thinking about it, I'm postponing writing a RPN parse/serializer for now since I managed to get away with a code cleanup that leaves things in a not too shabby state.

I've pushed an update that takes advantage of exact computations, but I'm worried that performance is going to take a hit with heavy-duty expressions (especially those involving inverse trigonometrics). Switching between exact and approximate modes is done with '=' (shift+pi). Similarly, I've reduced the stack size to 8 elements, just in case the added memory consumption in a worst-case scenario pushes the calculator over the edge.

@ch-nry

This comment has been minimized.

ch-nry commented Nov 11, 2018

This look great on the simulator. (the app did not crash anymore)
but I don't find the rom file when i make with : make EPSILON_APPS='rpn graph code statistics probability solver calculation sequence regression settings'
where should it be?

@boricj

This comment has been minimized.

Contributor

boricj commented Nov 11, 2018

The default make target will build epsilon.elf or (epsilon.exe if you're under Windows). You need to explicitly ask for epsilon.bin while invoking make if you want the firmware binary, but you might as well call make epsilon_flash to upload it to your calculator.

@ch-nry

This comment has been minimized.

ch-nry commented Nov 11, 2018

thanks, it's working.
(this info is missing in the readme file.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment