PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.64k stars 74 forks source link

User defined constants #55

Closed bokeron2020 closed 3 years ago

bokeron2020 commented 3 years ago

I'm using the windows binary an what I'm missing the most ATM is a way to define constants I use often so I don't have to define them as variables every session. I suppose it would mean having at least an external config file... which I would prefer to be human-readable/editable, maybe some json?

PaddiM8 commented 3 years ago

Currently it's possible to load a file with kalker, by doing kalker -i file in the terminal. Although, it would be good to have something more intuitive. Hmm...

bokeron2020 commented 3 years ago

Thanks for your answer PaddiM8. I've been playing a bit with your app and just recently found its launch options. I've tried to create that file with predefined variables but it seems I'm not using proper syntax. Could you point me to some example file?

ERROR: thread 'main' panicked at 'Failed to parse input file.: InvalidNumberLiteral("24000\r")', cli\src\main.rs:78:60 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

Also, out of topic question, is there a possibility to keep history between sessions?

PaddiM8 commented 3 years ago

Actually, that's a bug on Windows! Should be fixed now. Also, there has been some changes to the way multi-line expressions are handled since the input file feature was implemented, meaning you now want to put a semicolon at the end of each line in the input file (not necessary on the last line though). Eg.


x = 3pi;
y = 2x;
xy
``

I just implemented persistent history, so these things should be included in the next release! I will still think about a good way to implement *intuitive* user-defined constants.
bokeron2020 commented 3 years ago

Is there/are you considering some pseudolanguage to define non built-in functions like converting hex<->dec ? if-then-else or something like that could maybe be enough.

Oh, by the way, --precision apparently works internally, right? Any way to choose decimals shown or rounding options? Calculations and rounding changes fron -p 32 to -p 64 but decimals stay at 9 positions.

PaddiM8 commented 3 years ago

I have been thinking about maybe making it possible to define functions using other languages, eg. Python, and being able to use it in kalker. That may happen some day. "if-then-else"? You can actually express this already using piecewise functions.

--precision sets the precision of the internal float. Hm, something like that isn't possible right now it need to be tweaked and may become more flexible in the future.

bokeron2020 commented 3 years ago

I cannot even imagine how to define piecewise functions in the file used for --input-file. Would you mind sharing some example?

PaddiM8 commented 3 years ago

Yeah sure.

Here's a quick example of a file with a fibonacci function and some variables.

fib(n) = {
    1 if n < 2;
    fib(n - 2) + fib(n - 1) otherwise
};
x = 2pi;
y = 2.5;

Here's another one with just a simple piecewise

f(x) = {
    2x if x < 2;
    3x if x < 6;
    4x otherwise
}
bokeron2020 commented 3 years ago

Perfect. Thanks a lot for your help! And for your app!

I needed something like this that could calculate percentages like your app does... and those who did were less convenient or failed in some other aspect. Yours is just what I needed. Clean, easy to use, enough syntax parsing for most of what I do but really simple at the same time.

For my uses I would like what you mentioned above, defining more complex functions using Python. Then maybe I could define an hex to dec algorithm myself, or whatever, that wouldn't overcomplicate normal use for those who don't need it (and for you).

Right now what I miss (just a bit, nothing dramatic) is getting some control over how many decimals we get on-screen (arbitrary-precision arithmetic would be totally awesome!) and some rounding options.

Keep up the good work you've been doing on this project! Regards from Spain.

PaddiM8 commented 3 years ago

Thank you! I'd love to implement these things when I have time, especially Python bindings. :)

PaddiM8 commented 2 years ago

Perfect. Thanks a lot for your help! And for your app!

I needed something like this that could calculate percentages like your app does... and those who did were less convenient or failed in some other aspect. Yours is just what I needed. Clean, easy to use, enough syntax parsing for most of what I do but really simple at the same time.

For my uses I would like what you mentioned above, defining more complex functions using Python. Then maybe I could define an hex to dec algorithm myself, or whatever, that wouldn't overcomplicate normal use for those who don't need it (and for you).

Right now what I miss (just a bit, nothing dramatic) is getting some control over how many decimals we get on-screen (arbitrary-precision arithmetic would be totally awesome!) and some rounding options.

Keep up the good work you've been doing on this project! Regards from Spain.

There is now support for different number bases and input files that are loaded by default! IIRC I improved precision handling a bit, so when you specify a precision --precision it gives you more decimals. It might not be perfect at this stage though.