<jupyter_start><jupyter_text><jupyter_code>%%shell
set -e

#---------------------------------------------------#
JULIA_VERSION="1.4.2" # any version ≥ 0.7.0
JULIA_PACKAGES="IJulia BenchmarkTools PyCall PyPlot"
JULIA_PACKAGES_IF_GPU="CUDA"
JULIA_NUM_THREADS=4
#---------------------------------------------------#

if [ -n "$COLAB_GPU" ] && [ -z `which julia` ]; then
  # Install Julia
  JULIA_VER=`cut -d '.' -f -2 <<< "$JULIA_VERSION"`
  echo "Installing Julia $JULIA_VERSION on the current Colab Runtime..."
  BASE_URL="https://julialang-s3.julialang.org/bin/linux/x64"
  URL="$BASE_URL/$JULIA_VER/julia-$JULIA_VERSION-linux-x86_64.tar.gz"
  wget -nv $URL -O /tmp/julia.tar.gz # -nv means "not verbose"
  tar -x -f /tmp/julia.tar.gz -C /usr/local --strip-components 1
  rm /tmp/julia.tar.gz

  # Install Packages
  if [ "$COLAB_GPU" = "1" ]; then
      JULIA_PACKAGES="$JULIA_PACKAGES $JULIA_PACKAGES_IF_GPU"
  fi
  for PKG in `echo $JULIA_PACKAGES`; do
    echo "Installing Julia package $PKG..."
    julia -e 'using Pkg; pkg"add '$PKG'; precompile;"'
  done

  # Install kernel and rename it to "julia"
  echo "Installing IJulia kernel..."
  julia -e 'using IJulia; IJulia.installkernel("julia", env=Dict(
      "JULIA_NUM_THREADS"=>"'"$JULIA_NUM_THREADS"'"))'
  KERNEL_DIR=`julia -e "using IJulia; print(IJulia.kerneldir())"`
  KERNEL_NAME=`ls -d "$KERNEL_DIR"/julia*`
  mv -f $KERNEL_NAME "$KERNEL_DIR"/julia  

  echo ''
  echo "Successfully installed `julia -v`!"
  echo "Please reload this page (press Ctrl+R, ⌘+R, or the F5 key) then"
  echo "jump to the 'Checking the Installation' section."
fi
versioninfo()<jupyter_output>Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 4<jupyter_text>Pretty similar, right? But notice the small differences:|Julia|Python|-----|------|`function` | `def`|`for i in X`&nbsp;&nbsp;&nbsp;&nbsp;`...``end` | `for i in X:`&nbsp;&nbsp;&nbsp;&nbsp;`...`|`1:n` | `range(1, n+1)`|`cond ? a : b` | `a if cond else b`|`2i + 1` | `2 * i + 1`|`4s` | `return 4 * s`|`println(a, b)` | `print(a, b, sep="")`|`print(a, b)` | `print(a, b, sep="", end="")`|`"$p"` | `f"{p}"`|`"$(p - π)"` | `f"{p - math.pi}"`This example shows that:* Julia can be just as concise and readable as Python.* Indentation in Julia is _not_ meaningful like it is in Python. Instead, blocks end with `end`.* Many math features are built in Julia and need no imports.* There's some mathy syntactic sugar, such as `2i` (but you can write `2 * i` if you prefer).* In Julia, the `return` keyword is optional at the end of a function. The result of the last expression is returned (`4s` in this example).* Julia loves Unicode and does not hesitate to use Unicode characters like `π`. However, there are generally plain-ASCII equivalents (e.g., `π == pi`)  Ola<jupyter_code>print("Ola Mundo!")<jupyter_output>Ola Mundo!<jupyter_text>Operacoes Artimeticas<jupyter_code>x = 1
y = 2
s = s+1 
s<jupyter_output><empty_output><jupyter_text>Funcoes<jupyter_code>function somar(x,y)
  s = x+y
  return s
end


