Introduction

Why Julia

  • (too) many dynamic languages to choose from: Python, R, etc.
  • (too) many classifications:
    • high level VS low level languages: C / C++ / Fortran
    • implementations: compiled VS interpreted

from a user point of view

  • write source code -> compile -> run the program
  • run directly the source code

scripting mode

  • source code -> compile -> run

Read–Evaluation–Print Loop (REPL)

  • calculator mode

dynamically-typed language

  • is convenient
x = 1.0 
x = -1.0 + 0*im
x = [1 2; 3 4]
# feed them to...
f(x) = sqrt(x)
g(x) = exp(x)
h(x) = log(x)
  • but the convenience comes with a cost: SLOW.

why Python is slow?

  • not (only) because it's interpreted
  • many codes are already implemented in C, should be fast!
  • it's a data type problem:
    • type inference and type stability
    • obj.method(x, y) VS method(obj, x, y)

the 2-language problem

  • in Python: speeding up = vectorize

  • the 2-language problem:

    • write the slow part in C / C++ / Fortran, then glue them with the rest with Python.
    • it works...
    • but the convenience is kind of lost, and eventually we may as well go back to C.

Why Julia (for this course)

  • learning what to calculate (i.e. physics) is hard enough

    ...and there is no free lunch

  • beginner friendly and easy to learn

Why Julia (for this course)

  • useful built-in functions:
    • eigen, inv, vector multiplication
    • no need to import numpy as np, etc...
  • start counting from 1 (don't argue!)
    • VS 0-based Python
  • column-major
  • functions (and structures) have a clear "end"

Why Julia (for this course)

  • it is fast enough
    • loops are fast
    • to vectorize or not, is just a matter of style
    • JIT compiler
  • have fun: try something new and exciting, and see how far we can go...
  • may contribute to some new packages and documentation

about programming

  • Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
    Brian Kernighan, The Elements of Programming Style, 2nd edition.

  • pep8 for python

  • julia style guide

class rule

  • rule #1: you do not talk about NUMQM2022.
  • rule #2: you DO NOT talk about NUMQM2022.
  • rule #3: do not use the sample codes provided, they are ugly and inefficient, improve them instead.

class rule

  • rule #4: undergraduate students are watching (and grading) us: explain things so that they can understand.
  • rule #5: when you have to choose between right (but boring) and wrong (but funny) answers, pick the wrong ones.

THE END