Live data from Hacker News

Julia as a CLI Calculator

krasjet.com

91–100 of 134 posts

Re: Julia as a CLI Calculator

#91
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…

For a "computational math" (ish) language, having FP64 as the default number format seems pretty reasonnable to me. Cases where one needs bignums of course exist, but I think they are less common. Usually if you need arbitrary precision, you know it.

Re: Julia as a CLI Calculator

#92
post #76
post #68

The typography in this post is beautiful (as well as the content), anybody know where this comes from? Did the author do it by hand or is it something off the shelf? Asking for a friend...

The styling is done from scratch. For more information, see the colophon [1] and karasu [2]. [1]: https://krasjet.com/colophon/ [2]: https://github.com/Krasjet/karasu

Nice job!

Re: Julia as a CLI Calculator

#93
post #44

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 forg…

As a RPN calculator user, my first choice is XCalc ( http://www.tordivel.no/xcalc/ ). The non-RPN one that I use the most is SpeedCrunch ( http://speedcrunch.org/ ), Insect ( https://github.com/sharkdp/insect/ ) and Frink ( http://frinklang.org/ ). All have unit conversion too.

Frink is my tool of choice for computing, despite it bit esoteric.

Re: Julia as a CLI Calculator

#94
post #47

I use Mathematica as my advanced calculator. It’s a functional language with an extremely vast and consistent mathematical and non-mathematical library, top notch symbolic capabilities (SymPy is just child’s play in comparison), top notch numerical capabilities, and very decent performance. You certainly don’t need to write your own rotation function — well, 2D rotation is trivial, but what if you want 3D rotation ar…

I know it's a very general question, but can I ask what sort of calculations you perform using Mathematica? Every time it has a new release, I download the demo and play around with it, but I never get as far as using it to actually compute anything that other CLI calculators couldn't do.

Re: Julia as a CLI Calculator

#95

Earlier quoted context omitted.

Maybe you'd like str |> x->parse(Int,x) |> abs ? >I like when the code reads like a sentece, it's just less mental overhead. But the OOP version is further from a real sentence here. You're taking the absolute value of the string parsed as an integer, not "for the string grabbing the parser to apply the change to an integer to take the absolute value".

I think they're both equally correct, though the UFCS/pipe syntax is mentally easier to follow. Let's say someone told you (making up random stuff): "The absolute value of the sum of the mean of the square of two vectors mapped over the product of X and Y." Try to think about that in your head. By the time you've reached the end of the sentence, there have been so many steps and no context values that you can't even…

>"The absolute value of the sum of the mean of the square of two vectors mapped over the product of X and Y."

abs(sum(mean(abs2,x .* y)))?

Re: Julia as a CLI Calculator

#96

Earlier quoted context omitted.

> Oof, beauty is in the eye of the beholder. I guess that's true, from my experience Julia's way is simply less readable. It also make IDE autocomplete much more useful. > A lot of relevant math is 1-indexed. Initially I kind of liked it and disagreed with people who didn't. But as I used Julia over time, I regularly encountered situations in which it was really frustrating and enacted a mental tax. The opposite neve…

> But as I used Julia over time, I regularly encountered situations in which it was really frustrating and enacted a mental tax. The opposite never happens. The opposite would be true for a large swath of people coming from scientific computing backgrounds if Julia defaulted to 0-based indexes. That said, in my experience people doing scientific computing have a poorly calibrated sense of what constitutes “hard.” I’m…

I've encountered a few pieces of math that are more naturally expressed in 0-based indexes and it is pretty easy to define them in Julia using arbitrary indexing.

TaylorSeries.jl is a great example of this. x = x_0 + x_1 t + ... Then indexing into it with x[0] would give the zero-th order Taylor coefficient.

Re: Julia as a CLI Calculator

#97
post #94
post #47

I use Mathematica as my advanced calculator. It’s a functional language with an extremely vast and consistent mathematical and non-mathematical library, top notch symbolic capabilities (SymPy is just child’s play in comparison), top notch numerical capabilities, and very decent performance. You certainly don’t need to write your own rotation function — well, 2D rotation is trivial, but what if you want 3D rotation ar…

I know it's a very general question, but can I ask what sort of calculations you perform using Mathematica? Every time it has a new release, I download the demo and play around with it, but I never get as far as using it to actually compute anything that other CLI calculators couldn't do.

I’m a physicist so all kinds of numerical and symbolic calculations, e.g. very complicated integrals, differential equations, integral equations, and so on. I also work on math problems either seriously (way back when I was an undergrad I worked on some number theoretical problems where computational insight is very important) or for fun (think Project Euler style problems).

If you just need to a calculator to do everyday arithmetic or unit conversions, or even simple physics calculations with units, it’s serious overkill... I certainly hardly ever need it when I’m wearing my programmer hat.

I guess to answer is that the boundary between a calculator and a full blown computational environment is very blurry to me.

Re: Julia as a CLI Calculator

#98

I really wish there was a language based on Swift that would include most of the nice language, REPL and library characteristics of Julia (and perhaps few from Dart). That would get really close to a "perfect language" for me. Overall I like Julia - and use it as a CLI calculator as well - but there are several things that prevent it from being a good general purpose language: - OOP support is "meh". - str.parse(Int)…

crop(resize(first(images), 100, 100), 25, 25, 75, 75) this will likely get better when julia implements proper pipes, IIRC coming soon in the plans (like elixir does): images |> first |> resize(100,100) |> crop(25, 25, 75, 75) If the language bothers to implement an inspect method (again, like elixir) this is vastly superior to . chaining because you can do this: images |> inspect |> first |> inspect |> resize(100,10…

I'm not sure what `inspect` does, but can you clarify what you mean by proper pipes?

  julia> x = [3,2,4,5]
  4-element Array{Int64,1}:
   3
   2
   4
   5

  julia> x |> sort |> x->reshape(x,(2,2))
  2×2 Array{Int64,2}:
   2  4
   3  5
works.

It gives a syntax error if the pipes are on the newline. Is that your gripe?

Or is it that it doesn't automatically partially apply the function, requiring you to use an anonymous function, like `x->reshape(x,(2,2))` instead of as you have it `resize(100,100)` implicitly. I prefer the explicitness.

Re: Julia as a CLI Calculator

#99
My main calculator is gnu calc which is the calculator built into emails. It tends to hit various ceilings where it can’t go much further but it has lots of nice features:

1. The data I want to work with tends to be in my text editor so it makes sense to have the calculator there too. Macros can be used to fix up formatting to input numbers

2. Speed of input makes it so much nicer to use. If I look at the examples in the article, here is a comparison. Julia:

  7 / 4
  x = ans + 2 im 
  exp(x)
  A = [...]
  A * [...]
  [a^2 for a \in A]
Emacs:

  7 RET 4 /
  (0,2) + s t x (but I probably wouldn’t use a variable)
  s r x E (if I used the stack this is just “E”)
  [(same but RET or , not SPC)] s t A
  s r A [...] *
  s r A V M I Q (that’s vector map inverse square root)
These examples make emacs look bad because I’ve replicated saving things to variables it actually I’d just use the stack. I guess in Julia you can press the up arrow. There are other examples like 1 |> exp |> sin is just 1 E S in Calc (and those operations broadcast over vectors automatically, although I think emasculated does the right thing and doesn’t broadcast exp over matrices).

Skipping the massive tangent of non-calculator things about Julia, we move on to a discussion of plotting. There isn’t a Unicode-art plotting mode in emacs because we have had graphical terminals for over 30 years. In emacs you plot with g f and can then modify your plot with other commands. In just about every language you need to call a function called plot so you’re already losing on characters before you’ve even started. If plotting is fast and easy then exploration is easy.

3. The calculator has lots of useful features that fit well together. Plotting is built in. As are unit conversions, a bunch of symbolic algebra (simplification, differentiation, basic integration, curve fitting, solving equations, numeric integration/solutions, and a super nice facility for editing expressions). There’s a bunch of other functions for stats, vectors (both linalg and things like map/reduce), number theory, physics, etc. There are language modes for things like latex output too. Most stuff works on a bunch of number types (bigints, rationals, arbitrary precision floats, infinity, intervals thereof, complex numbers, error forms, symbolic expressions, dates)

4. I want to reiterate the point about speed. The thing I care about being fast is telling the computer what to do. It takes basically 0 time to do most mathematical operations so latency is dominated by input. So even though emacs uses interpreted emacs lisp and doesn’t even use hardware floating point numbers, it still feels faster than Julia with its optimising JIT. If I want to do something with a large amount of data then I can either wait a few seconds or realise that I’ve gone beyond calculator work and use something better suited.

I think Julia is a great language and it has great advantages over emacs for numerical computing. A big one is that the language and type system is much more naturally extensible for this sort of thing. But I don’t feel that it makes a particularly good calculator. The main reason to think that it is a good calculator is that the alternatives (bash/bc/python/matlab) are so bad.

Post reply on HN