r= somar(1,2)
r<jupyter_output><empty_output><jupyter_text>|Julia|Python|-----|------|`if cond1`&nbsp;&nbsp;&nbsp;&nbsp;`...``elseif cond2`&nbsp;&nbsp;&nbsp;&nbsp;`...``else`&nbsp;&nbsp;&nbsp;&nbsp;`...``end` |`if cond1:`&nbsp;&nbsp;&nbsp;&nbsp;`...``elif cond2:`&nbsp;&nbsp;&nbsp;&nbsp;`...``else:`&nbsp;&nbsp;&nbsp;&nbsp;`...`|`&&` | `and`|`\|\|` | `or`|`!` | `not`|`⊻` (type `\xor`) | `^`|`true` | `True`|`false` | `False`|`cond && f()` | `if cond: f()`|`cond \|\| f()` | `if not cond: f()`|`for i in 1:5 ... end` | `for i in range(1, 6): ...`|`for i in 1:5, j in 1:6 ... end` | `from itertools import product``for i, j in product(range(1, 6), range(1, 7)):`&nbsp;&nbsp;&nbsp;&nbsp;`...`|`while cond ... end` | `while cond: ...`|`continue` | `continue`|`break` | `break`    Condicionais<jupyter_code>function aprovacao(nota, freq)
  if nota>7 && freq>=0.75
    aprov = "Aprovado"
  else
    aprov = "Reprovado"
  end
  return aprov
end

luiz = aprovacao(9,0.8)
luiz<jupyter_output><empty_output><jupyter_text>Loops<jupyter_code>function media_turma()
  notas = [5,5,6,6,7,7,8,8,9,9]
  soma=0
  for i in 1:length(notas)
    soma = soma+ notas[i]
  end
  return soma/length(notas)
end

mt = media_turma()
mt
notas = [5,5,6,6,7,7,8,8,9,9]
notas[1]<jupyter_output><empty_output><jupyter_text>Funcao de Alta Ordem<jupyter_code>function somar(x,y)
  s = x+y
  return s
end

function calculadora(f,x,y)
  return f(x,y)
end

