
Insect: a fast, repl-style scientific calculator - curtis
https://shark.fish/insect/
======
mjn
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
        4m
    

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
        4m·min/s
    

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
        240m
    

But it'd be convenient to automatically get these kinds of simplifications,
especially when dealing with more complex expressions.

~~~
sharkdp
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](https://github.com/sharkdp/insect/issues/37)

------
msutherl
Since Numi <[https://numi.io/>](https://numi.io/>) has become slow to launch –
and I find Soulver
<[http://www.acqualia.com/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.

[https://gist.github.com/msutherl/b2ab6d5ae7454ea1a987ee85385...](https://gist.github.com/msutherl/b2ab6d5ae7454ea1a987ee85385d8c3d)

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

~~~
msutherl
[https://numi.io/](https://numi.io/),
[http://www.acqualia.com/soulver/](http://www.acqualia.com/soulver/)

------
socialist_coder
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

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

    
    
      > 5+20
      25
      > ans+10
      35

~~~
socialist_coder
That should be in the docs!

~~~
sharkdp
Done, thanks!

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

~~~
kps
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.

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

------
kccqzy
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
         1080
        >  Sin[30 Degree]
         1/2
        >  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.

------
tempodox

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

Hmmm...

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

~~~
jhlgkhkhil
From a scientific calculator I would definitely expect complex numbers.

------
vmarsy
this is pretty cool,

    
    
        > sqrt(2)
        1.41421
    
        > sqrt(2)-1.41421
        0.00000356237
    
        > 1.00000356237 + 0.0000001
        1
    
    

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

    
    
        > 3e6 + 0.1
        3000000
        > 3e7 + 1
        30000001
        > 3e7 + 1.1
        30000000
        > 3e7 + 42.9
        30000000
    

There might be a bug, 42.9 < 1 ?

~~~
sharkdp
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](https://news.ycombinator.com/item?id=13918393)

------
xixi77
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.

~~~
sharkdp
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).

~~~
xixi77
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".

~~~
sharkdp
I see, thanks for the clarification

------
32bitkid
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/](http://calca.io/) [1]:
[https://qalculate.github.io/](https://qalculate.github.io/)

------
lend000
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.

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

------
WhitneyLand
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.

------
pveierland
Nice tool!

    
    
      > 6Mbit/s * 1.5h
      9Mbit·h/s
    

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
      4.05Gb
    

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.

~~~
sharkdp
> 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:

[https://github.com/sharkdp/insect/issues/37](https://github.com/sharkdp/insect/issues/37)

> 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.

------
tombert
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.

~~~
popinman322
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?

~~~
tombert
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.

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

[https://numi.io](https://numi.io)

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

------
wtallis
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.

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

------
eggy
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

------
dallamaneni
May also be worth looking at Wolfram open cloud:
[https://lab.open.wolframcloud.com/objects/wpl/GetStarted.nb](https://lab.open.wolframcloud.com/objects/wpl/GetStarted.nb)

------
otnaktut

      > sin(pi)
      -3.73566e-20

Needs some more work...

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

~~~
madcaptenor
Notice the following:

    
    
      > sin(pi)
    
      -3.73566e-20
    
      > sin(2*pi)
    
      7.47132e-20
    
      > sin(3*pi)
    
      -1.1207e-19
    
      > sin(4*pi)
    
      1.49426e-19
    

So

    
    
      abs(sin(n*pi)) 
    

is proportional to n, and

    
    
      sin(n*pi)
    

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?

~~~
sharkdp
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)](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
      1

------
partycoder
Seems very similar to speedcrunch (desktop application)

[http://speedcrunch.org/](http://speedcrunch.org/)

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

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

------
wmblaettler
> 1/0.999996

1

~~~
sharkdp
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..

~~~
tata12345
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.

[https://en.wikipedia.org/wiki/Propagation_of_uncertainty](https://en.wikipedia.org/wiki/Propagation_of_uncertainty)

PS: Great job anyway, bookmarked, thanks!

~~~
sharkdp
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!

------
zeropoint46
nautical miles / knots would be useful :)

------
wiz21c
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

------
dongslol
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.

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

~~~
dongslol
Well, loldongs was taken!

