9 ms·
Show HN: Kalk, A calculator with math syntax, complex numbers
- paddim8 5y agokalk 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 5y agoCongrats! 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 5y agoIt 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 5y agoThat’s great to hear - thanks for the insight. And kudos again on a great project, definitely not easy to get all this functionality!
- kseistrup 5y agoI 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 5y agoThank 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 5y agoAny calculation, even simple ones >> 1+2 fish: Job 1, './kalk-linux' terminated by signal SIGILL (Illegal instruction)
- kseistrup 5y ago(Same thing happens if the shell is bash.)
- afranchuk 5y agoWell, 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 5y agoAh, 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 5y agoHmm, 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 5y agoI agree, that's very strange, considering the similar enviroments. But perhaps your CPU has a more modern instruction set than mine.
- eigenket 5y agoAny 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 5y agoI 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 5y agoThere 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 5y agoYeah 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!
- gojofika 5y agoYou might check the link to get unlimited Google Voice Number https://bit.ly/34tc4BI https://bit.ly/34tc4BI (100% trusted & quality service guaranteed)
- artfulhippo 5y agoCan you support big numbers? When I input 3^4^5, it outputs infinity.
- paddim8 5y agoThe 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 5y ago[deleted]
- Bootvis 5y agoThis seems off: >> f(x) = x^2 >> f''(4) 0.9995297887
- paddim8 5y agoOh yeah, derivatives of higher order being less accurate is a known problem. I forgot to specify that, thanks!
- Bootvis 5y agoMaybe 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 5y agoThank you! Yeah, or at least give a warning.
- whiterock 5y agolook into Dual numbers. That way there is no accuracy loss. More generally look into AD (automatic differentiation). thanks me later, cheers
- longemen3000 5y ago
- fish45 5y agoThis is somewhat similar to my project at https://calcula.tech 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
- xixixao 5y agoVery cool, I'm building a similar project atm as well (not ready to share, but you could dig it up easily), the latex reprinting of input is an interesting twist that I'm sure many people will appreciate. I am afraid this domain is a prime nerd-sniping range, because there are so many variations on building a better, more interactive calculator. No profits here besides learning and great fun!
- dmitriid 5y agoFor 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 5y agoPerforming the calculation with Soulver did not surprise me (being what I calculated in my head ahead of time): 2 + 2 × 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 5y agoWolfram 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)
- paddim8 5y agoHaha damn, didn't expect that
- sp1rit 5y agoWhat about the win32 calculator shipped with w7 and w10 ltsc?
- TchoBeer 5y agoAndroid gives me 2.2
- app4soft 5y ago2.2 via Google[0] > and there's no % in engineering calc Use 0.1 instead of 10%, it has the same vibe ;) [0] https://www.google.com/search?gbv=1&q=2%2B2%C3%9710%25&oq=&aqs= https://www.google.com/search?gbv=1&q=2%2B2%C3%9710%25&oq=&a...
- a1369209993 5y ago
- bbodi 5y agoIf everybody adds his/her rust+wasm+calculator projects in the comments, let me jump in as well with mine :) https://bbodi.github.io/notecalc3/ https://bbodi.github.io/notecalc3/ Nice work btw!
- deleted 5y ago[deleted]
- 0_gravitas 5y agoah beautiful, i was hoping a cli-ified/updated version of the already wonderful OpalCalc would come into existence!
- simias 5y ago`√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 5y agoYeah same with x^-1, I forgot about that, thanks!
- HDMI_Cable 5y agoThis 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 5y agoCan 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 5y agowhat features from bc do you need? Have you seen calc (the calc package in debian/ubuntu)?
- tux1968 5y agoIf you're looking for something more advanced while still at the command prompt, check out "calc": http://isthe.com/chongo/tech/comp/calc/ http://isthe.com/chongo/tech/comp/calc/ On Fedora: sudo dnf install calc ; alias bc=calc
- Grustaf 5y agoNice work! And you beat me to the name "Kalk", I've had a private github repo with a calculator with that name for a while, though mine takes sort of the opposite approach, input and manipulation is very visual.
- app4soft 5y ago> though mine takes sort of the opposite approach, input and manipulation is very visual. There is already opensource app for that: microMathematics Plus (μMath+) — Extended visual calculator for Android.[0,1] [0] https://github.com/mkulesh/micromathematics https://github.com/mkulesh/micromathematics [1] https://f-droid.org/packages/com.mkulesh.micromath.plus/ https://f-droid.org/packages/com.mkulesh.micromath.plus/
- Grustaf 5y agoSure, there's lots of great calculator apps with visual interfaces.
- krick 5y agoThis 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 5y agoThese 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...
- sp1rit 5y agoWould love to have TeX syntax support for this one, as I'm so used to typing it.
- jeroenhd 5y agoAn interactive calculator that passes the 0.1+0.2 test, very nice.
- teleforce 5y agoKudos to the author, it seems a very nice calculator program. Any chance in the future that Kalk will support quaternion numbers[1]? [1]https://en.wikipedia.org/wiki/Quaternion https://en.wikipedia.org/wiki/Quaternion
- paddim8 5y agoThank you. Oh my... aren't those really complicated? Haha
- sudosysgen 5y agoYou can operate on them using the same rules as complex numbers with a slight twist.
- xixixao 5y agoCan you give an example of a quaternion computation that would be useful in a calculator? I would imagine that quaternions and GA are best suited to have a graphical output, ala https://enkimute.github.io/ganja.js/examples/coffeeshop.html https://enkimute.github.io/ganja.js/examples/coffeeshop.html ?
- deleted 5y ago[deleted]
- chrismorgan 5y agoI immediately found a few Unicode features I hoped were supported but aren’t. Superscripts: firstly numerals, like 3² = 9, but ideally then letters as well, e.g. 3ⁱ = 3^i. Might be suitable to support superscripts to define nth roots, too, e.g. ⁵√. tan¯¹ can be a thing too. Subscripts: same deal; log₂ 31 = log(31, 2). Proper arithmetic operators: times (×), minus (−), division (÷). Also fraction slash (⁄), which can be preceded and succeeded either by normal numerals (e.g. 12⁄34) or by superscripts and subscripts (e.g. ⁵⁶⁄₇₈). (Full font support for fraction slash is weak, but generally tolerable even if imperfect.) Also the prebaked fractions like ½ and ⅜. Also mixed fractions: I reckon 1 2/3 should be parsed as 1+2/3, not 12/3. Them Unicode fractions can join in here too, with 1⅔ (using a prebaked fraction) being 1+2/3, or 1²³⁄₄₅ (using superscript, fraction slash, subscript) being 1+23/45. Cubic and quartic roots: ∛ and ∜. At this point it’s worth just looking through the whole Symbol, Math Unicode category and implementing everything applicable. Hmm, set operations, lots of fun symbols there. Lots of fun spaces too, e.g. where I wrote log₂ 31 earlier I wanted to use NARROW NO-BREAK SPACE after the ₂, but alas, HN normalises it to a plain old space. That space gets used as a number grouping separator especially, avoiding the whole ,/. localisation problem without being too wide.
- paddim8 5y agoOh yes! I have thought about the subscript/superscript thing, but didn't think of these other things. That would actually be great.
- sillysaurusx 5y agoFor what it’s worth, my first session went like this: >> e^iπ+1 2.6974097548 + 2.6435590641i >> e^iπ 1.6974097548 + 2.6435590641i In fairness, I still don’t know where “e” comes from in complex number notation. The transition from cos(angle) + i sin(angle) seems to become “e^i(angle), lol” and no one explains it further. Before I started doing signal processing, I too would have thought that e^i pi is something like 1.69 + 2.64, so it’s correct, in a certain sense. But perhaps not the common mathematical sense. EDIT: Ah, I see the problem. I suspected that e^iπ was being turned into πe^i incorrectly, but when I typed the open parenthesis for e^() and put my cursor inside it, typing "i" resulted in e^i() rather than e^(i). So it was impossible to parenthesize correctly, and I assumed e^iπ had the usual meaning.
- lhjn 5y agoIt's the exponential notation for complex numbers, see for example https://tutorial.math.lamar.edu/Extras/ComplexPrimer/Forms.aspx https://tutorial.math.lamar.edu/Extras/ComplexPrimer/Forms.a...
- sillysaurusx 5y agoThat post proves the point: it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828... The reason I posted my comment is because e^(i pi) is obviously supposed to be -1+0j. But I see now that I was using the calculator incorrectly (I was doing the equivalent of πe^i) but there was a bug in the parenthesis operator preventing me from typing it that way on mobile.
- Tubeee 5y ago> it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828... It really isn't, beyond the fact that exp(1) = 2.718…. Then, by definition exp(it) = exp(1)^(it) = e^it. It isn't much more than a notational artifact as far as I'm concerned. For that matter, raising any base b to a power is equivalently just scaling it by ln(b) and plugging it into exponential function, that is, b^it = cos(ln(b) * t) + i sin(ln(b) * t).
- dividedbyzero 5y agoPity it's not in homebrew. I realize I can manually download a binary and manually install it and make a note somewhere where I got it from in case I forget and then periodically re-check manually if an update is out, or just never install any updates, but I'm trying to not do that if it can be helped.
- paddim8 5y agoYeah maybe it should be on homebrew and other package managers. Didn't actually expect it to get this much attention! I'll see what I can do
- kqbx 5y agoI'm a big fan of https://qalculate.github.io/ https://qalculate.github.io/. It has a nice GUI which can be used interchangeably with the CLI version. It also has units, many built-in physical constants, currency conversion, matrices and probably tons of other stuff I don't know about. I don't think it can be easily ran in a browser though.