Hacker News new | comments | show | ask | jobs | submit login
Insect: a fast, repl-style scientific calculator (shark.fish)
92 points by curtis 100 days ago | hide | past | web | 68 comments | favorite

This is pretty slick, and I think very useful as-is.

But, while we're all posting wishlists, one thing that'd be nice is if it simplified unnecessarily complex compound units in the result. In the simplest case, it's able to do this, canceling out literally identical units that appear in both a numerator and denominator:

    > 2m/s * 2s
Obviously that is a better result than this hypothetical example would be:

    > 2m/s * 2s
    4 m·s/s
But if you use two different units of time, you get essentially a result like that worse one:

    > 2m/s * 2min
The unit m·min/s is not exactly wrong as a result here, but is unwieldy and a bit unusual as a unit of length. Since a "min/s" is just a scalar quantity, the scalar 60 (1 min/s = 60 s/s = 60), this simplifies to 240m.

You do get that result if you explicitly ask for it,

    > 2m/s * 2min -> m
But it'd be convenient to automatically get these kinds of simplifications, especially when dealing with more complex expressions.

Thank you for the feedback!

Absolutely agreed. This is on my priority list and there is already an open issue which is tracked here: https://github.com/sharkdp/insect/issues/37

Since Numi <https://numi.io/> has become slow to launch – and I find Soulver <http://www.acqualia.com/soulver/> overkill for quick calculations – I've been looking for a replacement. Here's how to set insect up to run "as" a Mac app.


OT: The angled-brackets are getting interpreted as a part of the URL - both links couldn't be found because of it.

I wish it automatically captured the last result and let you easily use it in your next input. The current command line calculator I'm using also lacks this.

> 5+20

> = 25

> +10

> = 35

Thank you for the feedback. You can use `ans` to refer to the last result:

  > 5+20
  > ans+10

Python and a few other REPLs seem to use _ to capture the previous result. Could be a useful shorthand (not to complicated your design at all)

That should be in the docs!

Done, thanks!

Seems very nice. It's a little odd that the examples include characters that are hard to type on most keyboards.

I'd argue they can be easy to type on most keyboards - just that most people do not enable the functionality and it usually is not enabled-by-default. So not "hard" but "atypical".

On Linux, set up a `Compose key`[0]. That makes `°` become `Compose o o`. If you're on Windows, a useful thing to do is enable the US-International keyboard so that you can more easily type characters with accents, so you can type Pokémon properly. US-International also respects the AltGR/Right alt to compose many characters [1]. For example, I can type ² by pressing AltGr+2 which really is quite easy. I can also type ° by pressing AltGr+Shift+;

[0] https://en.wikipedia.org/wiki/Compose_key

[1] https://en.wikipedia.org/wiki/AltGr_key

I have a German keyboard, which has keys for °,² and ³. I really liked that when I was typing my math homework in high school. It's not really ergonomic for programming though, what with {[]} not being easily reachable. So now I have my keyboard permanently set to US layout, frustrating anyone who expects the key labels to make sense.

You just need a better layout.

However, everything the examples inspired me to try fails. 2² works but 2⁴ fails. 30° works but 30°25′8″ fails. 10×3÷4 fails. ‘pi’ and ‘hbar’ are predefined but ‘π’ and ‘ℏ’ aren't.

Author here, thank you for the feedback! I will try to add these. Tracked here: https://github.com/sharkdp/insect/issues/44

Thank you for the feedback! I have a german keyboard and haven't really considered this. I will try to improve the examples.

Edit: should be fixed now.

the way some other repl improve this is by allowing to tab complete form latex definition. For EG: \habar<tab>, \pi<tab> or 8^2<tab> will expand to what you expect. This also allows for combining like F\vec<tab> of \theta<tab>\dot<tab>

You can also write ^2 instead of ² and "degrees". But yea, a bit weird as an example.

"deg" and "rad" seems to work as well so you don't have to type "degrees" and "radians"

Not to be snarky, but these days Wolfram Mathematica has spoiled me so much that I use it for even simple computations like the ones is meant for. And I almost always already have it open and I don't need to wait for anything to load.

    >  1920/16*9
    >  Sin[30 Degree]
    >  Quantity[2, "Minutes"] + Quantity[30, "Seconds"]
     Quantity[150, "Seconds"]
    >  UnitConvert[Quantity[6, "Megabits"/"Seconds"] *Quantity[1.5, "Hours"], "Gigabits"]
     Quantity[32.4, "Gigabits"]
    >  r = Quantity[80, "Centimeters"]
     Quantity[80, "Centimeters"]
    >  UnitConvert[Pi r^2, ("Meters")^2]
     Quantity[(16 \[Pi])/25, ("Meters")^2]
    >  UnitConvert[Quantity[40000., "Kilometers"/"SpeedOfLight"], "Milliseconds"]
     Quantity[133.426, "Milliseconds"]
