Live data from Hacker News

Julia as a CLI Calculator

krasjet.com

11–20 of 134 posts

Re: Julia as a CLI Calculator

#11
post #4
post #3

I love the julia language. I would love to use julia as a command line calculator. Unfortunately, starting the interpreter is excruciatingly slow, an order of magnitude slower than octave or python (and several orders of magnitude slower than bc or dc).

One way to alleviate the slowish startup is to use PackageCompiler.jl (discussed at the end of the article https://krasjet.com/rnd.wlk/julia/#packagecompiler.jl ). I like that there's more than just the standard calculator operations available at the REPL, but I can see why you wouldn't use it if you don't need it and bc satisfies your needs.

I remember years ago when caching was about to be integrated in the next version and be here in a few weeks. Now it has been half a decade of people complaining about how slow it is for his to keep recompiling the same thing over and over.

Re: Julia as a CLI Calculator

#12
post #6
post #5

Earlier quoted context omitted.

Simply loading the REPL takes half a second for me. I use it all the time as a simple calculator.

> Simply loading the REPL takes half a second for me. I juse it all the time as a simple calculator. Half a second is precisely what is meant by "excruciatingly slow". If I need a simple calculator, I expect to be able to use it to compute intermediary results in a shell loop. If my loop has one thousand iterations, you are spending about 10 minutes just initializing the interpreter. This is absurd. Of course, you ca…

Well, we have different ideas of calculators then.

Re: Julia as a CLI Calculator

#13
post #10

A problem with Julia is that it does not parse input numbers with arbitrary precision by default. Example: julia> sin(1.461920290375737576933544899379e+31) -0.9468766486679395 julia> sin(parse(BigFloat, "1.461920290375737576933544899379e+31")) 0.6864670207863400975666631018263839509022548965872940746039593018855528710432756 Fricas is better in this regard, some links: https://en.wikipedia.org/wiki/FriCAS https://fric…

This is unlikely to be a problem for the vast majority of people using julia as a calculator

Re: Julia as a CLI Calculator

#14
post #6
post #5

Earlier quoted context omitted.

Simply loading the REPL takes half a second for me. I use it all the time as a simple calculator.

> Simply loading the REPL takes half a second for me. I juse it all the time as a simple calculator. Half a second is precisely what is meant by "excruciatingly slow". If I need a simple calculator, I expect to be able to use it to compute intermediary results in a shell loop. If my loop has one thousand iterations, you are spending about 10 minutes just initializing the interpreter. This is absurd. Of course, you ca…

that sounds like a case where it would be best to pipe stuff into julia and read the output.

or hack up a daemon-process thing where you can start it up outside the loop, then call it inside the loop

Re: Julia as a CLI Calculator

#15
post #10

A problem with Julia is that it does not parse input numbers with arbitrary precision by default. Example: julia> sin(1.461920290375737576933544899379e+31) -0.9468766486679395 julia> sin(parse(BigFloat, "1.461920290375737576933544899379e+31")) 0.6864670207863400975666631018263839509022548965872940746039593018855528710432756 Fricas is better in this regard, some links: https://en.wikipedia.org/wiki/FriCAS https://fric…

This is unlikely to be a problem for the vast majority of people using julia as a calculator

The problem is that you won't know when your results are wrong because of low input precision. And when you do know, things will be a bit more complicated.

Re: Julia as a CLI Calculator

#16
post #10

A problem with Julia is that it does not parse input numbers with arbitrary precision by default. Example: julia> sin(1.461920290375737576933544899379e+31) -0.9468766486679395 julia> sin(parse(BigFloat, "1.461920290375737576933544899379e+31")) 0.6864670207863400975666631018263839509022548965872940746039593018855528710432756 Fricas is better in this regard, some links: https://en.wikipedia.org/wiki/FriCAS https://fric…

You can do julia> big"1.461920290375737576933544899379e+31" 1.461920290375737576933544899379e+31

    julia> sin(big"1.461920290375737576933544899379e+31")
     0.6864670207863400975666631018263839509022548965872940746039593018855528710432756

to succinctly parse arbitrary precision literals.

Re: Julia as a CLI Calculator

#17
post #3

I love the julia language. I would love to use julia as a command line calculator. Unfortunately, starting the interpreter is excruciatingly slow, an order of magnitude slower than octave or python (and several orders of magnitude slower than bc or dc).

Besides the other suggestions, you can do things like start julia using the --compile=min or -O0 command line flags to reduce / eliminate compilation overhead and make it startup quicker.

The beta version of version 1.5.0 starts up in 0.25 seconds with --compile=min and I believe it's the same on 1.4.0

Re: Julia as a CLI Calculator

#18
Since this is a calculator topic, I'd like request your input on which calculators you use.

I use the Emacs calculator (M-x calc) and XCalc (http://www.tordivel.no/xcalc/) as I like to use RPN calculators. The Windows 10 calculator is painful and slow. XCalc has a mini mode, where it will sit as a small, single line without distracting you too much. I like that feature very much.

One thing with Emacs is that I forget the shortcuts for non-frequent calculations that I'd have to go and search for it.

Re: Julia as a CLI Calculator

#20
post #19

I use python CLI for exactly the same :)

I used to use Python REPL for that until I switched to fish shell. Now I just run

    $ math "999.999 / 3"
    333.333
Granted, I don't really do any complex calculations in my terminal.
Post reply on HN