r = calculadora(somar,1,2)
r<jupyter_output><empty_output><jupyter_text>Analise de Dados<jupyter_code>import Pkg
Pkg.add("CSV")
Pkg.add("DataFrames")
Pkg.add("HTTP")
using CSV
using DataFrames
using HTTP
;wget http://quant-ibmec.group/notas.csv
;ls -la
notas=CSV.read("notas.csv", DataFrame)
@show typeof(notas)
print(notas)
grades = DataFrame(CSV.File(HTTP.get("http://quant-ibmec.group/notas.csv").body))
print(grades)
first(grades,2)
print(notas.AP1)
notas.AP1
notas.MF=notas.AP1*0.4+notas.AP2*0.4+notas.AP3*0.2
print(notas)<jupyter_output>[1m12×8 DataFrame[0m
[1m Row [0m│[1m Curso  [0m[1m Alunos  [0m[1m AP1     [0m[1m AP2     [0m[1m AP3     [0m[1m Nota    [0m[1m Conceito [0m[1m MF      [0m
[1m     [0m│[90m String [0m[90m String  [0m[90m Float64 [0m[90m Float64 [0m[90m Float64 [0m[90m Float64 [0m[90m String   [0m[90m Float64 [0m
─────┼────────────────────────────────────────────────────────────────────────
   1 │ ADM     João         9.0      8.0      9.0      8.6  B             8.6
   2 │ ADM     Maria        6.0      4.0     10.0      6.0  D             6.0
   3 │ DIR     José         4.0      3.0      4.0      3.6  F             3.6
   4 │ ADM     Pedro        8.0     10.0      7.0      8.6  B             8.6
   5 │ ECO     Paulo        7.5      8.0      9.5      8.1  B             8.1
   6 │ DIR     Esther       6.0      4.5      6.0      5.4  D             5.4
   7 │ ADM     Gabriel      8.0      6.0      8.0      7.2  B             7.2
   8 │ DIR     Rafael       7.5     10.0  [...]<jupyter_text>Matrizes |Julia|Python|-----|------|`a = [1, 2, 3]` | `a = [1, 2, 3]`or`import numpy as np``np.array([1, 2, 3])`|`a[1]` | `a[0]`|`a[end]` | `a[-1]`|`a[2:end-1]` | `a[1:-1]`|`push!(a, 5)` | `a.append(5)`|`pop!(a)` | `a.pop()`|`M = [1 2 3]` | `np.array([[1, 2, 3]])`|`M = [1 2 3]'` | `np.array([[1, 2, 3]]).T`|`M = hvcat(1,  1, 2, 3)` | `np.array([[1], [2], [3]])`|`M = [1 2 3`&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;`4 5 6]`or`M = [1 2 3; 4 5 6]` | `M = np.array([[1,2,3], [4,5,6]])`|`M[1:2, 2:3]` | `M[0:2, 1:3]`|`[M1; M2]` | `np.r_[M1, M2]`|`[M1  M2]` | `np.c_[M1, M2]`|`[M1 M2; M3]` | `np.r_[np.c_[M1, M2], M3]`<jupyter_code>notas = [5 5 5
         9 9 9
         6 7 8]
pesos = [0.4 0.4 0.2]
mf = notas * pesos'
print(mf)<jupyter_output>[5.0; 9.0; 6.800000000000001]<jupyter_text>Outras Referencias |Julia|Python|-----|------|`Dict("tree"=>"arbre", "love"=>"amour")` | `{"tree": "arbre", "love": "amour"}`|`d["arbre"]` | `d["arbre"]`|`get(d, "unknown", "default")` | `d.get("unknown", "default")`|`keys(d)` | `d.keys()`|`values(d)` | `d.values()`|`haskey(d, k)` | `k in d`|`Dict(i=>i^2 for i in 1:4)` | `{i: i**2 for i in 1:4}`|`for (k, v) in d` | `for k, v in d.items():`|`merge(d1, d2)` | `{**d1, **d2}`|`merge!(d1, d2)` | `d1.update(d2)` |Julia|Python|-----|------|`Set([1, 3, 5, 7])` | `{1, 3, 5, 7}`|`5 in odd` | `5 in odd`|`Set([i^2 for i in 1:4])` | `{i**2 for i in range(1, 5)}`|`odd ∪ primes` | `odd | primes`|`union(odd, primes)` | `odd.union(primes)`|`odd ∩ primes` | `odd & primes`|`insersect(odd, primes)` | `odd.intersection(primes)`|`setdiff(odd, primes)` | `odd - primes` or `odd.difference(primes)`|`symdiff(odd, primes)` | `odd ^ primes` or `odd.symmetric_difference(primes)` |Julia|Python|-----|------|`@enum Fruit apple=1 banana=2 orange=3` | `from enum import Enum``class Fruit(Enum):`&nbsp;&nbsp;&nbsp;&nbsp;`APPLE = 1`&nbsp;&nbsp;&nbsp;&nbsp;`BANANA = 2`&nbsp;&nbsp;&nbsp;&nbsp;`ORANGE = 3`| `Fruit(2) === banana` | `Fruit(2) is Fruit.BANANA`| `instances(Fruit)` | `dir(Fruit)` |Julia|Python|-----|------|`a === b` | `a is b`|`a !== b` | `a is not b`|`objectid(obj)` | `id(obj)` The `options` vararg acts like a dictionary (we will discuss dictionaries later). The keys are **symbols**, e.g., `:verbose`. Symbols are like strings, less flexible but faster. They are typically used as keys or identifiers.|Julia|Python (3.8+ if `/` is used)|-----|------| `function foo(a, b=2, c=3)`&nbsp;&nbsp;&nbsp;&nbsp;`...``end``foo(1, 2)  positional only` | `def foo(a, b=2, c=3, /):`&nbsp;&nbsp;&nbsp;&nbsp;`...``foo(1, 2)  pos only because of /`| `function foo(;a=1, b, c=3)`&nbsp;&nbsp;&nbsp;&nbsp;`...``end``foo(c=30, b=2)  keyword only` | `def foo(*, a=1, b, c=3):`&nbsp;&nbsp;&nbsp;&nbsp;`...``foo(c=30, b=2)  kw only because of *`| `function foo(a, b=2; c=3, d)`&nbsp;&nbsp;&nbsp;&nbsp;`...``end``foo(1; d=4)  pos only; then keyword only` | `def foo(a, b=2, /, *, c=3, d):`&nbsp;&nbsp;&nbsp;&nbsp;`...``foo(1, d=4)  pos only then kw only`| `function foo(a, b=2, c...)`&nbsp;&nbsp;&nbsp;&nbsp;`...``end``foo(1, 2, 3, 4)  positional only` | `def foo(a, b=2, /, *c):`&nbsp;&nbsp;&nbsp;&nbsp;`...``foo(1, 2, 3, 4)  positional only`| `function foo(a, b=1, c...; d=1, e, f...)`&nbsp;&nbsp;&nbsp;&nbsp;`...``end``foo(1, 2, 3, 4, e=5, x=10, y=20)` | `def foo(a, b=1, /, *c, d=1, e, **f):`&nbsp;&nbsp;&nbsp;&nbsp;`...``foo(1, 2, 3, 4, e=5, x=10, y=20)` |Julia|Python|-----|------|`x -> x^2` | `lambda x: x**2`|`(x,y) -> x + y` | `lambda x,y: x + y `|`() -> println("yes")` | `lambda: print("yes")` A few things to note here:* Julia only allows a single `catch` block which handles all possible exceptions.* `obj isa SomeClass` is a shorthand for `isa(obj, SomeClass)` which is equivalent to Python's `isinstance(obj, SomeClass)`.|Julia|Python|-----|------|`try`&nbsp;&nbsp;&nbsp;&nbsp;`...``catch ex`&nbsp;&nbsp;&nbsp;&nbsp;`if ex isa SomeError`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`...`&nbsp;&nbsp;&nbsp;&nbsp;`else`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`...`&nbsp;&nbsp;&nbsp;&nbsp;`end``finally`&nbsp;&nbsp;&nbsp;&nbsp;`...``end` | `try:`&nbsp;&nbsp;&nbsp;&nbsp;`...``except SomeException as ex:`&nbsp;&nbsp;&nbsp;&nbsp;`...``except Exception as ex:`&nbsp;&nbsp;&nbsp;&nbsp;`...``finally:`&nbsp;&nbsp;&nbsp;&nbsp;`...`|`throw any_value` | `raise SomeException(...)`| `obj isa SomeType`or `isa(obj, SomeType`) | `isinstance(obj, SomeType)` In short:|Julia | Python|------|-------|`import Foo` | `import foo`|`import Foo.Bar` | `from foo import bar`|`import Foo.Bar: a, b` | `from foo.bar import a, b`|`import Foo.Bar.a, Foo.Bar.b` | `from foo.bar import a, b`|`import .Foo` | `import .foo`|`import ..Foo.Bar` | `from ..foo import bar`|`import ...Foo.Bar` | `from ...foo import bar`|`import .Foo: a, b` | `from .foo import a, b`|||`using Foo` | `from foo import *; import foo`|`using Foo.Bar` | `from foo.bar import *; from foo import bar `|`using Foo.Bar: a, b` | `from foo.bar import a, b`|Extending function `Foo.f()` | Result|-----------------------------|--------|`import Foo.f   or Foo: f` `f(x::Int64) = ...`  | OK|`import Foo``Foo.f(x::Int64) = ...` | OK|`using Foo``Foo.f(x::Int64) = ...` | OK|`import Foo.f  or Foo: f``Foo.f(x::Int64) = ...` | `ERROR: Foo not defined`|`using Foo``f(x::Int64) = ...` | `ERROR: Foo.f must be explicitly imported`|`using Foo: f``f(x::Int64) = ...` | `ERROR: Foo.f must be explicitly imported` |Julia (in interactive mode) | Python (in a terminal)|-----|------|`]status` | `pip freeze`or`conda list`|`]add Foo` | `pip install foo`or`conda install foo`|`]add Foo@1.2` | `pip install foo==1.2`or`conda install foo=1.2`|`]update Foo` | `pip install --upgrade foo`or`conda update foo`|`]pin Foo` | `foo==` in `requirements.txt` or`foo=` in `environment.yml`|`]free Foo` | `foo` in `requirements.txt`or`foo` in `environment.yml`|`]test Foo` | `python -m unittest foo`|`]rm Foo` | `pip uninstall foo`or`conda remove foo`|`]help` | `pip --help`<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.25584458347053013, 'fraction_numerical': 0.0417352650642081, 'mean_word_length': 3.7624460995687965, 'pattern_counts': {'":': 2, '<': 40, '<?xml version=': 0, '>': 46, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '491188', 'license': 'MIT', 'n_tokens_mistral': 5553, 'n_tokens_neox': 5184, 'n_words': 1157, 'path': 'QM_IntroJulia.ipynb', 'repo_name': 'Grupo-de-Pesquisa-em-Macro-Aplicada/Ibmec-Pesquisa-Macro-Aplicada', 'size': '12148'}