[HN Gopher] Calculus with Julia
       ___________________________________________________________________
        
       Calculus with Julia
        
       Author : barrenko
       Score  : 113 points
       Date   : 2024-05-18 19:24 UTC (3 hours ago)
        
 (HTM) web link (jverzani.github.io)
 (TXT) w3m dump (jverzani.github.io)
        
       | jagged-chisel wrote:
       | PDF link in the page header is 404
        
         | mhd wrote:
         | I assume they turned it off intentionally:
         | 
         |  _" These notes may be compiled into a pdf file through Quarto.
         | As the result is rather large, we do not provide that file for
         | download. For the interested reader, downloading the
         | repository, instantiating the environment, and running quarto
         | to render to pdf in the quarto subdirectory should produce that
         | file (after some time)."_
        
       | dfee wrote:
       | I skipped around in the book a bit and found it interesting. I'd
       | consider encouraging my kids to learn calculus this way.
       | 
       | However, I am curious about the first paragraph of the preface:
       | 
       | > Julia is an open-source programming language with an easy to
       | learn syntax that is well suited for this task.
       | 
       | Why is Julia better suited than any other language?
        
         | blagie wrote:
         | This is a good overview:
         | 
         | https://computationalthinking.mit.edu/Spring21/
         | 
         | The very short story is that it's a language somewhat similar
         | to Python (and, likewise, easy-to-use), but with much richer
         | syntax for expressing mathematics directly.
         | 
         | It also has richer notebooks. The key property is that in
         | python notebooks, you run cells. In julia notebooks, it handles
         | things like dependencies. If I change x, either as a number or
         | a slider, all the dependencies things update. You can define a
         | plot, add sliders, and it just works.
         | 
         | (Also: I'm not an expert in Julia; most of my work is in Python
         | and JavaScript. I'm sure there are other reasons as well, but
         | the two above come out very clearly in similar courses)
        
         | patagurbon wrote:
         | Julia inherited a lot of MATLAB DNA like standard library
         | linear algebra and 1 based indices. In addition it's got very
         | commonly used Unicode support and intentionally can look like
         | pseudocode in many cases.
        
         | dnfsod wrote:
         | I also clicked around and felt the formatting of the book was a
         | bit confusing, but found some of the Julia features intriguing.
         | (like "postfixing" allowing the same pencil notation of f' and
         | f'' et al)
         | 
         | In my opinion, and experience, the best "calculus book" is
         | Learn Physics with Functional Programming which only relies on
         | libraries for plotting.
         | 
         | https://www.lpfp.io/
         | 
         | > Why is Julia better suited than any other language?
         | 
         | Julia is known as a "programming language for math" and was
         | designed with that conceit steering a lot of its development.
         | 
         | Explicitly it supports a lot of mathematical notation that
         | matches handwritten or latex symbols.
         | 
         | Implicitly they may be referencing the simplified (see
         | Pythtonic) syntax, combined with broad interoperability (this
         | tutorial uses SymPy for a lot of the heavy lifting), lots of
         | built in parallel computing primitives, and its use of JIT
         | compilation allowing for fast iteration/exploration.
        
         | jakderrida wrote:
         | I'm just guessing, but:
         | 
         | 1. Open Source.
         | 
         | 2. Easy to learn. (kind of)
         | 
         | 3. Robust plotting and visualization capabilities, which are
         | integral (I f*cking swear no pun intended) to understanding
         | calculus, the foundational purpose of calculus being to find
         | the area under the curve. (something I really wish they told me
         | day one of Pre-Calc)
         | 
         | 4. This one is just a vague feeling, but the fact that Python's
         | most robust Symbolic Regression package, SymPy, relies on
         | running Julia in the background to do all the real work
         | suggests to me that Julia is somehow just superior when it
         | comes to formulas as opposed to just calculations. IDK how,
         | though.
        
           | constantcrying wrote:
           | 1-3 apply exactly the same to python, 4 is just false, SymPy
           | is written in python, it has nothing to do with Julia.
        
             | patagurbon wrote:
             | They're thinking of PySR but you are right on all points!
        
         | constantcrying wrote:
         | >Why is Julia better suited than any other language?
         | 
         | Because it is a language specifically targeted for doing
         | numerical analysis.
         | 
         | Python, which is it's main "competitor" has a notoriously poor
         | syntax for mathematical operations with miniscule standard
         | library support for mathematics, a very limited type system and
         | abysmal runtime performance. Julia addresses all of these
         | issues and gives a relatively simple to read language, which
         | often closely resembles mathematical notation and has quite
         | decent performance.
        
           | mgaunard wrote:
           | "its" not "it's"
           | 
           | numpy has similar syntax to MATLAB and Julia
           | 
           | Python's type system is pretty rich and allows overloading
           | all operators
        
             | constantcrying wrote:
             | >numpy has similar syntax to MATLAB and Julia
             | 
             | Numpy has absolutely awful syntax compared to Julia or
             | MATLAB. It is fundamentally limited by pythons syntax,
             | which was never meant to support the rich operations you
             | can do in Julia.
             | 
             | I have done quite a bit in both languages and it is
             | extremely clear which language was designed for numerical
             | analysis and which wasn't .
             | 
             | >Python's type system is pretty rich and allows overloading
             | all operators
             | 
             | The language barely has support for type annotations. Duck
             | typing is actually a very bad thing for doing numerical
             | analysis, since you actually care a lot about the data
             | types you are operating on.
             | 
             | Pythons type system is so utterly inadequate that you need
             | an external library to have things like proper float types.
        
             | patagurbon wrote:
             | I would argue that default element-wise operations and 0
             | based indexing can lead to a lot of cognitive overhead vs
             | the "more math-y" notation of MATLAB or Julia. And
             | overloaded operators like block matrix notation or linear
             | solves are much closer.
             | 
             | The type system in Julia is perhaps even better than MATLAB
             | for some linear algebra operations (a Vector is always a
             | Vector, a scalar is always a scalar). But the Python
             | ecosystem is often far superior to both, and MATLAB has
             | toolboxes which don't have equivalents in either other
             | language. Julia has some uniquely strong package ecosystems
             | (autodiff to some extent, differential equations,
             | optimization), but far fewer.
        
         | staplung wrote:
         | Julia has a bunch of little niceties for mathematics:
         | 
         | * Prefixing a variable with a scaler will implicitly multiply,
         | as in standard math notation (e.g. 3x would evaluate to 6 if x
         | is 2)
         | 
         | * Lots of unicode support. Some feel almost gratuitous ([?] and
         | [?] are operators that work as you would expect) but it's
         | pretty nice to have p predefined (it's even an irrational
         | datatype) and to use [?] as an operator (e.g. [?]2 is a valid
         | expression and evaluates to a float). It's not just that Julia
         | supports these constructions but provides a convenient way to
         | get them to appear.
         | 
         | * This is a little less relevant for calculus but vectors and
         | matrices are fist class types in Julia. Entering and visually
         | parsing matrices is so much easier in Julia than in Python.
         | m = [1 2 3;            4 5 6;            7 8 9]
         | 
         | vs.                 m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
         | 
         | Transposition is a single character operator ('). Dot product
         | can be done with the dot operator (m [?] n). A\b works as it
         | does in matlab.
         | 
         | 4) Julia supports broadcasting. It also has comprehensions but
         | with broadcasting I personally find much less need for
         | comprehensions.
         | 
         | 5) Rationals are built-in with very simple syntax (1//2))
        
           | RivieraKid wrote:
           | I quite like and use Julia but wish there was a language
           | mixing the best aspects of Julia and Swift (which I think can
           | be done without many compromises, i.e. it would be a better
           | language overall).
           | 
           | Some things I don't like about Julia:
           | 
           | - array.mean().round(digits=2) is more readable than
           | round(mean(array), digits=2)
           | 
           | - Poor support for OOP (no, pure FP is not the optimal
           | programming approach).
        
             | patagurbon wrote:
             | You _can_ overload your own types to get a lot of those
             | things (poor support for OOP is harder but you can sort of
             | emulate it with traits). Overloading `getproperty` for the
             | former case.
             | 
             | Of course it's not built in, which I understand is annoying
             | if that's your preferred coding style. I personally am sad
             | that really good traits aren't encoded in the language.
        
             | abisen wrote:
             | If I am not using named arguments I find myself using the
             | pipe operator a lot. I also find it more readable.
             | 
             | array |> mean |> round
             | 
             | For scenarios with named arguments there is a little not so
             | cleaner workaround
             | 
             | array |> mean |> x->round(x, digits=2)
        
       | blagie wrote:
       | I like the concept.
       | 
       | I'd much rather have this built on top of or from something like
       | MOOCulus.
       | 
       | https://ximera.osu.edu/mooculus/calculus1
       | 
       | Holistically, I prefer MOOCulus. However, the value-add of
       | Calculus with Julia is large. If the two could integrate
       | somehow... the key thing about MOOCulus is the writing quality is
       | better (much less verbose), and the integrated exercises means
       | kids follow it closely. It's also very refined, from a lot of
       | classroom use.
       | 
       | If it were forked and Julia-enhanced, that would be a very big
       | step up, though. As would the addition of applications.
        
         | bmitc wrote:
         | I checked out the website, and it's really hard to even know
         | how to use. Plus, the first thing I clicked on, "Equal or
         | Not?", has errors.
        
       | Alifatisk wrote:
       | For someone coming from Matlab, is Julia a valid replacement?
        
         | goerz wrote:
         | Very much so. See
         | https://docs.julialang.org/en/v1/manual/noteworthy-differenc...
         | for some details
        
           | BenFranklin100 wrote:
           | While not a Matlab nor Julia user, I think you may be
           | neglecting the nearly 40 years of code, toolboxes, and
           | countless examples of common engineering problems solved in
           | Matlab. Engineers tend to be more of a practical sort than
           | developers, and just want to apply a known solution to a
           | problem than mess around with newish software languages.
        
         | adgjlsfhk1 wrote:
         | yes.
        
         | nsajko wrote:
         | Very much so. Julia code can be both much nicer and much more
         | performant than Matlab code can.
        
         | antegamisou wrote:
         | [delayed]
        
       | tiffanyh wrote:
       | LuaJIT faster
       | 
       | I find it interesting that after all these year of little
       | development on LuaJIT, and active development in Julia - that
       | LuaJIT is still faster (while also being general purpose).
       | 
       | https://julialang.org/benchmarks/
        
         | slwvx wrote:
         | I find it interesting that after all these years of HN,
         | commenters still ignore the main topic of the OP (a calculus
         | book) to focus on the language it's written in
        
         | patagurbon wrote:
         | LuaJIT is only appreciably faster on text ingestion and
         | printing in those benchmarks. Julia is also plenty general
         | purpose, just targeted (initially at least) towards the
         | numerical community. LuaJIT is fantastically impressive though.
        
       ___________________________________________________________________
       (page generated 2024-05-18 23:00 UTC)