Optimized Python is as good as Julia

If somebody asks whether it is worth to learn another computer language, then usually practical reasons are not the only ones, and fun factor is an important one. For some fun, see seven lines of Julia

As for Python+Numpy vs. Julia for maths. Surely, one gets used to the ubiquitous np. suffix, still it is not good for readability. On the Julia side, the acceptance of unicode makes it possible to write concise readable math:

function i(i₀, ν, ϕ, t)
    ω = π*ν
    return i₀*sin(ω*t + ϕ)
end

– you know how the equivalent of it would look in Python.

2 Likes

I find programs with short variable names much more readable than the “industrial convention” long names.

1 Like

Sure, I totally agree a speed difference like that is not alone a reason to switch programming languages and it’s also not going to be a reliably reproduced number.

I’m just saying it’s not nothing, and I disagree with the original phrasing of the post that says that since julia is only 1.5-2x faster than Numpy here, they’re “just as good”.

1 Like

You can do this in Python though too, right? I have a program now with a µs for microseconds.

2 Likes

yes, indeed, my bad. Though I think not everything - i₀ appears not possible.

What about the mathematical function names (np.sin etc.?)

At least 7x faster is a good reason to use Julia (in not “only 1.5-2x faster than Numpy”), and likely it can be improved further.

For your “two”- or four-line example, I would actually rather show off the concise one-line possibility of defining a function in Julia:

i(i₀, ν, ϕ, t) = i₀*sin(π*ν*t + ϕ)  # or even for more accuracy and speed: = i₀*sinpi(ν*t + ϕ*(1/π))

Or if you take a closer look at ideal which is simply 1:n then it could be

count(splat(==), enumerate(hats))

Eliminating ideal at all

2 Likes