numworks / epsilon

Modern graphing calculator operating system.
https://www.numworks.com/resources/engineering/software/
1.7k stars 461 forks source link

Reverse Polish Notation (RPN) input #35

Open jerr0328 opened 6 years ago

jerr0328 commented 6 years ago

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.

ch-nry commented 6 years ago

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

bwaels commented 6 years ago

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

fabuffet commented 6 years ago

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

mchobby commented 6 years ago

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

fabuffet commented 6 years ago

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

AshleyF commented 6 years ago

+1 RPN is a must

Ecco commented 6 years ago

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?

boricj commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

boricj commented 6 years ago

@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 commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

JensGrabner commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

boricj commented 5 years ago

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 commented 5 years ago

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

boricj commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

boricj commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.

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 commented 5 years ago

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 commented 5 years ago

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

boricj commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

akoun commented 3 years ago

thanks for this. RPN really means "parenthesis free notation" and should be a default in any serious calculator...

Such calculators are usually intended for probably smart people to who the calculator is a tool so I guess that is why after trying RPN for 10 min there is no going back :)

shaunsingh commented 2 years ago

I would definitely love an RPN app built into epsilon itself, but saying that it should be default is a stretch. This is a calculator made for high school and college education, the target demographic is likely working with algebra, basic calculus, geometry, etc. In those cases, "textbook" (algebraic) notation is far easier (and in some cases quicker) to use and follow

Disclaimer: I have both a DM42 and a numworks n0110, both of which I use. On the numworks for simple calculations I prefer the RPN app, for others I prefer the KhiCas app.

https://www.youtube.com/watch?v=VyQpylN0FiE&lc=UgzfS07r5hBubkK1dFR4AaABAg.9U61hK3A4Ws9U7w2We3gtd

Many of the examples in the video I can solve much faster on my Numworks using KhiCas.

There are instances where RPN is much faster. However, most of the time what are students doing? Writing down equations, plotting them, solving for x, etc. The numworks handles this well, you can input and graph functions in one app, solve them in another, and calculate in another app.

errors in complicated expressions are harder to make

This was the case when calculators couldn't process PEMDAS ootb. Nowadays, its as simple as copying what's on the paper into your calculator, not having to insert parenthesis may be faster, but I'm not sure how it's harder to make errors.

I do like using RPN when it makes sense, but by no means should it be default nor is it a tool for only "smart people" (in my opinion).

nozense commented 1 year ago

Is this anywhere in the pipeline for the official os/firmware? Not having rpn is the only reason I'm considering an alternative firmware.

raparici commented 1 year ago

A 5 stack official app would be amazing for those who are used with RPN (or are willing to try). The former rpn app is not compiling anymore along the current firmware.