It's more verbose to type out the units unless you use the integrated WolframAlpha query with Control-Equal.

  > ln(-1)
  > sqrt(-1)

Would you expect a complex number as an output? I wouldn't, if someone didn't tell me that it supported complex numbers.

From a scientific calculator I would definitely expect complex numbers.

Well, Emacs Calc does (as well as pretty much everything else).

Beyond getting a complex number as output: which complex number? (For example, is `i` or `-i` the correct answer to `sqrt(-1)`? If that seems too easy, how about the correct answer to `sqrt(-i)`?) It would be interesting to see a calculator that handled multi-valued functions properly, but I think that would require some major UI (and possibly even theoretical) advances in order to degenerate gracefully to the single-valued case.

Thank you for the feedback. I'm going to work on this. It is already addressed here: https://github.com/sharkdp/insect/issues/30

this is pretty cool,

    > sqrt(2)

    > sqrt(2)-1.41421

    > 1.00000356237 + 0.0000001

What are the rules you apply when truncating results? number of digits displayed?

    > 3e6 + 0.1
    > 3e7 + 1
    > 3e7 + 1.1
    > 3e7 + 42.9
There might be a bug, 42.9 < 1 ?

Thank you for the feedback!

This is not really a bug, but I agree that it looks quite weird right now. Explanation in this comment: https://news.ycombinator.com/item?id=13918393

This is neat!

One small annoyance is that it captures common browser shortcuts: e.g. Cmd-L on Mac (iirc Ctrl-L on Win/Linux) is a shortcut for the URL which is what I usually use when I want to go to another page. In insect, it just prints an "l" on screen, so I need to use the mouse to navigate elsewhere.

Thank you for the feedback!

Ctrl-L is used to clear the screen (same as in terminals, apparently it does not work for you?), but I agree... I also use Ctrl-L to change the URL. I'll see if I can change it (this is not really part of insect, but jquery.terminal).

You are welcome! :)

Just to clarify: Ctrl-L does clear the screen -- this would have been a problem on Windows, but does not bother me on a Mac; on the other hand, Cmd-L (which is the Mac shortcut for the URL) simply prints an "l".

I see, thanks for the clarification

While you're looking, on Windows, Alt+D also normally goes to the address bar in all browsers, but it gets taken over too.

(And I agree this is very cool, especially the way it handles physical units.)

I've used Calca[0] for a while now; and it computes pretty much anything I throw at it. And while its paradigm is nice for a lot of things (a markdown editor that can also do math), I would love a REPL-style interface to it, for quick commandline calculations, so maybe this will fill that void. However, my initial reaction is that its different enough to make it not worth my while. But it's always good to see other products/tools in the same space.

Oddly enough, the reason I eventually stumbled Calca was trying to find a replacement for qalculate[1].

[0]: http://calca.io/ [1]: https://qalculate.github.io/

This is cool -- is there a distinction between Bytes and bits? That would be useful for performance calculations. Right now, it seems like lower case 'b' is used for bytes and there is no support for bits.

There is: Currently, "b", "byte" and "bytes" is for bytes and "bit", "bits" is for bits.

It would be fun to wrap it in a mobile app and customize it for Siri. You could probably generate some decent input speed considering a phone doesn't have a physical keyboard.

Anyway, nice project.

Nice tool!

  > 6Mbit/s * 1.5h
It seems as though the "h/s" should be resolved and that the result should instead be "4.05Gb", without needing to explicitly specify that the resulting unit should be Gb:

  > 6Mbit/s * 1.5h -> Gb
It would also be nice if "month" and "year" were added. WolframAlpha uses "30 days 10 hours" for a month and 365 days for a year.

> It seems as though the "h/s" should be resolved and that the result should instead be "4.05Gb"

Yes, thank you. This is already tracked here:


> It would also be nice if "month" and "year" were added. WolframAlpha uses "30 days 10 hours" for a month and 365 days for a year.

I thought about it and didn't add it at first, due to the ambiguity. But I guess these values seem like reasonable defaults.

This is quite neat. I tend to just fire up the Python or GNU Units whenever I need some quick math, but it's nice to have something rather consolidated.

You are probably familiar with it already, but in case some readers are not, bc is a nice traditional tool for such things.


I used to use Lua for quick calculations, but I've recently started using R because of operator vectorization.

For conversions, why use GNU Units over, say, Google in your browser? I find that most of my unit conversions happen in my browser, while I'm online. Anecdotal evidence, obviously, but is this not the case for others? Where do most people use unit conversions?

I'm also not an engineer, so I can't take that into account from experience alone. Wouldn't your tooling provide automated conversions into "correct" units?

