Try Julia
forio.com
forio.com
julia> 3 ** 60
syntax: use ^ instead of **
julia> 3 ^ 60
-3535985420588157519
julia> factorial(45)
-8797348664486920192
julia> factorial(75)
0
julia> 5 * 5555555555555555555
-9115710369641325457
julia> 5 * 55555555555555555555
syntax: invalid numeric constant 55555555555555555555
This isn't C. The expectations have changed thanks to scripting languages. If I'm supposed to use this promising language to do calculations and manipulate data, I'd expect to be able to natively handle large numbers without overflowing.See also: http://www.johnmyleswhite.com/notebook/2013/01/03/computers-...
No, but that also means Julia isn't much special then either right?
Maybe it is just me but Julia positions itself as a better Python not just a better C, in that position, can you really blame people if they misunderstand and expect same "high level" behavior from it?
That's a really dumb conclusion. It's special in other things it offers (from a better Matlab like language with crazy ass speed to homoiconicy and great FFI). Who said it's only special if it fulfils some specific rainbow-unicorn pipe dream?
It also doesn't read the programmer's thought -- so not special in that regard either.
>Maybe it is just me but Julia positions itself as a better Python not just a better C, in that position, can you really blame people if they misunderstand and expect same "high level" behavior from it?
Lots of people also find Go a "better Python", and Go is like assembly compared to Julia...
(defun double (x)
(+ x x)) ; BigInts (or floats, for that matter)
(defun double (x)
(declare (type fixnum x))
(+ x x)) ; will emit an error if X is more than a long
(defun double (x)
(declare (type fixnum x)
(optimize speed (safety 0)))
(the fixnum (+ x x))) ; trusts that everything is a long - basically like CScientific programmers don't expect a behavior different than Julia's from a modern language.
>I understand that things get trickier when trying to implement arbitrary-precision arithmetic while keeping performance high.
It's not merely "trickier". It's impossible to be fast enough.
The question is why aren't large numbers the default, or why doesn't it do automatic up and down conversion and so on.
Scientific languages generally don't use aribitrary precision arithmetic. Examples: MATLAB, scipy/numpy/pandas. The reason is that they're optimized for the key use case of large linear algebra calculations. Making arbitrary precision the default would require an overflow or type/tag test in the inner loop dramatically reducing performance. The goal of these languages is to operate at near peak cpu bandwidth.
When wide ranging precision is needed floats are used despite their flaws, because again, the performance matters so much. FEM, CFD and similar engineering calculations can effectively use as much computation as you have hardware and patience for. Machine Learning will too if you're dataset is larger than trivial.
The Julia folks know what they're doing and it's what the community they're targeting expects.
http://docs.julialang.org/en/latest/manual/faq/#why-does-jul...
Julia defaults to what is fast on your machine. If you want to use BigInt you can do so but it doesn't do so by default.
You can also use 128bit integers in Julia. Example: rand(Int128, 10)
julia> 55555555555555555555
55555555555555555555
julia> typeof(55555555555555555555)
Int128
julia> typeof(5555555555555555555555555555555555555555)
BigInt (constructor with 7 methods)You have to convert to BigInt or BigFloat like this:
julia> big(3) ^ 60
42391158275216203514294433201In any case. If you think of it as a nicer C, it works very well. It is a slight disappointment if you think of it as a nicer Python.
I try to use Julia instead of Python now if I don't need specific libs, it definitey feels like a nicer language to me (i.e. I can get stuff done faster).
It seems like in the last week it just started popping up on HN every couple days.
As a general question, is Julia Studio the best way to go about setting up a workflow? Or should I go with something like a Julia plugin for Sublime Text (which I believe exists). Or are there any other tools out there that make Julia dev straightforward?
Not directly related to performance, but you might be interested in this: https://github.com/helgee/JPLEphemeris.jl
That JPL Ephemeris library has given me an idea. I think I might try porting over the NAIF Spice [1] toolkit to Julia. It has MATLAB, IDL, C and FORTRAN ports so I think Julia would fit right in there.
I'm becoming increasingly convinced that Julia is the future of technical computing. We've just started pulling together a BioJulia team - if anyone is interested drop an email (in profile).
If and when they're right, they can smugly point out how forward thinking they were.
- Lisp-like macros and other metaprogramming facilities
- It's a general purpose language
- Multiple dispatch
- Designed for parallelism and distributed computation
In Clojure it's hard to write imperative code, which was one of the reasons I've left. Sometimes, imperative programming is the best way to code something. Sometimes it's best to do it in a functional way. Julia can do both.
The same is true for mutability. I understand the advantages of immutability but I think it's overhyped. Besides the obvious advantage of mutability - performance - it sometimes makes for more readable and shorter code. And what if you have some complex nested state and need to change a small part of it?
BTW - what do you mean by functional programming exactly, how does it differ from imperative programming in your view?
There are several options, I chose the one with sudo gedit /etc/apt/sources.list and
1514 sudo gedit /etc/apt/sources.list 1515 sudo apt-get update #not needed 1516 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3D3D3ACC 1517 sudo apt-get update 1518 sudo apt-get install julia (there are broken dependencies) 1519 sudo apt-get install libopenblas-base 1520 sudo apt-get update 1521 sudo apt-get install libopenblas-base 1522 sudo apt-get install libatlas-base-dev 1523 sudo apt-get install libopenblas-base 1524 sudo apt-get install julia 1525 julia 1526 history | tail 1527 history | tail -n 20
Julia's standard library includes a host of mathematical functions, in addition to the standard operators. Complex numbers are also supported, using the built-in im unit:
round(pi)
lcm(54, 392, 232) # least common multiple
sqrt(square(100))
e^(pi * im)
log(e ^ 2) + log10(100)
When you're ready, type "next" to continue
julia> round(pi)
no method round(MathConst{:π},)This issue was also reported at https://github.com/JuliaLang/julia/issues/5561
function foo()
return 42
end
function bar()
return foo()
end
Evaluating bar() gives 42, just as one would expect.Now let's redefine foo():
function foo()
return 69
end
Evaluating bar() still gives 42!Not getting something so basic correct tells me to avoid the whole thing for fear of getting subtly screwed by some other oversight. Actually, oversight isn't the right word, since broken automatic compilation has been a known problem for two years: https://github.com/JuliaLang/julia/issues/265.
And these people expect to be taken seriously? Sell crazy someplace else, we're all stocked up here. The honest approach would be to forbid redefining functions.
This issue was brought to my attention by pals who had investigated Julia and rejected it for this very reason. No way I'll use it for anything. And that will be my recommendation to anyone who asks me about it.
You should pick different advisors.
It's funny: I've forwarded this issue to several pals with experience in language & compiler design, and to a man they were dismayed that something so basic was going unfixed or was even broken in the first place.
You're not supposed to rename functions in your code -- are you kidding me you're hang up on this?
I'm running Emacs with a split window for development. R runs in the bottom window, and the source file I'm editing is in the top. This lets me send code to R for evaluation and supports an incremental style of development. I'll slowly build up functions, and this sometimes requires editing functions that my current function uses. This style of development is typical for people using R, Matlab, Lisp, or any language featuring a REPL. But you can't do it in Julia.
Julia needs to support this style of development if it's to garner support from people using these languages. Full stop.
And the fact that Julia doesn't support updating functions makes me think that something is very broken down in the core of the language. The tone of the GitHub thread is: "We don't know how to fix this." Scary!
https://gist.github.com/anonymous/8656066
> I'm running Emacs with a split window for development. R runs in the bottom window, and the source file I'm editing is in the top. This lets me send code to R for evaluation and supports an incremental style of development. I'll slowly build up functions, and this sometimes requires editing functions that my current function uses. This style of development is typical for people using R, Matlab, Lisp, or any language featuring a REPL. But you can't do it in Julia.
This is what everyone does in Julia too, with Emacs, IJulia, and others. Here is how to do it: put "module X" at the beginning of your file, and an extra "end" as the last line. Each time you send the file to Julia, the module is recompiled, and inter-dependent functions are updated to the latest version. Problem solved. This is mentioned (in a slightly different context) in the FAQ:
http://docs.julialang.org/en/release-0.2/manual/faq/#how-can...
But I admit it's not immediately obvious, and we should probably put it front-and-center somewhere.
No, the authors should fix automatic recompilation. It's difficult for me to imagine how this bug even exists. The fact that it does coupled with the excuses and blaming the messenger surrounding it tells me that the authors don't know what they're doing and that I should steer clear for fear of running into similar flaws.
Good luck!
I'm reminded of how some Python devotees are unable to see how the v2.7/v3.x split turns of newcomers. The impression given is that the community can't make up its mind on which way to go and that the best approach is to avoid the language all together.
I'd suggest you slow down on the entitlement.
No one denies that this is a problem, and it will be fixed. But I disagree that it represents a fundamental flaw. For iterative development, it is a minor inconvenience, so other priorities have taken precedence. If you are redefining functions in this way in tested code, there may be bigger problems to worry about.
The Julia developers have paid fastidious attention to correctness (to the point of making a pilgrimage to visit Kahan early on). The type system is well thought-out and nice to use. Spurious crashes are almost nonexistent (and fixed within hours, without fail). The foundation is solid, but it's still a work in progress, and it will take some time to shake these sorts of features out.
But when I can write a nine-line example that produces incorrect output—no thanks. Especially when one of the lead developers (see the linked thread) states that supporting function redefinition isn't needed for v1.0. Clearly these people are working under a very different set of priorities than me.
"The foundation is solid"—I do not think it means what you think it means.
Yes, they are pragmatists.
Plus they know that the language is the first priority, not the REPL.
What does that mean?
proportion_value = x ./ sum(x)
The blocker for me with julia is translating my vectorized way of thinking into loops. I know the loops are optimized, but yuck.
julia>function haz(n) s = 0 for i in 1:n if i % 2 == 0 s = s+1 else s = s-1 end end s end haz (generic function with 1 method)
julia> @elapsed haz(10^8) 0.12459633
Compare with lisp sbcl on the same machine:
(defun haz(n) (let ((s 0)) (declare (optimize (speed 3) (safety 0)) (fixnum n s)) (loop for i fixnum from 1 upto n do (if (zerop (mod n 2)) (incf n) (decf n)) finally (return s))))
"I can do things I needed C to do before, and almost as fast"
which leads me personally to ask,
If you could do this in C before, and faster, then why are you switching?
Most people will say "because C is bad/difficult/clumsy for doing X"
which leads me to say,
why are you using C to do X?
I sincerely believe (as a computational scientist) that a combination of a high-level language for real-time interactive exploration and prototyping with a fast language like C for doing the actual gruntwork, is the best.
Attempts to combine the best of C (speed) with the best of scripting languages (easy to do things fast without having to pay attention to what you are doing) in my opinion end up merely joining the worst of both worlds rather than the best of both worlds.
Besides isn't programming about being specific? Do you really want to code stuff without having to worry about the details?
People only ever used C when speed was crucial and depending on what you were comfortable in or what you had learned maybe Fortran for speed instead of C.
Julia is meant for scientific computing with some nice features. As I see it it is similar enought to Matlab to be easily learned by those who use Matlab but has enough goodies that it can be a viable alternative.
Programming isn't about being specific it is about accomplishing a task and many times yes you don't want to have to worry about the details as long as it works the way it should.
Anyway I'm all in favour of an open, fast MATLAB alternative
Converting to C can take a LOT of time, and is an order of magnitude less enjoyable than Julia. What about maintaining the code, making improvements, integrating with other code? And what if the prototyping needs too be fast too? It can become a massive pain in the ass. Why should I undergo that if I can just use Julia?
> Attempts to combine the best of C (speed) with the best of scripting languages (easy to do things fast without having to pay attention to what you are doing) in my opinion end up merely joining the worst of both worlds rather than the best of both worlds.
I've used both Julia and C and I think it's the exact opposite, it combines the best of both worlds.
Because they know C, it's fast and it has lots of libs available. They might also dislike Java or CL.
Not every engineering decision is perfect, lots of factors play in.
>Attempts to combine the best of C (speed) with the best of scripting languages (easy to do things fast without having to pay attention to what you are doing) in my opinion end up merely joining the worst of both worlds rather than the best of both worlds.
The "pay attention" things is to needless complexity (memory management etc). They only reason we put up with those things was to get speed. If we can get adequate speed without those, nobody cares about them.
>Besides isn't programming about being specific? Do you really want to code stuff without having to worry about the details?
No, programming is about getting results. Nobody cares about the details in the level of programming language minutuae.
We care about the "effort put in" and "quality/speed of results coming out" ratio.
julia++, i started playing with it this weekend and i'm super pleased. i concur with another comment in this discussion that this is what i wish python had been evolving into. it gets me wondering if python is maybe being left behind compared to other dynamic languages or if it's just fad-ism at work (or me just learning more about languages and features).
Undefined
500
Is this broken?