[HN Gopher] Show HN: Kalk, A calculator with math syntax, comple...
___________________________________________________________________
Show HN: Kalk, A calculator with math syntax, complex numbers, etc.
(Rust, WASM)
Author : paddim8
Score : 131 points
Date : 2021-05-30 15:07 UTC (7 hours ago)
(HTM) web link (kalk.strct.net)
(TXT) w3m dump (kalk.strct.net)
| bbodi wrote:
| If everybody adds his/her rust+wasm+calculator projects in the
| comments, let me jump in as well with mine :)
| https://bbodi.github.io/notecalc3/
|
| Nice work btw!
| simias wrote:
| `[?]2` works but `[?]-1` doesn't, which surprised me a bit. I'
| expect unary `-` to bind tighter, but in this context it
| considers that it's a binary operator between `[?]` and `-1`. If
| you put parens it works of course.
| paddim8 wrote:
| Yeah same with x^-1, I forgot about that, thanks!
| [deleted]
| jeroenhd wrote:
| An interactive calculator that passes the 0.1+0.2 test, very
| nice.
| Bootvis wrote:
| This seems off: >> f(x) = x^2 >>
| f''(4) 0.9995297887
| paddim8 wrote:
| Oh yeah, derivatives of higher order being less accurate is a
| known problem. I forgot to specify that, thanks!
| Bootvis wrote:
| Maybe best to just disable it for now, I played with e^x as
| well and the results were off as well.
|
| Ignoring these, I really like Kalk!
| paddim8 wrote:
| Thank you! Yeah, or at least give a warning.
| jll29 wrote:
| Beautiful Web GUI, beautiful source code, "cargo install
| kalk_cli" && it works like a charm! Thanks for sharing
| this.
| paddim8 wrote:
| Thank you so much! This is my first (and only) Rust
| project so I'm a bit nervous about the code quality.
| whiterock wrote:
| look into Dual numbers. That way there is no accuracy loss.
| More generally look into AD (automatic differentiation).
| thanks me later, cheers
| [deleted]
| HDMI_Cable wrote:
| This is really nice and all, but what I (and probably many
| others) would love is an alternative to `bc`. It's so useful but
| also so limited.
| anyfoo wrote:
| Can you elaborate? I think I know what you mean, but when I
| clicked the link it already seemed to be a "more advanced bc"
| to me. What are you missing, big numbers (that's what came to
| my mind)?
| kzrdude wrote:
| what features from bc do you need? Have you seen calc (the calc
| package in debian/ubuntu)?
| fish45 wrote:
| This is somewhat similar to my project at https://calcula.tech,
| although the usecase is a bit different. There are a few other
| calculators around that use Rust + WASM which is kind of
| interesting
| paddim8 wrote:
| kalk is a calculator that has syntax highlighting, automatically
| turns names into symbols (eg. sqrt to [?]), supports math-like
| syntax (eg. f(x) = x(2sinx + 3) , estimation of derivatives and
| integrals, complex numbers, and runs in the browser using
| WebAssembly.
| math-dev wrote:
| Congrats! I write calculators myself from time to time, but
| this sounds very impressive :) How was your experience using
| webassembly? Any good guides that helped you with that part?
| paddim8 wrote:
| It was actually surprisingly seamless with Rust. "wasmpack"
| pretty much did it all for me. I added some attributes (well,
| whatever they're called in Rust) to function and struct
| declaration to show that bindings should be generated for
| these things, and from that wasmpack could generate
| JavaScript bindings! Unfortunately I was slightly limited by
| some libraries not working with WebAssembly, but I got around
| that fairly easily.
| math-dev wrote:
| That's great to hear - thanks for the insight. And kudos
| again on a great project, definitely not easy to get all
| this functionality!
| 0_gravitas wrote:
| ah beautiful, i was hoping a cli-ified/updated version of the
| already wonderful OpalCalc would come into existence!
| eigenket wrote:
| Any interest in adding more symbolic stuff? There often isn't
| really any reason to do derivatives numerically. While I was
| looking at the derivatives I noticed the word "quotinent" should
| be "quotient" in the readme.
| paddim8 wrote:
| I have thought about doing derivatives and such algebraically
| when possible. It should certainly be doable, and I already
| have a system for moving things around to achieve these kind of
| things. This may be a thing in the future.
| eigenket wrote:
| There are also some algorithms for trying to deal with
| symbolic integrals but they're pretty intense compared to
| what you have to do for derivatives (which are very easy).
| paddim8 wrote:
| Yeah that makes sense. I won't be able to do it 100% of
| course, especially considering I so far have only learned
| high school maths, but even if it just manages to do it in
| some situations, that would still be fine as long as it
| falls back to (often quite accurate) numerical integration.
| I'll read some more about it!
| artfulhippo wrote:
| Can you support big numbers?
|
| When I input 3^4^5, it outputs infinity.
| paddim8 wrote:
| The desktop program does technically have the capabilities of
| that, but lately I've been focusing a lot more on the web
| version, that unfortunately doesn't, so results are 64-bit at
| the moment. I have been waiting for a proper Rust library that
| can do this, so that it could work on the web version as well,
| but so far, that has not happened, so I'll probably do some
| work on properly supporting big numbers on the desktop program
| soon.
| [deleted]
| kseistrup wrote:
| I usually use the interactive Python prompt when doing
| calculations, but kalk takes it up a notch. Well done!
|
| (The pre-built Linux binary segfaults before it can show the
| result on my ArchLinux box, but the cargo installed one works
| like a charm.)
| paddim8 wrote:
| Thank you! I made this as a replacement for using the Python
| prompt for calculations actually haha.
|
| Hm that's strange though, it seems to work for me (also on
| Arch). What calculation did you do?
| kseistrup wrote:
| Any calculation, even simple ones >> 1+2
| fish: Job 1, './kalk-linux' terminated by signal SIGILL
| (Illegal instruction)
| kseistrup wrote:
| (Same thing happens if the shell is bash.)
| afranchuk wrote:
| Well, that's not a segfault. It's more likely that it's
| being compiled with an incorrect/specific architecture
| (e.g. using AVX2 instructions). Though it really shouldn't
| be using such instructions for basic math. It is possible
| the instruction pointer is getting messed up too.
| kseistrup wrote:
| Ah, thanks for setting me straight. I just noticed the
| core dump and assumed a segfault.
|
| And thanks for fixing the two issues so fast.
| paddim8 wrote:
| Hmm, that's very strange, considering I'm running a very
| similar setup (Arch and fish). I wonder if it could be an
| issue with the library I'm using for big floats..
| kseistrup wrote:
| I agree, that's very strange, considering the similar
| enviroments. But perhaps your CPU has a more modern
| instruction set than mine.
| dmitriid wrote:
| For fun, try to run this: `2 + 2 * 10%` in all calculators you
| have access to: on you phone, on your desktop, in kalk.
|
| As they say, "the answer will surprise you" :)
| npongratz wrote:
| Performing the calculation with Soulver did not surprise me
| (being what I calculated in my head ahead of time):
| 2 + 2 x 10% = 2.2
|
| At the risk of admitting my ignorance, yet more interested in
| learning something new: should this answer (2.2) surprise me?
| dmitriid wrote:
| Wolfram Alpha and iOS also give 2.2
|
| On MacOS the answer is 2.4
|
| In kalk it's 2.002
|
| On Windows it's 0.4 in simple calc, and 2 in programmer calc
| (and there's no % in engineering calc)
| TchoBeer wrote:
| Android gives me 2.2
| paddim8 wrote:
| Haha damn, didn't expect that
| sp1rit wrote:
| What about the win32 calculator shipped with w7 and w10
| ltsc?
| kzrdude wrote:
| Is there an explanation for the answer in kalk? Seems buggy
|
| It seems like an expression like "1 * 10%" in kalk is computed
| as if it means "1% * 10%" => "0.01 * 0.1" => "0.001"
| a1369209993 wrote:
| $ units You have: 2 + 2 * 10% Definition: 2.2
|
| ITYM "the answer _may_ surprise you ", and in this case it did
| not.
| j1elo wrote:
| The calculator that comes with MIUI 12 (Xiaomi phone) writes
| everything as you type, like you'd expect.
|
| But, the moment you type `%`, it instead replaces `10` with
| `0.1`. So in the end the screen shows: 2+2x0.1 = 2.2
|
| I guess not as surprising as you expected :-]
| krick wrote:
| This looks extremely useful, even though currently makes quite a
| few mistakes, as noted by others. A few features that could be
| nice:
|
| 1) It handles 1 000 000 * 3 just fine, but returns 3000000. So it
| would be nice if it would format output as 3 000 000 as well for
| readability. At least as an optional setting (even though I have
| no idea why someone wouldn't want that).
|
| 2) Some way of referencing last result. Often you need to perform
| operations step by step, when, say, estimating something. So
| either 10 \n + 20 \n * 3 ..., or just referencing last output
| like some special variable. I though I could do it more verbosely
| by just x = 10; x = x + 20 ..., but that gives "Variable
| references itself."
|
| 3) Not sure about this one, since this is not something natural
| at all, and I don't know what to propose to make it natural (at
| least without proposing map/filter/reduce and some sort of multi-
| line inputs). Neither is it a real problem, but it's just
| something I probably use a calculator most often: simply adding
| up a dozen of numbers, copied from somewhere as a column. So
| currently I must first open vim, convert it to and expression bc
| will handle ( 15 + 21 + 32 ...), and then paste in to bc. With
| kalk it would be similar. Would be great if one could skip that
| step since this (I assume) would be a common use-case. But, yeah,
| I don't have an actual suggestion on how to naturally address
| that.
| paddim8 wrote:
| These are some great suggestions! I should absolutely make it
| add spaces, can't believe I didn't think of that.
|
| Also, it actually does have a way to reference the last result,
| I forgot to document it. It's a variable called "ans"!
|
| The last thing, yeah, that would be neat. I'll think about
| it...
| gojofika wrote:
| You might check the link to get unlimited Google Voice Number
| https://bit.ly/34tc4BI (100% trusted & quality service
| guaranteed)
| sp1rit wrote:
| Would love to have TeX syntax support for this one, as I'm so
| used to typing it.
___________________________________________________________________
(page generated 2021-05-30 23:00 UTC)