Oh, I just use Units because I'm used to it, and it has always done the job well. I also like that it's self-contained on my computer, instead of requiring a dependency on the outside world.

You can use GHCi, too.

There's a similar MacOS app called Numi that's a bit more polished.


Soulver is also similar and has been around for longer, although it's paid: http://www.acqualia.com/soulver/

It seems strange to market a scientific calculator as "fast" when processing power hasn't been a limitation since the 1980s. The way to make a scientific calculator faster in a meaningful way is to make the user interface more efficient. Insect doesn't appear to have any innovations in that field.

When I wrote that, I thought of wolfram alpha....

I use Frink for pretty much of this. I keep it open on my desktop and do calcs like:

250 lbf * 1 m/s -> kW

You can put hp or other desired units you require in the answer. It will hint on balancing the equation to make the units physically similar.

  [1]  https://frinklang.org

May also be worth looking at Wolfram open cloud: https://lab.open.wolframcloud.com/objects/wpl/GetStarted.nb

  > sin(pi)
Needs some more work...

Thank you for the feedback! I will try to fix this.

Notice the following:

  > sin(pi)


  > sin(2*pi)


  > sin(3*pi)


  > sin(4*pi)


is proportional to n, and

alternates in sign. This is because your "pi" is really a floating-point number which is slightly more than pi...

Is there a way around this without doing all computation symbolically?

You are absolutely right. I am afraid there is no good solution for the problem except for performing symbolic calculations or simplifications.

A hacky solution could be to round the output of sin(x) to a given internal precision. This would only hide the real internal numerical problem, though.

It seems that other calculators suffer from the same issue: https://www.google.de/search?q=sin(1e10*pi)

For now, I have increased the internal precision to 30 significant digits and updated the value of Pi to be more precise than that. Of course, this doesn't really solve the problem... just shifts it by a few orders of magnitude :-)

Edit: Also, note that everything is fine if the answer is not zero (due to the rounding in the output):

  > sin(pi)+1

Seems very similar to speedcrunch (desktop application)


I wish it was a bit more usable on my phone, where I would most likely find use for an interface like this.

Hm, it wraps weirdly (mid-word) on narrow screens...

> 1/0.999996


The output is currently rounded to six significant digits. In this case, the result is 1,000004.., which is rounded to 1,00000 and displayed as 1. I'm not sure what the best default behaviour would be. Typically, I would say that six sign. digits are more than enough for most applications..

It's great that you use significant digits, but then you have to be explicit about it, and display exactly that many digits, in this case all the zeros (1,00000).

> I would say that six sign. digits are more than enough for most applications

A better solution would be to not use a fixed number of significant digits, but to display the result with the precision of the least precise number the user entered. If you could follow the propagation of uncertainty through the calculations, that would be even better.


PS: Great job anyway, bookmarked, thanks!

Thank you for the feedback!

> It's great that you use significant digits, but then you have to be explicit about it, and display exactly that many digits, in this case all the zeros (1,00000).

Yes, I completely agree from a statistics/physics viewpoint. The reason I display it as `1` right now is that I only have a fixed number of sign. digits (and not the sophisticated solution that you propose - which would be great!). If I always displayed all six digits, one would get `3 - 2 = 1.00000`...

> A better solution would be to not use a fixed number of significant digits, but to display the result with the precision of the least precise number the user entered. If you could follow the propagation of uncertainty through the calculations, that would be even better.

That would be fantastic. I'll look into it.

> PS: Great job anyway, bookmarked, thanks!

I'm glad you like it!

nautical miles / knots would be useful :)

I find it funny that nowadays one seems to need 30 or 40 routers, a few hundred kilometers of cable, some power source, 43 level of abstraction, 30 maintenance engineers around the globe to, well, compute 10 + 5

As somebody who thinks messaging is everything, I must protest this name as bad marketing surrounding a potentially good product. Insects evoke in humans a visceral feeling of disgust and sickness. If my work tools were ever being audited I would not be able to explain to my boss why there I am employing an "insect" in my computer.

First impressions are everything. Please see in "The Psychology of Human Misjudgment" the excellent description of humans' "Influence-from-Mere-Association Tendency." The technical merits of a product will not matter if people can't get past their initial feelings. This is highly inconsiderate.

Until the name is swapped out for a more sensible one, I will not be downloading this software.

There's a certain irony in this rant coming from 'dongslol'.

Well, loldongs was taken!

I agree with you in a sense. Insect is a repl for a scientific calculator. It's hosted on shark.fish. None of those lend indication that it's a repl or used for scientific calculation. That's fine, but neither of them are memorable in their own right if someone wanted to return to it without a bookmark. I don't expect Insect to become a ubiquitous name for college students needing a scientific calculator on the go, but it's a trend/fad/thing that happens with other products who want to break into a certain namespace.



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact