text:
# poweriter.jl
# 2019-06-06, Jeff Fessler, University of Michigan

using Random: seed!
using LinearAlgebra: opnorm, norm
using Test: @test

"""
`v1,σ1 = poweriter(A; niter=?, ...)`

determine first right singular vector `v1`
and first singular value `σ1` of `A`
by applying power iteration to `A'A`

in
* `A` M × N matrix

option
* `niter` default 200
* `x0` initial guess of `v1`
* `tol` stopping tolerance for s1, default 1e-6
* `chat::Bool` verbose? default false

out
* `v1` `[N]` principal right singular vector
* `σ1` spectral norm of `A`
"""
function poweriter(A; niter=200,
		tol::Real = 1e-6,
		x0::AbstractArray{<:Number} = ones(eltype(A), size(A,2)),
		chat::Bool = true,
	)
	x = copy(x0)
	ratio_old = Inf
	for iter=1:niter
		Ax = A * x
		ratio = norm(Ax) / norm(x)
		if abs(ratio - ratio_old) / ratio < tol
			chat && @info "done at iter $iter"
			break
		end
		ratio_old = ratio
		x = A' * Ax
		x /= norm(x)
	end
	return x, norm(A * x) / norm(x)
end

"""
poweriter(:test)
self test
"""
function poweriter(test::Symbol)
	test != :test && throw("bad symbol $test")
	seed!(0)
	M = 30
	N = 20

	A = randn(M,N) # real
	s0 = opnorm(A)
	chat = false
	_,s1 = poweriter(A; tol=1e-9, chat=chat)
	@test isequal(round(s0,digits=7), round(s1,digits=7))

	A = randn(ComplexF32, M, N) # complex
	s0 = opnorm(A)
	_,s1 = poweriter(A; tol=1e-9, chat=chat)
	@test isequal(round(s0,digits=5), round(s1,digits=5))

	true
end


text:
refVals = []
refPrecs = []

#! format: off
# SC ========== Test number 1 reference values and precision match template. =======
# SC ========== /home/jmc/cliMa/cliMa_new_jmc/test/Ocean/SplitExplicit/simple_box_rk3.jl test reference values ======================================
# BEGIN SCPRINT
# varr - reference values (from reference run)
# parr - digits match precision (hand edit as needed)
#
# [
#  [ MPIStateArray Name, Field Name, Maximum, Minimum, Mean, Standard Deviation ],
#  [         :                :          :        :      :          :           ],
# ]
varr = [
 [  "oce Q_3D",   "u[1]", -2.16721345244414054232e-01,  1.57840557320998220447e-01, -5.59921465916523013878e-03,  1.73941108901450175450e-02 ],
 [  "oce Q_3D",   "u[2]", -2.19220347308738905401e-01,  2.31784478500299123693e-01, -2.15429258177158092225e-03,  2.12517725248480282563e-02 ],
 [  "oce Q_3D",      "η", -4.69394735091986536890e-01,  2.06288744860751438459e-01, -2.16765734563377927271e-04,  1.47004018586567947180e-01 ],
 [  "oce Q_3D",      "θ",  2.38571451036062890869e-03,  9.91209376647090323331e+00,  2.49760287312251527680e+00,  2.18031198350304133982e+00 ],
 [   "oce aux",      "w", -1.61734977485578068895e-04,  1.50833500332270227301e-04,  5.43794052142437598582e-07,  1.38648560985387203702e-05 ],
 [   "oce aux",   "pkin", -8.85948574009684719499e+00,  0.00000000000000000000e+00, -3.26449934601666758027e+00,  2.50111590039020725840e+00 ],
 [   "oce aux",    "wz0", -3.66555541768163618680e-05,  1.94813350674614766593e-05, -4.61824895762852330113e-10,  9.37524239840742993843e-06 ],
 [   "oce aux", "u_d[1]", -1.56194066602061892857e-01,  1.21967899279333547025e-01, -2.05350727093651255306e-05,  1.15672828345751727702e-02 ],
 [   "oce aux", "u_d[2]", -2.09729915133787636616e-01,  2.37375904307950719163e-01,  1.58965003169083721666e-06,  1.81625473749615351515e-02 ],
 [   "oce aux", "ΔGu[1]", -2.09811375971404995481e-06,  3.23018047166822386688e-06, -4.22417846605267206689e-08,  2.80615396594168210400e-07 ],
 [   "oce aux", "ΔGu[2]", -2.18036232525426524906e-06,  2.31188192991968871615e-06,  1.27801756611837186519e-06,  7.19811396028193828918e-07 ],
 [   "oce aux",      "y",  0.00000000000000000000e+00,  4.00000000000000046566e+06,  2.00000000000000000000e+06,  1.15573163901915703900e+06 ],
 [ "baro Q_2D",   "U[1]", -3.61200008824836729104e+01,  2.32336820840376567787e+01, -5.58234606367367547364e+00,  1.11708003103345792084e+01 ],
 [ "baro Q_2D",   "U[2]", -4.02361402227773581330e+01,  4.41897774443185085147e+01, -2.15561232944511127485e+00,  1.17915802114324606009e+01 ],
 [ "baro Q_2D",      "η", -4.69794642977587939559e-01,  2.06346018349864157582e-01, -2.16567930962150958151e-04,  1.47057680237089760666e-01 ],
 [  "baro aux",  "Gᵁ[1]", -3.23018047166822403968e-03,  2.09811375971404989044e-03,  4.22417846605267028812e-05,  2.80629288101644008488e-04 ],
 [  "baro aux",  "Gᵁ[2]", -2.31188192991968856707e-03,  2.18036232525426528633e-03, -1.27801756611837201427e-03,  7.19847029373728297674e-04 ],
 [  "baro aux", "U_c[1]", -3.60967490653019851266e+01,  2.32266714099544557826e+01, -5.58248511658658941315e+00,  1.11690207251244704167e+01 ],
 [  "baro aux", "U_c[2]", -4.02002845377460147347e+01,  4.41870183291104439149e+01, -2.15756908928005142201e+00,  1.17881994981494511165e+01 ],
 [  "baro aux",    "η_c", -4.69394735091986536890e-01,  2.06288744860751438459e-01, -2.16765734563369958385e-04,  1.47011295833105265496e-01 ],
 [  "baro aux", "U_s[1]", -3.61200008824836729104e+01,  2.32336820840376567787e+01, -5.58234606367367547364e+00,  1.11708003103345792084e+01 ],
 [  "baro aux", "U_s[2]", -4.02361402227773581330e+01,  4.41897774443185085147e+01, -2.15561232944511127485e+00,  1.17915802114324606009e+01 ],
 [  "baro aux",    "η_s", -4.69794642977587939559e-01,  2.06346018349864157582e-01, -2.16567930962150958151e-04,  1.47057680237089760666e-01 ],
 [  "baro aux",  "Δu[1]", -1.12410191785971484528e-03,  1.98901388437166311979e-03,  1.77992355967350647386e-04,  4.24716110102865956194e-04 ],
 [  "baro aux",  "Δu[2]", -1.40780586763535704373e-03,  1.04939722938436467460e-03, -2.11977336567820129603e-04,  2.73797449735710581031e-04 ],
 [  "baro aux", "η_diag", -4.69273762873680611030e-01,  2.06327225515284040647e-01, -2.15810591775846216884e-04,  1.47008240438936316208e-01 ],
 [  "baro aux",     "Δη", -2.62922736242607313351e-04,  2.37963172744791451318e-04, -9.55142787533847028187e-07,  6.94341553655788138637e-05 ],
 [  "baro aux",      "y",  0.00000000000000000000e+00,  4.00000000000000046566e+06,  2.00000000000000000000e+06,  1.15578885204060329124e+06 ],
]
parr = [
 [  "oce Q_3D",   "u[1]",    12,    12,    12,    12 ],
 [  "oce Q_3D",   "u[2]",    12,    12,    12,    12 ],
 [  "oce Q_3D",      "η",    12,    12,     8,    12 ],
 [  "oce Q_3D",      "θ",    12,    12,    12,    12 ],
 [   "oce aux",      "w",    12,    12,     8,    12 ],
 [   "oce aux",   "pkin",    12,    12,    12,    12 ],
 [   "oce aux",    "wz0",    12,    12,     8,    12 ],
 [   "oce aux", "u_d[1]",    12,    12,    12,    12 ],
 [   "oce aux", "u_d[2]",    12,    12,    12,    12 ],
 [   "oce aux", "ΔGu[1]",    12,    12,    12,    12 ],
 [   "oce aux", "ΔGu[2]",    12,    12,    12,    12 ],
 [   "oce aux",      "y",    12,    12,    12,    12 ],
 [ "baro Q_2D",   "U[1]",    12,    12,    12,    12 ],
 [ "baro Q_2D",   "U[2]",    12,    12,    12,    12 ],
 [ "baro Q_2D",      "η",    12,    12,     8,    12 ],
 [  "baro aux",  "Gᵁ[1]",    12,    12,    12,    12 ],
 [  "baro aux",  "Gᵁ[2]",    12,    12,    12,    12 ],
 [  "baro aux", "U_c[1]",    12,    12,    12,    12 ],
 [  "baro aux", "U_c[2]",    12,    12,    12,    12 ],
 [  "baro aux",    "η_c",    12,    12,     8,    12 ],
 [  "baro aux", "U_s[1]",    12,    12,    12,    12 ],
 [  "baro aux", "U_s[2]",    12,    12,    12,    12 ],
 [  "baro aux",    "η_s",    12,    12,     8,    12 ],
 [  "baro aux",  "Δu[1]",    12,    12,    12,    12 ],
 [  "baro aux",  "Δu[2]",    12,    12,    12,    12 ],
 [  "baro aux", "η_diag",    12,    12,     8,    12 ],
 [  "baro aux",     "Δη",     9,     9,     6,    10 ],
 [  "baro aux",      "y",    12,    12,    12,    12 ],
]
# END SCPRINT
# SC ====================================================================================

    append!(refVals ,[ varr ] )
    append!(refPrecs,[ parr ] )

#! format: on

ext: jl


text:
export HardScore

"""
    HardScore{I} <: Score{I}

A fixed score.
"""
struct HardScore{I} <: Score{I}
    value :: I
end

@impl begin
    struct HardScoreGetScore end
    function get_score(sf::HardScore{I}, i::I)::AbstractFloat where {I}
        i == sf.value ? 1.0 : 0.0
    end
end


text:
module IntegrateTests

using Test
using Gridap.Arrays
using Gridap.Fields
using Gridap.Fields: OtherMockBasis, MockBasis, MockField
using FillArrays
using Gridap.TensorValues

p1 = Point(2,2)
p2 = Point(4,2)
p3 = Point(1,3)
p4 = Point(5,2)
x = [p1,p2,p3,p4]
np = length(x)

d = 2
v = 3.0
ndof = 8
i = MockField{d}(v)
w = fill(1/np,np)
j = TensorValue(1.0,0.0,0.0,1.0)

@test integrate(i,x,w,j) == 9.0

ri = 5.0
r = MockBasis{d}(ri,ndof)

@test integrate(r,x,w,j) == fill(15.0,ndof)

l = 10
ai = Fill(i,l)
aw = fill(w,l)
aj = fill(j,l)
ax = fill(x,l)
ar = Fill(r,l)

s = integrate(ai,ax,aw,aj)
test_array(s,fill(9.0,l))

s = integrate(ar,ax,aw,aj)
test_array(s,fill(fill(15.0,ndof),l))

c = fill(1.0,ndof)
f = OtherMockBasis{d}(ndof)
ϕ = lincomb(f,c)
j = ∇(ϕ)
w = fill(1/np,np)
b = attachmap(r,ϕ)

@test integrate(i,x,w,j) == 38016.0

@test integrate(b,x,w,j) == fill(63360.0,ndof)

l = 10
ac = fill(c,l)
af = Fill(f,l)
aϕ = lincomb(af,ac)
aj = ∇(aϕ)
aw = Fill(w,l)
ax = Fill(x,l)
ar = Fill(r,l)
ab = attachmap(ar,aϕ)

s = integrate(ab,ax,aw,aj)
test_array(s,fill(fill(63360.0,ndof),l))

end # module


text:
function decompose_CNot_41()
    # Reference: https://doi.org/10.1109/DSD.2018.00005

    return Dict{String, Any}(

    "num_qubits" => 4,
    "maximum_depth" => 10,
    "elementary_gates" => ["H_1", "H_2", "H_3", "CNot_1_3", "CNot_4_3", "Identity"],
    "target_gate" => QCOpt.get_full_sized_gate("CNot_4_1", 4),
    "objective" => "minimize_depth",
    )

end

function decompose_quantum_fulladder()
    #Reference-1: https://doi.org/10.1109/DATE.2005.249
    #Reference-2: https://doi.org/10.1109/TCAD.2005.858352

    num_qubits = 4

    function target_gate_1()

        CV_1_2 = QCOpt.get_full_sized_gate("CV_1_2", num_qubits);
        CV_4_2 = QCOpt.get_full_sized_gate("CV_4_2", num_qubits);
        CVdagger_1_2 = QCOpt.get_full_sized_gate("CVdagger_1_2", num_qubits);
        CVdagger_3_2 = QCOpt.get_full_sized_gate("CVdagger_3_2", num_qubits);
        CNot_3_1 = QCOpt.get_full_sized_gate("CNot_3_1", num_qubits);
        CNot_4_3 = QCOpt.get_full_sized_gate("CNot_4_3", num_qubits);
        CNot_2_4 = QCOpt.get_full_sized_gate("CNot_2_4", num_qubits);

        return CNot_2_4 * CV_4_2 * CVdagger_1_2 * CVdagger_3_2 * CNot_4_3 * CNot_3_1 * CV_1_2
    end

    return Dict{String, Any}(

    "num_qubits" => num_qubits,
    "maximum_depth" => 7,
    "elementary_gates" => ["CV_1_2", "CV_4_2", "CV_3_2", "CVdagger_1_2", "CVdagger_4_2", "CVdagger_3_2", "CNot_3_1", "CNot_4_3", "CNot_2_4", "CNot_4_1", "Identity"],
    "target_gate" => target_gate_1(),
    "objective" => "minimize_depth",
    )

end

function decompose_double_toffoli()

    # Reference: https://doi.org/10.1109/TCAD.2005.858352

    num_qubits = 4

    function target_gate()
        CV_3_4 = QCOpt.get_full_sized_gate("CV_3_4", num_qubits);
        CV_2_4 = QCOpt.get_full_sized_gate("CV_2_4", num_qubits);
        CVdagger_2_4 = QCOpt.get_full_sized_gate("CVdagger_2_4", num_qubits);
        CNot_1_3 = QCOpt.get_full_sized_gate("CNot_1_3", num_qubits);
        CNot_3_2 = QCOpt.get_full_sized_gate("CNot_3_2", num_qubits);

        return CV_2_4 * CNot_1_3 * CNot_3_2 * CV_3_4 * CVdagger_2_4 * CNot_3_2 * CNot_1_3
    end

    return Dict{String, Any}(

    "num_qubits" => 4,
    "maximum_depth" => 7,
    "elementary_gates" => ["CV_1_2", "CV_2_4", "CV_3_4", "CVdagger_1_2", "CVdagger_2_4", "CVdagger_3_4", "CNot_1_3", "CNot_3_2", "CNot_2_3", "Identity"],
    "target_gate" => target_gate(),
    "objective" => "minimize_depth"
    )

end

function decompose_double_peres()

    # Reference: https://doi.org/10.1109/TCAD.2005.858352

    num_qubits = 4

    function target_gate()
        CV_1_4 = QCOpt.get_full_sized_gate("CV_1_4", num_qubits);
        CV_2_4 = QCOpt.get_full_sized_gate("CV_2_4", num_qubits);
        CV_3_4 = QCOpt.get_full_sized_gate("CV_3_4", num_qubits);
        CVdagger_3_4 = QCOpt.get_full_sized_gate("CVdagger_3_4", num_qubits);
        CNot_1_2 = QCOpt.get_full_sized_gate("CNot_1_2", num_qubits);
        CNot_2_3 = QCOpt.get_full_sized_gate("CNot_2_3", num_qubits);

        return CV_2_4 * CNot_1_2 * CV_3_4 * CV_1_4 * CNot_2_3 * CVdagger_3_4
    end

    return Dict{String, Any}(

    "num_qubits" => 4,
    "maximum_depth" => 7,
    "elementary_gates" => ["CV_1_4", "CV_2_4", "CV_3_4", "CVdagger_1_4", "CVdagger_2_4", "CVdagger_3_4", "CNot_1_2", "CNot_2_3", "Identity"],
    "target_gate" => target_gate(),
    "objective" => "minimize_depth"
    )

end


text:
function diversity(graph::AbstractGraph)
    D = Dict{Integer,Number}()
    k = degree(graph)
    w = Dict{AbstractEdge,Number}()

    for e = edges(graph)
        w[e] = typeof(graph)<:AbstractSimpleWeightedGraph ? weight(e) : 1
    end

    for v = vertices(graph)
        Ev = edges_of(graph,v)
        p = Dict{AbstractEdge,Number}()

        for e = Ev
            p[e] = w[e]/sum(w[e1] for e1 in Ev)
        end
        D[v] = k[v]>1 ? -sum(p[e]*log(p[e]) for e in Ev)/log(k[v]) : NaN
    end

    return D
end


text:
@coeff function K_I(reactor::Reactor)
 sqrt(P_F/K_F) / K_beta
end


text:
package java.lang;

import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;

public class System {
    public final static PrintStream out =
        new PrintStream(new OutputStream() {
            public void write(int b) { }
            public void print(String s) { }
            public void print(char c) { }
            public void println(String s) { } }
        );

    public final static PrintStream err =
        new PrintStream(new OutputStream() {
            public void write(int b) { }
            public void print(String s) { }
            public void print(char c) { }
            public void println(String s) { } }
        );

    public final static InputStream in =
        new InputStream() { public int read() { return -1; }};

        public static long currentTimeMillis(){ return -1; }

        public static void exit(int i) { }

        public static void arraycopy(Object src,  int  srcPos,
                Object dest, int destPos, int length) {
            if (src instanceof Object[] && dest instanceof Object[]) {
                ((Object[])dest)[destPos] = ((Object[])src)[srcPos];
                ((Object[])dest)[destPos+length] = ((Object[])src)[srcPos+length];
            }
            else  if (src instanceof int[] && dest instanceof int[]) {
                ((int[])dest)[destPos] = ((int[])src)[srcPos];
                ((int[])dest)[destPos+length] = ((int[])src)[srcPos+length];
            }
        }

}

max_stars_repo_name: HarvardPL/cryptoerase

max_issues_repo_name: HarvardPL/cryptoerase

max_forks_repo_name: HarvardPL/cryptoerase


text:
### A Pluto.jl notebook ###
# v0.17.2

using Markdown
using InteractiveUtils

# ╔═╡ e8668469-d378-463e-a8be-324f2362d90b
using FFTW

# ╔═╡ 189e4b15-a8bf-4b9b-8832-1e41be5ade12
using LinearAlgebra

# ╔═╡ c347e5d8-7da2-4aad-aa56-cec1cd6ee6f7
using SpecialFunctions

# ╔═╡ b81c4dba-caf2-4293-93be-134ae7194877
using Luxor

# ╔═╡ e0b6e55a-d6f3-4125-9796-a8463c7e00cd
using Plots

# ╔═╡ 8f32367b-b19b-4c18-80ff-5edaabcfb0d9
include("NystromMethodQP.jl");

# ╔═╡ a8253062-df3c-11eb-26e1-0dcff18bf886
md"
# Method comparison: single-sheet scattering

This notebook will compare an RCWA-based method with a boundary-integral equation
method for solving the scattering through one periodic sheet with a 1D unit cell.
"

# ╔═╡ fd018c1d-6a0d-42bb-8605-a599c70709ee
md"
## Incident wave parameters
"

# ╔═╡ 2b2defdf-66a3-44a2-9e78-25738dfa9f02
kᵢ = 10.0 # incident wavenumber = ω/c

# ╔═╡ 2a880954-0413-491e-bd55-0b0a9de2e2e4
λᵢ = 2π/kᵢ

# ╔═╡ 4d714c5c-cbde-4750-83c2-11ea89bf3041
θⁱ = π/2 # incidence angle, measured counter-clockwise from +x direction

# ╔═╡ 2af83733-4752-467d-93cc-1db8209d71dd
αᵢ = kᵢ * cos(θⁱ) # component of kᵢ along x (sheet)

# ╔═╡ 31098999-eba6-474c-87bf-3d8929ee5017
βᵢ = kᵢ * sin(θⁱ) # component of kᵢ along y (transmiision axis)

# ╔═╡ 7ead1c90-772b-40fe-8388-9f6347316c2a
md"
## Metasurface impedance parameters

For references on the metasurface impedance/conductivity parameters see
- [Pérez-Arancibia et al., 2018, Sideways adiabaticity: beyond ray optics for slowly varying metasurfaces](https://doi.org/10.1364/OE.26.030202)
- [Yu et al., 2011, Light Propagation with Phase Discontinuities: Generalized Laws of Reflection and Refraction](https://doi.org/10.1126/science.1210713)
"

# ╔═╡ f09b7267-b5a6-46dd-9ff7-ac48f61531b2
k = kᵢ / 1.1 # wavenumber that attains the metasurface design goals
# do not choose k = kᵢ (a.k.a Wood anomaly)

# ╔═╡ 460673fc-b9be-4779-b7c9-5f158e54f0c4
θᵗ = π/3 # desired transmitted field angle

# ╔═╡ dcee0976-8f6d-4dba-9d6c-a91561870419
d = cos(θᵗ)-cos(θⁱ) # design parameter

# ╔═╡ 0ac33952-951c-45be-beb3-e0a43f8b6d60
λ = 2π/k # wavelength that attains the metasurface design goals

# ╔═╡ 2eb8bc93-f6e8-4ec8-a013-dad617a13359
L₀ = λ/abs(d) # period of metasurface

# ╔═╡ ec08bb0a-cee7-47e6-a6eb-440673799d7c
# Defining susceptibilities
η(x) = sin(abs(θⁱ)).*(1+exp.(im*k*d*x))
# η(x) = 0

# ╔═╡ 18f474f7-72be-4a36-afb4-147592bd68df
μ(x) = sin(abs(θⁱ)).*(1-exp.(im*k*d*x))
# μ(x) = 0

# ╔═╡ 84b55287-2b2e-41ad-86b2-2dcdd42634e6
md"
## Discretization parameters
"

# ╔═╡ c22c549b-f588-4c13-8540-978af37ed666
N = 100 # number of discretization points / modes along unit cell

# ╔═╡ a6928e0a-b892-4416-ac66-55e28d60aa7e
L = L₀  # Unit cell width (integer multiple of period of metasurface)

# ╔═╡ e9cbab99-d1c7-44d5-a44d-10d47819e055
dx = L/N

# ╔═╡ b2cc77c1-a578-4290-adda-da4b29ca3d5f
x = range(0, step=dx, length=N) # x points in unit cell

# ╔═╡ 1710cfd1-89c3-4bf8-b825-e76e7c898d74
begin
	# plot metasurface conductivity (η), impedance (μ) parameters
	paramPlot = plot(x,real.(η.(x)), ls=:solid, label="Re η")
	paramPlot = plot!(x,imag.(η.(x)), ls=:dash, label="Im η")
	paramPlot = plot!(x,real.(μ.(x)), ls=:solid, label="Re μ")
	paramPlot = plot!(x,imag.(μ.(x)), ls=:dash, label="Im μ")
	plot(paramPlot,lw=3,frame=:box, xguide="x", yguide="η, μ")
end

# ╔═╡ f476676e-b0d6-46fa-829c-0e691abddffd
y = range(-L, L, length=2N) # y points above and below unit cell

# ╔═╡ 6ac3be67-7dae-42e4-95fd-b0df707892bb
y₁ = y[y .< 0] # y points in domain below sheet

# ╔═╡ 116f6639-9fe5-4f6d-92c2-a6441f11a6d2
y₂ = y[y .> 0] # y points in domain above sheet

# ╔═╡ 852b84b4-5112-4a1c-bece-a767cee13768
k⃗ = 2*pi*fftfreq(N, 1/dx) # wavenumbers for Fourier decomposition

# ╔═╡ 93fc5b34-18cc-4a88-9984-a5762305b946
β⃗ = @. sqrt(Complex(kᵢ^2 - k⃗^2))

# ╔═╡ badfeed7-aabf-44ae-8a97-ab5ca797bf76
i = findfirst(k⃗ .- αᵢ .< eps()) # mode index of incident wave

# ╔═╡ d1b49c5e-e9a2-4b44-90e9-622fab40c740
@assert i == findfirst(real.(β⃗ .- βᵢ) .< eps())

# ╔═╡ 1ef4e805-3dd9-4f39-a697-ddc0b4f04ad8
md"
## Carlos' solver
"

# ╔═╡ ad90ebc0-99f2-4636-bce8-12abf791a69a
uInc(x,y)= exp(im*αᵢ*x+im*βᵢ*y)  # incident planewave

# ╔═╡ dd28d0f8-dcf5-45b0-80f7-9aca4c2ca828
# Vertices that define the curve Γ
ver = [
	L/2   0;   #1
    -L/2   0   #2
]
# In this case, Γ is just a line segment from (L/2,0) to (-L/2,0).

# ╔═╡ 2e77a377-69af-496e-8e06-59fa8135fd29
# This matrix defines the orientation of the curve
        #starting node  #ending node  #domain on the right #domian on the left
info = [1               2             1                    0]

# ╔═╡ 2dcd0f66-f906-4358-907b-7aa0a9199c01
# The parameter M defines the number of boundary points to used in the discretization of the BIE
M  = Int(round(max(20,20/λᵢ)))

# ╔═╡ da3f4379-7b2d-4efc-a9b2-5dcccd4a7d40
# Γ contains all the information of the discretized curve that is needed for the numerical solution of the problem
Γ  = SkeletonCctor(ver,info,[M]);

# ╔═╡ d088a142-f43a-4347-92ca-fb0d6569a262
Γ.plt

# ╔═╡ 51170e8f-2802-4450-b0f6-795b5ad9cacd
method = "MK" # Selection of the Nystrom method to be used

# ╔═╡ 31799b9e-1da0-4e02-8899-2cf7e6ce9563
NC = 6      # Number of unit cells considered in the windowed sum (A = NC*L)

# ╔═╡ f8bb8da7-20d0-43da-846e-5130e7b38edc
mat = matricesSkeleton(1,Γ,kᵢ,L,αᵢ,NC,method); # Construction of the Nystrom matrices

# ╔═╡ 9fc48c4a-f3f4-4a1a-9fb3-b82a08f3c394
x1 = Γ.parts[1].x[:,1] # x-coordinate of the discretization points on Γ

# ╔═╡ df9e0973-7c43-445e-86bb-fa7030c650e1
f1(x) = -2*im*kᵢ*η(x)*exp(im*αᵢ*x)

# ╔═╡ cf4f4bf4-8a47-401a-b569-905c9b3cd9fd
f2(x) = -2*im*βᵢ*exp(im*αᵢ*x)

# ╔═╡ b08df8b1-de6f-4b71-a650-48e483d91a3e
# Solving the boundary integral equations
begin
A⁺ = -0.5*I+im*kᵢ*Diagonal(η.(x1))*mat.S  # System matrix for Ω⁺
b⁺ = f1.(x1) # boundary data for Ω⁺
ψ⁺ = A⁺\b⁺

A⁻ = -0.5*I+im*kᵢ*Diagonal(μ.(x1))*mat.S # System matrix for Ω⁻
b⁻ = f2.(x1) # boundary data for Ω⁻
ψ⁻ = A⁻\b⁻

φ⁺ = 0.5*(ψ⁺+ψ⁻)
φ⁻ = 0.5*(ψ⁺-ψ⁻)
end;

# ╔═╡ ec2d9dea-e4d7-4703-8422-f4d9c4aec3fd
begin
ver⁺ = [L 0;-L 0;-L 2L;L 2L];
Ω⁺ = isin(x,y,ver⁺);

ver⁻ = [L 0;-L 0;-L -2L;L -2L];
Ω⁻ =isin(x,y,ver⁻);
end;

# ╔═╡ e9847c59-f98f-419d-88c1-3200ec3e3b4a
UInc = reshape(uInc.(Ω⁺.pts[:,1],Ω⁺.pts[:,2]),Ω⁺.Ny,Ω⁺.Nx);

# ╔═╡ 93c2a72c-629f-4512-a048-8245ed2ebeb0
# solve for upper potential (~30 seconds)
pot⁺ = potentialsSkeleton(Ω⁺.pts,Γ,kᵢ,L,αᵢ,NC);

# ╔═╡ 96f0ddeb-d722-4379-ba89-535f8ea15844
begin
	U⁺scat = reshape(pot⁺.SL*φ⁺,Ω⁺.Ny,Ω⁺.Nx)
	U⁺ = Ω⁺.In .* (U⁺scat .+ UInc)
end;

# ╔═╡ 25a97227-9531-40d4-b354-32663e016ad5
Ω⁺mask = isfinite.(Ω⁺.In);

# ╔═╡ 85a067b0-24e1-47e6-87e7-6850f981cf04
# extract the fields in the upper domain
if θⁱ < 0
	CI₂ = reshape(UInc[Ω⁺mask], length.((y₂, x)))
	CO₂ = reshape(U⁺[Ω⁺mask] .- UInc[Ω⁺mask], length.((y₂, x)))
else
	CI₂ = reshape(UInc[Ω⁺mask] .- UInc[Ω⁺mask], length.((y₂, x)))
	CO₂ = reshape(U⁺[Ω⁺mask], length.((y₂, x)))
end;

# ╔═╡ 46922475-76df-4734-8762-b72dca549b08
# solve for lower potential (~30 seconds)
pot⁻ = potentialsSkeleton(Ω⁻.pts,Γ,kᵢ,L,αᵢ,NC);

# ╔═╡ d218485c-875a-4d8c-b89b-c967c0f3f10f
begin
	U⁻scat = reshape(pot⁻.SL*φ⁻,Ω⁻.Ny,Ω⁻.Nx)
	U⁻ = Ω⁻.In .* (U⁻scat .+ UInc)
end;

# ╔═╡ 8b34269f-8fdf-44d4-9fa4-ad2e31aa0917
Ω⁻mask = isfinite.(Ω⁻.In);

# ╔═╡ bdf6e2d5-30df-4bb5-a755-b71f29d99b41
# extract the fields in the lower domain
if θⁱ < 0
	CI₁ = reshape(UInc[Ω⁻mask] .- UInc[Ω⁻mask], length.((y₁, x)))
	CO₁ = reshape(U⁻[Ω⁻mask], length.((y₁, x)))
else
	CI₁ = reshape(UInc[Ω⁻mask], length.((y₁, x)))
	CO₁ = reshape(U⁻[Ω⁻mask] .- UInc[Ω⁻mask], length.((y₁, x)))
end;

# ╔═╡ 6045bf4a-e6ac-4411-bd0e-171ee51f3c97
md"
## Luke's solver
"

# ╔═╡ a82986c7-007e-4b6c-9afa-530dc062c5ce
begin
	β̂ = Diagonal(β⃗)
    η̃ = ifft(fft(Matrix(Diagonal(η.(x))), 2), 1)
    μ̃ = ifft(fft(Matrix(Diagonal(μ.(x))), 2), 1)
    A = [
        -β̂-kᵢ*η̃    -β̂-kᵢ*η̃;
        -β̂-kᵢ*μ̃     β̂+kᵢ*μ̃
    ]
    B = [
        -β̂+kᵢ*η̃    -β̂+kᵢ*η̃;
        -β̂+kᵢ*μ̃     β̂-kᵢ*μ̃
    ]
	S = A\B
	if θⁱ < 0
		I₁ = zeros(N)
		I₂ = [n==i ? 1 : 0 for n in 1:N]
	else
		I₁ = [n==i ? 1 : 0 for n in 1:N]
		I₂ = zeros(N)
	end
	inc = [I₁; I₂]
	scat = S*inc
	O₁ = scat[1:N]
	O₂ = scat[N+1:2N]
end;

# ╔═╡ 5d443572-9d5e-4495-867f-e908d9b56716
md"
## Comparisons

To compare the frequency domain results of Luke's solver to the fields produced by
Carlos' solver, we will have to map the scattered amplitudes onto the grid of Carlos'
solver, possibly correcting for an overall complex normalization factor
(amplitude and phase)

We can find that normalization factor by setting the film to be trivial and comparing
the incident and scattered wave

I will compare
- incident fields in upper domain (these are just the incident wave)
- incident fields in lower domain (these are both zero)
- scattered fields in upper domain
- scattered fields in lower domain
"

# ╔═╡ bbe3111b-18b3-4832-b636-621567a19632
part = real;

# ╔═╡ a39dd1aa-868d-4819-877f-ccd4b856cb4c
heatmap(x,y,part.(cat(CI₁ + CO₁, CI₂ + CO₂; dims=1)),color=:RdBu,clim=(-1.0,1.0),aspect_ratio=:equal,frame=:box)

# ╔═╡ f667b91a-c07d-44b1-968c-55b80f11eb47
begin
	# quick plotting
	BO₁ = rotr90(bfft(exp.(-β⃗ * transpose(im * y₁)) .* O₁, 1))
	BI₂ = rotr90(bfft(exp.(-β⃗ * transpose(im * y₂)) .* I₂, 1))
	BI₁ = rotr90(bfft(exp.( β⃗ * transpose(im * y₁)) .* I₁, 1))
	BO₂ = rotr90(bfft(exp.( β⃗ * transpose(im * y₂)) .* O₂, 1))
	fields = cat(BI₁ + BO₁, BI₂ + BO₂; dims=1)
	heatmap(x, y, part.(fields), xguide="x", yguide="y", aspect_ratio=:equal,color=:RdBu,)
end

# ╔═╡ 0ef24eb1-e9d8-442c-ab8e-03f56735f3c5
md"
Increase resolution to show convergence
"

# ╔═╡ 6fc9edc2-c2aa-4be8-9f74-d069de42acb6
phase = -5*dx # this is a fudge factor to reduce the apparent far-field error # try -5dx

# ╔═╡ 18ebd13e-88cd-453c-8690-1efc55b35900
# Incident, upper
heatmap(x, y₂, part.(exp(im*phase) * BI₂ - CI₂), aspect_ratio=1, xguide="x", yguide="z", title="$(part)(error incident field above sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ d9b1970e-f8e3-42a6-b2db-c6d4967bcec2
histogram(reshape(part.(exp(im*phase) * BI₂ - CI₂), :), normalize=true, title="density $(part)(error incident field above sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ e19bf203-1eac-457f-bd61-1d9bfff9aa88
# scattered, upper
heatmap(x, y₂, part.(exp(phase*im) * BO₂ - CO₂), aspect_ratio=1, xguide="x", yguide="z", title="$(part)(error scattered field above sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 3c80c613-78f1-4136-8f6e-dd31b1a60e8e
histogram(reshape(part.(exp(im*phase) * BO₂ - CO₂), :), normalize=true, title="density $(part)(error scattered field above sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 980eed0d-3ba6-48a1-b31f-8a1446c96444
# Incident, lower
heatmap(x, y₁, part.(exp(im*phase) * BI₁ - CI₁), aspect_ratio=1, xguide="x", yguide="z", title="$(part)(error incident field under sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 620c1306-295e-4ed6-84a6-75fde9e27e66
histogram(reshape(part.(exp(im*phase) * BI₁ - CI₁), :), normalize=true, title="density $(part)(error incident field under sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 6aa9e5de-9daf-4b9a-9078-b909a9fc5e03
# scattered, lower
heatmap(x, y₁, part.(exp(im*phase) * BO₁ - CO₁), aspect_ratio=1, xguide="x", yguide="z", title="$(part)(error scattered field under sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 70e5c1b4-caf4-4760-a8b0-1a509604582e
histogram(reshape(part.(exp(im*phase) * BO₁ - CO₁), :), normalize=true, title="density $(part)(error scattered field under sheet), θᵗ=$(round(180 *θᵗ/π; digits=2))ᵒ")

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[compat]
FFTW = "~1.4.5"
Luxor = "~2.15.0"
Plots = "~1.22.3"
SpecialFunctions = "~1.7.0"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

[[AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "485ee0867925449198280d4af84bdb46a2a404d0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.0.1"

[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.1"

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"

[[Cairo]]
deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"]
git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b"
uuid = "159f3aea-2a34-519c-b102-8c37f9878175"
version = "1.0.5"

[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "f2202b55d816427cd385a9a4f3ffb226bee80f99"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+0"

[[ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "d9e40e3e370ee56c5b57e0db651d8f92bce98fea"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.10.1"

[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random"]
git-tree-sha1 = "a851fec56cb73cfdf43762999ec72eff5b86882a"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.15.0"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.0"

[[ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"]
git-tree-sha1 = "45efb332df2e86f2cb2e992239b6267d97c9e0b6"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.9.7"

[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "31d0151f5716b655421d9d75b7fa74cc4e744df2"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.39.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7"

[[DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.10"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "a32185f5428d3986f47c2ab78b1f216d5e6cc96f"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.5"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[EarCut_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3f3a2501fa7236e9b911e0f7a588c657e822bb6d"
uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
version = "2.2.3+0"

[[Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b3bfd02e98aedfa5cf885665493c5598c350cd2f"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.2.10+0"

[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"

[[FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "d8a578692e3077ac998b50c0217dfd67f21d1e5f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.0+0"

[[FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"]
git-tree-sha1 = "463cb335fa22c4ebacfd1faba5fde14edb80d96c"
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
version = "1.4.5"

[[FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c6033cc3892d0ef5bb9cd29b7f2f0331ea5184ea"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.10+0"

[[FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "3c041d2ac0a52a12a27af2782b34900d9c3ee68c"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.11.1"

[[FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"

[[Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.93+0"

[[Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"

[[FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.4+0"

[[FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0"

[[GLFW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"]
git-tree-sha1 = "0c603255764a1fa0b61752d2bec14cfbd18f7fe8"
uuid = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
version = "3.3.5+1"

[[GR]]
deps = ["Base64", "DelimitedFiles", "GR_jll", "HTTP", "JSON", "Libdl", "LinearAlgebra", "Pkg", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"]
git-tree-sha1 = "d189c6d2004f63fd3c91748c458b09f26de0efaa"
uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
version = "0.61.0"

[[GR_jll]]
deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Pkg", "Qt5Base_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "cafe0823979a5c9bff86224b3b8de29ea5a44b2e"
uuid = "d2c73de3-f751-5644-a686-071e5b155ba9"
version = "0.61.0+0"

[[GeometryBasics]]
deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "58bcdf5ebc057b085e58d95c138725628dd7453c"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.4.1"

[[Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"

[[Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "74ef6288d071f58033d54fd6708d4bc23a8b8972"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.3+1"

[[Graphics]]
deps = ["Colors", "LinearAlgebra", "NaNMath"]
git-tree-sha1 = "1c5a84319923bea76fa145d49e93aa4394c73fc2"
uuid = "a2bd30eb-e257-5431-a919-1863eab51364"
version = "1.1.1"

[[Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011"
uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472"
version = "1.3.14+0"

[[Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "Logging", "MbedTLS", "NetworkOptions", "Sockets", "URIs"]
git-tree-sha1 = "14eece7a3308b4d8be910e265c724a6ba51a9798"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.9.16"

[[HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
git-tree-sha1 = "129acf094d168394e80ee1dc4bc06ec835e510a3"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "2.8.1+1"

[[ImageCore]]
deps = ["AbstractFFTs", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Graphics", "MappedArrays", "MosaicViews", "OffsetArrays", "PaddedViews", "Reexport"]
git-tree-sha1 = "9a5c62f231e5bba35695a20988fc7cd6de7eeb5a"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.9.3"

[[ImageMagick]]
deps = ["FileIO", "ImageCore", "ImageMagick_jll", "InteractiveUtils", "Libdl", "Pkg", "Random"]
git-tree-sha1 = "5bc1cb62e0c5f1005868358db0692c994c3a13c6"
uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
version = "1.2.1"

[[ImageMagick_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pkg", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "ea2b6fd947cdfc43c6b8c15cff982533ec1f72cd"
uuid = "c73af94c-d91f-53ed-93a7-00f77d67a9d7"
version = "6.9.12+0"

[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"

[[IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d979e54b71da82f3a65b62553da4fc3d18c9004c"
uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"
version = "2018.0.3+2"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "f0c6489b12d28fb4c2103073ec7452f3423bd308"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.1"

[[IrrationalConstants]]
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.1.1"

[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"

[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"

[[JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.2"

[[JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d735490ac75c5cb9f1b00d8b5509c11984dc6943"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "2.1.0+0"

[[Juno]]
deps = ["Base64", "Logging", "Media", "Profile"]
git-tree-sha1 = "07cb43290a840908a771552911a6274bc6c072c7"
uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
version = "0.8.4"

[[LAME_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac"
version = "2.10.1+0"

[[LaTeXStrings]]
git-tree-sha1 = "c7f1c695e06c01b95a67f0cd1d34994f3e7db104"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.2.1"

[[Latexify]]
deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"]
git-tree-sha1 = "669315d963863322302137c4591ffce3cb5b8e68"
uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
version = "0.15.8"

[[LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libcroco_jll]]
deps = ["Artifacts", "Glib_jll", "JLLWrappers", "Libdl", "Pkg", "XML2_jll"]
git-tree-sha1 = "a8e3b1b67458c8933992b95db9c4b37865906e3f"
uuid = "57eb2189-7eb1-52c8-ac0e-99495f550b14"
version = "0.6.13+2"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "0b4a5d71f3e5200a7dff793393e09dfc2d874290"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.2+1"

[[Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae"
uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4"
version = "1.8.7+0"

[[Libglvnd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll", "Xorg_libXext_jll"]
git-tree-sha1 = "7739f837d6447403596a75d19ed01fd08d6f56bf"
uuid = "7e76a0d4-f3c7-5321-8279-8d96eeed0f29"
version = "1.3.0+3"

[[Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.42.0+0"

[[Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.1+1"

[[Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[Librsvg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libcroco_jll", "Libdl", "Pango_jll", "Pkg", "gdk_pixbuf_jll"]
git-tree-sha1 = "af3e6dc6747e53a0236fbad80b37e3269cf66a9f"
uuid = "925c91fb-5dd6-59dd-8e8c-345e74382d89"
version = "2.42.2+3"

[[Libtiff_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
git-tree-sha1 = "340e257aada13f95f98ee352d316c3bed37c8ab9"
uuid = "89763e89-9b03-5906-acba-b20f662cd828"
version = "4.3.0+0"

[[Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.36.0+0"

[[LinearAlgebra]]
deps = ["Libdl", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[LogExpFunctions]]
deps = ["ChainRulesCore", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "6193c3815f13ba1b78a51ce391db8be016ae9214"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.4"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Luxor]]
deps = ["Base64", "Cairo", "Colors", "Dates", "FFMPEG", "FileIO", "ImageMagick", "Juno", "QuartzImageIO", "Random", "Rsvg"]
git-tree-sha1 = "b2b3d49ffb3b89d9e052da47a0b6df13579738ea"
uuid = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
version = "2.15.0"

[[MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "5455aef09b40e5020e1520f551fa3135040d4ed0"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2021.1.1+2"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "5a5bc6bf062f0f95e62d0fe0a2d99699fed82dd9"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.8"

[[MappedArrays]]
git-tree-sha1 = "e8b359ef06ec72e8c030463fe02efe5527ee5142"
uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
version = "0.4.1"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "1c38e51c3d08ef2278062ebceade0e46cefc96fe"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.3"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[Measures]]
git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f"
uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
version = "0.3.1"

[[Media]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58"
uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27"
version = "0.5.0"

[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.2"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[MosaicViews]]
deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"]
git-tree-sha1 = "b34e3bc3ca7c94914418637cb10cc4d1d80d877d"
uuid = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389"
version = "0.3.3"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NaNMath]]
git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.5"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[OffsetArrays]]
deps = ["Adapt"]
git-tree-sha1 = "c0e9e582987d36d5a61e650e6e543b9e44d9914b"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.10.7"

[[Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7937eda4681660b4d6aeeecc2f7e1c81c8ee4e2f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+0"

[[OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"

[[OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"

[[OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "15003dcb7d8db3c6c857fda14891a539a8f2705a"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.10+0"

[[OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.5+0"

[[Opus_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.2+0"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.44.0+0"

[[PaddedViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "646eed6f6a5d8df6708f15ea7e02a7a2c4fe4800"
uuid = "5432bcbf-9aad-5242-b902-cca2824c8663"
version = "0.5.10"

[[Pango_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9bc1871464b12ed19297fbc56c4fb4ba84988b0d"
uuid = "36c8627f-9965-5494-a995-c6b170f724f3"
version = "1.47.0+0"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "98f59ff3639b3d9485a03a72f3ab35bab9465720"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.0.6"

[[Pixman_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29"
uuid = "30392449-352a-5448-841d-b1acce4e97dc"
version = "0.40.1+0"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PlotThemes]]
deps = ["PlotUtils", "Requires", "Statistics"]
git-tree-sha1 = "a3a964ce9dc7898193536002a6dd892b1b5a6f1d"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "2.0.1"

[[PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "b084324b4af5a438cd63619fd006614b3b20b87b"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.0.15"

[[Plots]]
deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "ba43b248a1f04a9667ca4a9f782321d9211aa68e"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.22.6"

[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Profile]]
deps = ["Printf"]
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[[Qt5Base_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"]
git-tree-sha1 = "ad368663a5e20dbb8d6dc2fddeefe4dae0781ae8"
uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1"
version = "5.15.3+0"

[[QuartzImageIO]]
deps = ["FileIO", "ImageCore", "Libdl"]
git-tree-sha1 = "16de3b880ffdfbc8fc6707383c00a2e076bb0221"
uuid = "dca85d43-d64c-5e67-8c65-017450d5d020"
version = "0.7.4"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RecipesBase]]
git-tree-sha1 = "44a75aa7a527910ee3d1751d1f0e4148698add9e"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.1.2"

[[RecipesPipeline]]
deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"]
git-tree-sha1 = "7ad0dfa8d03b7bcf8c597f59f5292801730c55b8"
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
version = "0.4.1"

[[Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"

[[Rsvg]]
deps = ["Cairo", "Glib_jll", "Librsvg_jll"]
git-tree-sha1 = "3d3dc66eb46568fb3a5259034bfc752a0eb0c686"
uuid = "c4c386cf-5103-5370-be45-f3a111cca3b8"
version = "1.0.0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Scratch]]
deps = ["Dates"]
git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda"
uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.1.0"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Showoff]]
deps = ["Dates", "Grisu"]
git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "1.0.3"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.1"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[SpecialFunctions]]
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "793793f1df98e3d7d554b65a107e9c9a6399a6ed"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "1.7.0"

[[StackViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c"
uuid = "cae243ae-269e-4f55-b966-ac2d0dc13c15"
version = "0.1.1"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "3c76dde64d03699e074ac02eb2e8ba8254d428da"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.2.13"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[StatsAPI]]
git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.0.0"

[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "eb35dcc66558b2dda84079b9a1be17557d32091a"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.12"

[[StructArrays]]
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
git-tree-sha1 = "2ce41e0d042c60ecd131e9fb7154a3bfadbf50d3"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.3"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.1"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.6.0"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[TensorCore]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6"
uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50"
version = "0.1.1"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[URIs]]
git-tree-sha1 = "97bbe755a53fe859669cd907f2d96aee8d2c1355"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.3.0"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Wayland_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "3e61f0b86f90dacb0bc0e73a0c5a83f6a8636e23"
uuid = "a2964d1f-97da-50d4-b82a-358c7fce9d89"
version = "1.19.0+0"

[[Wayland_protocols_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll"]
git-tree-sha1 = "2839f1c1296940218e35df0bbb220f2a79686670"
uuid = "2381bf8a-dfd0-557d-9999-79630e7b1b91"
version = "1.18.0+4"

[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"

[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"

[[Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.6.9+4"

[[Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e"
uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec"
version = "1.0.9+4"

[[Xorg_libXcursor_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "12e0eb3bc634fa2080c1c37fccf56f7c22989afd"
uuid = "935fb764-8cf2-53bf-bb30-45bb1f8bf724"
version = "1.2.0+4"

[[Xorg_libXdmcp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4"
uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05"
version = "1.1.3+4"

[[Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.4+4"

[[Xorg_libXfixes_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "0e0dc7431e7a0587559f9294aeec269471c991a4"
uuid = "d091e8ba-531a-589c-9de9-94069b037ed8"
version = "5.0.3+4"

[[Xorg_libXi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXfixes_jll"]
git-tree-sha1 = "89b52bc2160aadc84d707093930ef0bffa641246"
uuid = "a51aa0fd-4e3c-5386-b890-e753decda492"
version = "1.7.10+4"

[[Xorg_libXinerama_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll"]
git-tree-sha1 = "26be8b1c342929259317d8b9f7b53bf2bb73b123"
uuid = "d1454406-59df-5ea1-beac-c340f2130bc3"
version = "1.1.4+4"

[[Xorg_libXrandr_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll"]
git-tree-sha1 = "34cea83cb726fb58f325887bf0612c6b3fb17631"
uuid = "ec84b674-ba8e-5d96-8ba1-2a689ba10484"
version = "1.5.2+4"

[[Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96"
uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa"
version = "0.9.10+4"

[[Xorg_libpthread_stubs_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb"
uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74"
version = "0.1.0+3"

[[Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.13.0+3"

[[Xorg_libxkbfile_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "926af861744212db0eb001d9e40b5d16292080b2"
uuid = "cc61e674-0454-545c-8b26-ed2c68acab7a"
version = "1.1.0+4"

[[Xorg_xcb_util_image_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "0fab0a40349ba1cba2c1da699243396ff8e94b97"
uuid = "12413925-8142-5f55-bb0e-6d7ca50bb09b"
version = "0.4.0+1"

[[Xorg_xcb_util_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll"]
git-tree-sha1 = "e7fd7b2881fa2eaa72717420894d3938177862d1"
uuid = "2def613f-5ad1-5310-b15b-b15d46f528f5"
version = "0.4.0+1"

[[Xorg_xcb_util_keysyms_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "d1151e2c45a544f32441a567d1690e701ec89b00"
uuid = "975044d2-76e6-5fbe-bf08-97ce7c6574c7"
version = "0.4.0+1"

[[Xorg_xcb_util_renderutil_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "dfd7a8f38d4613b6a575253b3174dd991ca6183e"
uuid = "0d47668e-0667-5a69-a72c-f761630bfb7e"
version = "0.3.9+1"

[[Xorg_xcb_util_wm_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"]
git-tree-sha1 = "e78d10aab01a4a154142c5006ed44fd9e8e31b67"
uuid = "c22f9ab0-d5fe-5066-847c-f4bb1cd4e361"
version = "0.4.1+1"

[[Xorg_xkbcomp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxkbfile_jll"]
git-tree-sha1 = "4bcbf660f6c2e714f87e960a171b119d06ee163b"
uuid = "35661453-b289-5fab-8a00-3d9160c6a3a4"
version = "1.4.2+4"

[[Xorg_xkeyboard_config_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xkbcomp_jll"]
git-tree-sha1 = "5c8424f8a67c3f2209646d4425f3d415fee5931d"
uuid = "33bec58e-1273-512f-9401-5d533626f822"
version = "2.27.0+4"

[[Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845"
uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10"
version = "1.4.0+3"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[Zstd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "cc4bf3fdde8b7e3e9fa0351bdeedba1cf3b7f6e6"
uuid = "3161d3a3-bdf6-5164-811a-617609db77b4"
version = "1.5.0+0"

[[gdk_pixbuf_jll]]
deps = ["Artifacts", "Glib_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pkg", "Xorg_libX11_jll", "libpng_jll"]
git-tree-sha1 = "0facfc4bfd873c21b83a053bbf182b9ef19c69d8"
uuid = "da03df04-f53b-5353-a52f-6a8b0620ced0"
version = "2.42.6+0"

[[libass_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.15.1+0"

[[libblastrampoline_jll]]
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"

[[libfdk_aac_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "2.0.2+0"

[[libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"

[[libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "c45f4e40e7aafe9d086379e5578947ec8b95a8fb"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+0"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

[[x264_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2021.5.5+0"

[[x265_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.5.0+0"

[[xkbcommon_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll", "Wayland_protocols_jll", "Xorg_libxcb_jll", "Xorg_xkeyboard_config_jll"]
git-tree-sha1 = "ece2350174195bb31de1a63bea3a41ae1aa593b6"
uuid = "d8fb68d0-12a3-5cfd-a85a-d49703b185fd"
version = "0.9.1+5"
"""

# ╔═╡ Cell order:
# ╟─a8253062-df3c-11eb-26e1-0dcff18bf886
# ╠═e8668469-d378-463e-a8be-324f2362d90b
# ╠═189e4b15-a8bf-4b9b-8832-1e41be5ade12
# ╠═c347e5d8-7da2-4aad-aa56-cec1cd6ee6f7
# ╠═b81c4dba-caf2-4293-93be-134ae7194877
# ╠═e0b6e55a-d6f3-4125-9796-a8463c7e00cd
# ╟─fd018c1d-6a0d-42bb-8605-a599c70709ee
# ╠═2b2defdf-66a3-44a2-9e78-25738dfa9f02
# ╠═2a880954-0413-491e-bd55-0b0a9de2e2e4
# ╠═4d714c5c-cbde-4750-83c2-11ea89bf3041
# ╠═2af83733-4752-467d-93cc-1db8209d71dd
# ╠═31098999-eba6-474c-87bf-3d8929ee5017
# ╟─7ead1c90-772b-40fe-8388-9f6347316c2a
# ╠═f09b7267-b5a6-46dd-9ff7-ac48f61531b2
# ╠═460673fc-b9be-4779-b7c9-5f158e54f0c4
# ╠═dcee0976-8f6d-4dba-9d6c-a91561870419
# ╠═0ac33952-951c-45be-beb3-e0a43f8b6d60
# ╠═2eb8bc93-f6e8-4ec8-a013-dad617a13359
# ╠═ec08bb0a-cee7-47e6-a6eb-440673799d7c
# ╠═18f474f7-72be-4a36-afb4-147592bd68df
# ╠═1710cfd1-89c3-4bf8-b825-e76e7c898d74
# ╟─84b55287-2b2e-41ad-86b2-2dcdd42634e6
# ╠═c22c549b-f588-4c13-8540-978af37ed666
# ╠═a6928e0a-b892-4416-ac66-55e28d60aa7e
# ╠═e9cbab99-d1c7-44d5-a44d-10d47819e055
# ╠═b2cc77c1-a578-4290-adda-da4b29ca3d5f
# ╠═f476676e-b0d6-46fa-829c-0e691abddffd
# ╠═6ac3be67-7dae-42e4-95fd-b0df707892bb
# ╠═116f6639-9fe5-4f6d-92c2-a6441f11a6d2
# ╠═852b84b4-5112-4a1c-bece-a767cee13768
# ╠═93fc5b34-18cc-4a88-9984-a5762305b946
# ╠═badfeed7-aabf-44ae-8a97-ab5ca797bf76
# ╠═d1b49c5e-e9a2-4b44-90e9-622fab40c740
# ╟─1ef4e805-3dd9-4f39-a697-ddc0b4f04ad8
# ╠═8f32367b-b19b-4c18-80ff-5edaabcfb0d9
# ╠═ad90ebc0-99f2-4636-bce8-12abf791a69a
# ╠═dd28d0f8-dcf5-45b0-80f7-9aca4c2ca828
# ╠═2e77a377-69af-496e-8e06-59fa8135fd29
# ╠═2dcd0f66-f906-4358-907b-7aa0a9199c01
# ╠═da3f4379-7b2d-4efc-a9b2-5dcccd4a7d40
# ╠═d088a142-f43a-4347-92ca-fb0d6569a262
# ╠═51170e8f-2802-4450-b0f6-795b5ad9cacd
# ╠═31799b9e-1da0-4e02-8899-2cf7e6ce9563
# ╠═f8bb8da7-20d0-43da-846e-5130e7b38edc
# ╠═9fc48c4a-f3f4-4a1a-9fb3-b82a08f3c394
# ╠═df9e0973-7c43-445e-86bb-fa7030c650e1
# ╠═cf4f4bf4-8a47-401a-b569-905c9b3cd9fd
# ╠═b08df8b1-de6f-4b71-a650-48e483d91a3e
# ╠═ec2d9dea-e4d7-4703-8422-f4d9c4aec3fd
# ╠═e9847c59-f98f-419d-88c1-3200ec3e3b4a
# ╠═93c2a72c-629f-4512-a048-8245ed2ebeb0
# ╠═96f0ddeb-d722-4379-ba89-535f8ea15844
# ╠═25a97227-9531-40d4-b354-32663e016ad5
# ╠═85a067b0-24e1-47e6-87e7-6850f981cf04
# ╠═46922475-76df-4734-8762-b72dca549b08
# ╠═d218485c-875a-4d8c-b89b-c967c0f3f10f
# ╠═8b34269f-8fdf-44d4-9fa4-ad2e31aa0917
# ╠═bdf6e2d5-30df-4bb5-a755-b71f29d99b41
# ╠═a39dd1aa-868d-4819-877f-ccd4b856cb4c
# ╟─6045bf4a-e6ac-4411-bd0e-171ee51f3c97
# ╠═a82986c7-007e-4b6c-9afa-530dc062c5ce
# ╠═f667b91a-c07d-44b1-968c-55b80f11eb47
# ╟─5d443572-9d5e-4495-867f-e908d9b56716
# ╠═bbe3111b-18b3-4832-b636-621567a19632
# ╠═18ebd13e-88cd-453c-8690-1efc55b35900
# ╠═d9b1970e-f8e3-42a6-b2db-c6d4967bcec2
# ╠═e19bf203-1eac-457f-bd61-1d9bfff9aa88
# ╠═3c80c613-78f1-4136-8f6e-dd31b1a60e8e
# ╠═980eed0d-3ba6-48a1-b31f-8a1446c96444
# ╠═620c1306-295e-4ed6-84a6-75fde9e27e66
# ╠═6aa9e5de-9daf-4b9a-9078-b909a9fc5e03
# ╠═0ef24eb1-e9d8-442c-ab8e-03f56735f3c5
# ╠═70e5c1b4-caf4-4760-a8b0-1a509604582e
# ╠═6fc9edc2-c2aa-4be8-9f74-d069de42acb6
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002


text:
# This file was generated, do not modify it. # hide
Random.seed!(1515)

@pipeline SPCA(std = Standardizer(),
               pca = PCA())
spca_mdl = SPCA()
spca = machine(spca_mdl, X)
fit!(spca)
W = transform(spca, X)
names(W)

max_stars_repo_name: vdayanand/MLJTutorials

max_issues_repo_name: vdayanand/MLJTutorials

max_forks_repo_name: vdayanand/MLJTutorials


text:
module SPICE

export SpiceError

deps = abspath(joinpath(splitdir(@__FILE__)[1], "..", "deps", "deps.jl"))
if isfile(deps)
    include(deps)
else
    error("libcspice was not found. Please run 'Pkg.build(\"SPICE\").")
end

function __init__()
    # Set error handling to return on error
    ccall((:erract_c, libcspice), Cvoid, (Cstring, Cint, Cstring), "SET", 0, "RETURN")
    # Do not print error messages
    ccall((:errprt_c, libcspice), Cvoid, (Cstring, Cint, Cstring), "SET", 0, "NONE")
    nothing
end

struct SpiceError <: Exception
    msg::String
end

Base.show(io::IO, ex::SpiceError) = print(io, ex.msg)

function handleerror()
    failed = ccall((:failed_c, libcspice), Bool, ())
    if failed
        # Retrive error message
        msg = Array{UInt8}(undef, 1841)
        ccall((:getmsg_c, libcspice), Cvoid, (Cstring, Cint, Ref{UInt8}), "LONG", 1841, msg)
        message = String(msg[1:findfirst(iszero, msg) - 1])
        # Reset error status and throw Julia error
        ccall((:reset_c, libcspice), Cvoid, ())
        throw(SpiceError(message))
    end
    nothing
end

macro checkdims(m::Int, n::Int, arr::Symbol)
    name = string(arr)
    quote
        m1, n1 = size($(esc(arr)))
        if (m1, n1) != ($m, $n)
            msg = string("`$($name)` must be a $($m)x$($n) matrix but is ", m1, "x", n1, ".")
            throw(ArgumentError(msg))
        end
        nothing
    end
end

macro checkdims(len, arr::Symbol...)
    ex = :()
    for a in arr
        name = string(a)
        expr = quote
            n = length($(esc(a)))
            if n != $(esc(len))
                throw(ArgumentError("`$($name)` must have $($(esc(len))) elements but has $n."))
            end
        end
        push!(ex.args, expr)
    end
    :($ex; nothing)
end

# CSPICE data types
const SpiceBoolean = Cint
const SpiceChar = UInt8
const SpiceDouble = Cdouble
const SpiceInt = Cint

function chararray(strings)
    m = length(strings)
    # Longest string + terminator
    n = maximum(length.(strings)) + 1
    out = fill(UInt8(0), (n, m))
    for (i, s) in enumerate(strings)
        start = n * (i - 1) + 1
        stop = start + length(s) - 1
        out[start:stop] = codeunits(s)
    end
    out, m, n
end

function chararray_to_string(array::Vector{UInt8})
    idx = findfirst(iszero, array)
    idx = idx === nothing ? length(array) : idx - 1
    String(array[1:idx])
end

function chararray_to_string(array::Matrix{UInt8}, nmax=-1)
    strings = String[]
    m, n = size(array)
    n = nmax == -1 ? n : nmax
    n == 0 && return strings
    for i = 1:n
        line = array[:, i]
        idx = findfirst(iszero, line)
        idx = idx === nothing ? length(line) : idx - 1
        push!(strings, String(line[1:idx]))
    end
    strings
end

function array_to_cmatrix(array; n=0)
    cmat = hcat(array...)
    if n != 0
        m = size(cmat, 1)
        m != n && throw(ArgumentError("Expected each vector to have $n elements."))
    end
    cmat
end

function array_to_cmatrix(array::Vector{Vector{Int}}; n=0)
    array = map(x->SpiceInt.(x), array)
    cmat = hcat(array...)
    if n != 0
        m = size(cmat, 1)
        m != n && throw(ArgumentError("Expected each vector to have $n elements."))
    end
    cmat
end

function cmatrix_to_array(matrix)
    arr = [matrix[:, i] for i in 1:size(matrix, 2)]
end

function cmatrix_to_array(matrix::Matrix{SpiceInt})
    arr = [Int.(matrix[:, i]) for i in 1:size(matrix, 2)]
end

include("cells.jl")
include("types.jl")

include("a.jl")
include("b.jl")
include("c.jl")
include("d.jl")
include("e.jl")
include("f.jl")
include("g.jl")
include("h.jl")
include("i.jl")
include("j.jl")
include("k.jl")
include("l.jl")
include("m.jl")
include("n.jl")
include("o.jl")
include("p.jl")
include("q.jl")
include("r.jl")
include("s.jl")
include("t.jl")
include("u.jl")
include("v.jl")
include("w.jl")
include("x.jl")

end # module


text:
### interpreter
import Core.Compiler: AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, OptimizationParams
import Core.Compiler: get_world_counter, get_inference_cache, code_cache, lock_mi_inference, unlock_mi_inference

struct KernelInterpreter{Inner<:AbstractInterpreter} <: AbstractInterpreter
    # Wrapped AbstractInterpreter
    inner::Inner
end
KernelInterpreter(interp) = KernelInterpreter(interp)

# Quickly and easily satisfy the AbstractInterpreter API contract
get_world_counter(ki::KernelInterpreter) =  get_world_counter(ki.inner)
get_inference_cache(ki::KernelInterpreter) = get_inference_cache(ki.inner)
InferenceParams(ki::KernelInterpreter) = InferenceParams(ki.inner)
OptimizationParams(ki::KernelInterpreter) = OptimizationParams(ki.inner)
Core.Compiler.may_optimize(ni::KernelInterpreter) = true # TODO: Forward?
Core.Compiler.may_compress(ni::KernelInterpreter) = true # TODO: Forward?
Core.Compiler.may_discard_trees(ni::KernelInterpreter) = true # TODO: Forward?
Core.Compiler.add_remark!(ni::KernelInterpreter, sv::InferenceState, msg) = Core.Compiler.add_remark!(ni.inner, sv, msg)

### codegen/interence integration
code_cache(ki::KernelInterpreter) = WorldView(get_cache(typeof(ki.inner)), get_world_counter(ki))

# No need to do any locking since we're not putting our results into the runtime cache
lock_mi_inference(ki::KernelInterpreter, mi::MethodInstance) = nothing
unlock_mi_inference(ki::KernelInterpreter, mi::MethodInstance) = nothing

function cpu_invalidate(replaced, max_world)
    cache = get_cache(NativeInterpreter)
    invalidate(cache, replaced, max_world, 0)
    return nothing
end

function cpu_cache_lookup(mi, min_world, max_world)
    wvc = WorldView(get_cache(NativeInterpreter), min_world, max_world)
    return Core.Compiler.get(wvc, mi, nothing)
end

function cpu_infer(mi, min_world, max_world)
    wvc = WorldView(get_cache(NativeInterpreter), min_world, max_world)
    interp = KernelInterpreter(NativeInterpreter(min_world))
    return infer(wvc, mi, interp)
end

function infer(wvc, mi, interp)
    src = Core.Compiler.typeinf_ext_toplevel(interp, mi)
    # inference populates the cache, so we don't need to jl_get_method_inferred
    @assert Core.Compiler.haskey(wvc, mi)

    # if src is rettyp_const, the codeinfo won't cache ci.inferred
    # (because it is normally not supposed to be used ever again).
    # to avoid the need to re-infer, set that field here.
    # This is required for being able to use `cache_lookup` as the lookup
    # function for `CodegenParams` and `jl_create_native`.
    ci = Core.Compiler.getindex(wvc, mi)
    if ci !== nothing && ci.inferred === nothing
        ci.inferred = src
    end
    return
end


text:
using Distributions
using Base.LinAlg.BLAS

abstract RBM

typealias Mat{T} AbstractArray{T, 2}
typealias Vec{T} AbstractArray{T, 1}

type BernoulliRBM <: RBM
    W::Mat{Float64}
    vbias::Vec{Float64}
    hbias::Vec{Float64}
    dW_prev::Mat{Float64}
    momentum::Float64
    function BernoulliRBM(n_vis::Int, n_hid::Int; sigma=0.001, momentum=0.9)
        new(rand(Normal(0, sigma), (n_hid, n_vis)),
            zeros(n_vis), zeros(n_hid),
            zeros(n_hid, n_vis),
            momentum)
    end
    function Base.show(io::IO, rbm::BernoulliRBM)
        n_vis = size(rbm.vbias, 1)
        n_hid = size(rbm.hbias, 1)
        print(io, "BernoulliRBM($n_vis, $n_hid)")
    end
end

type GRBM <: RBM
    W::Mat{Float64}
    vbias::Vec{Float64}
    hbias::Vec{Float64}
    dW_prev::Mat{Float64}
    momentum::Float64
    function GRBM(n_vis::Int, n_hid::Int; sigma=0.001, momentum=0.9)
        new(rand(Normal(0, sigma), (n_hid, n_vis)),
            zeros(n_vis), zeros(n_hid),
            zeros(n_hid, n_vis),
            momentum)
    end
    function Base.show(io::IO, rbm::GRBM)
        n_vis = size(rbm.vbias, 1)
        n_hid = size(rbm.hbias, 1)
        print(io, "GRBM($n_vis, $n_hid)")
    end
end

function logistic(x)
    return 1 ./ (1 + exp(-x))
end

function mean_hiddens(rbm::RBM, vis::Mat{Float64})
    p = rbm.W * vis .+ rbm.hbias
    return logistic(p)
end

function sample_hiddens(rbm::RBM, vis::Mat{Float64})
    p = mean_hiddens(rbm, vis)
    return float(rand(size(p)) .< p)
end

function sample_visibles(rbm::BernoulliRBM, hid::Mat{Float64})
    p = rbm.W' * hid .+ rbm.vbias
    p = logistic(p)
    return float(rand(size(p)) .< p)
end

function sample_visibles(rbm::GRBM, hid::Mat{Float64})
    mu = logistic(rbm.W' * hid .+ rbm.vbias)
    sigma2 = 0.01                   # using fixed standard diviation
    samples = zeros(size(mu))
    for j=1:size(mu, 2), i=1:size(mu, 1)
        samples[i, j] = rand(Normal(mu[i, j], sigma2))
    end
    return samples
end

function gibbs(rbm::RBM, vis::Mat{Float64}; n_times=1)
    v_pos = vis
    h_pos = sample_hiddens(rbm, v_pos)
    v_neg = sample_visibles(rbm, h_pos)
    h_neg = sample_hiddens(rbm, v_neg)
    for i=1:n_times-1
        v_neg = sample_visibles(rbm, h_neg)
        h_neg = sample_hiddens(rbm, v_neg)
    end
    return v_pos, h_pos, v_neg, h_neg
end

function free_energy(rbm::RBM, vis::Mat{Float64})
    vb = sum(vis .* rbm.vbias, 1)
    Wx_b_log = sum(log(1 + exp(rbm.W * vis .+ rbm.hbias)), 1)
    return - vb - Wx_b_log
end

function score_samples(rbm::RBM, vis::Mat{Float64}; sample_size=10000)
    if issparse(vis)
        # sparse matrices may be infeasible for this operation
        # so using only little sparse
        cols = sample(1:size(vis, 2), sample_size)
        vis = full(vis[:, cols])
    end
    n_feat, n_samples = size(vis)
    vis_corrupted = copy(vis)
    idxs = rand(1:n_feat, n_samples)
    for (i, j) in zip(idxs, 1:n_samples)
        vis_corrupted[i, j] = 1 - vis_corrupted[i, j]
    end
    fe = free_energy(rbm, vis)
    fe_corrupted = free_energy(rbm, vis_corrupted)
    return n_feat * log(logistic(fe_corrupted - fe))
end

function update_weights!(rbm, h_pos, v_pos, h_neg, v_neg, lr, buf)
    dW = buf
    # dW = (h_pos * v_pos') - (h_neg * v_neg')
    gemm!('N', 'T', 1.0, h_neg, v_neg, 0.0, dW)
    gemm!('N', 'T', 1.0, h_pos, v_pos, -1.0, dW)
    rbm.W += lr * dW
    axpy!(lr, dW, rbm.W)
    # rbm.W += rbm.momentum * rbm.dW_prev
    axpy!(lr * rbm.momentum, rbm.dW_prev, rbm.W)
    # save current dW
    copy!(rbm.dW_prev, dW)
end

function fit_batch!(rbm::RBM, vis::Mat{Float64};
                    buf=None, lr=0.1, n_gibbs=1)
    buf = buf == None ? zeros(size(rbm.W)) : buf
    v_pos, h_pos, v_neg, h_neg = gibbs(rbm, vis, n_times=n_gibbs)
    lr = lr / size(v_pos, 1)
    update_weights!(rbm, h_pos, v_pos, h_neg, v_neg, lr, buf)
    rbm.hbias += vec(lr * (sum(h_pos, 2) - sum(h_neg, 2)))
    rbm.vbias += vec(lr * (sum(v_pos, 2) - sum(v_neg, 2)))
    return rbm
end

function fit(rbm::RBM, X::Mat{Float64};
             lr=0.1, n_iter=10, batch_size=100, n_gibbs=1)
    @assert minimum(X) >= 0 && maximum(X) <= 1
    n_samples = size(X, 2)
    n_batches = int(ceil(n_samples / batch_size))
    w_buf = zeros(size(rbm.W))
    for itr=1:n_iter
        tic()
        for i=1:n_batches
            # println("fitting $(i)th batch")
            batch = X[:, ((i-1)*batch_size + 1):min(i*batch_size, end)]
            batch = full(batch)
            fit_batch!(rbm, batch, buf=w_buf, n_gibbs=n_gibbs)
        end
        toc()
        @printf("Iteration #%s, pseudo-likelihood = %s\n",
                itr, mean(score_samples(rbm, X)))
    end
end

function transform(rbm::RBM, X::Mat{Float64})
    return mean_hiddens(rbm, X)
end

function generate(rbm::RBM, vis::Vec{Float64}; n_gibbs=1)
    return gibbs(rbm, reshape(vis, length(vis), 1); n_times=n_gibbs)[3]
end

function generate(rbm::RBM, X::Mat{Float64}; n_gibbs=1)
    return gibbs(rbm, X; n_times=n_gibbs)[3]
end

function components(rbm::RBM; transpose=true)
    return if transpose rbm.W' else rbm.W end
end


text:
module Languages
using JSON
using InteractiveUtils

	export Language
	export english_name, isocode, name, detect
	export articles, definite_articles, indefinite_articles
	export prepositions
	export pronouns
	export stopwords
	export LanguageDetector
	export list_languages

	cache = Dict()

	include("types.jl")
	include("utils.jl")
	include("word_lists.jl")
	include("whatlang.jl")

	function __init__()
	    trigram_models_json = JSON.parse(read(joinpath(dirname(@__FILE__), "..", "data", "data.json"), String))
	    global trigram_models = Dict{String, Dict}()
	    for (script, langs) in trigram_models_json
	        for (lang, trigrams) in langs #store only supported langs
				if from_code(lang) != nothing
	            	get!(trigram_models, script, Dict{String, Vector{String}}())[lang] = split(trigrams, '|')
	        	end
	    	end
		end
	end

	## Deprecations
	@Base.deprecate_binding EnglishLanguage English
	@Base.deprecate_binding GermanLanguage German

end


text:
module Plasma

using Flux
using ModelingToolkit
using GalacticOptim
using DiffEqFlux
using CUDA
using NeuralPDE
using LinearAlgebra
using DomainSets
import ModelingToolkit: Interval, infimum, supremum

abstract type AbstractPlasma end

abstract type AbstractGeometry end

abstract type AbstractDistribution end

abstract type AbstractCoil end

"""
Species holds

q – charge in C
m – mass in Kg

to describe a particle species
"""
struct Species{ T <: Number }
    q::T # charge in C
    m::T # mass in Kg

    function Species(q=-1.602176634e-19, m=9.10938188e-31)
        new{typeof(q)}(
            q, m
        )
    end
end

"""
Velocity distribution of particles

P – probability function
species – which species of particle
"""
struct Distribution <: AbstractDistribution
    P::Function
    species::Species
end

"""
Describes the initial geometry of a plasma

f – conditional function

# Example

Geometry(x -> x > 0.4 ? 1. : 0)
"""
struct Geometry{F <: Function} <: AbstractGeometry
    f::F

    function Geometry(f= _ -> 1)
        new{typeof(f)}(f)
    end
end

"""
CollisionlessPlasma object that can be passed to Plasma.solve for simulation

It takes a geometry and a vector of distributions (one for every particle).
"""
struct CollisionlessPlasma{ G <: AbstractGeometry } <: AbstractPlasma
    distributions::Vector{Distribution}
    geometry::G
end

"""
ElectrostaticPlasma object that can be passed to Plasma.solve for simulation

It takes a geometry and a vector of distributions (one for every particle).
"""
struct ElectrostaticPlasma{ G <: AbstractGeometry } <: AbstractPlasma
    distributions::Vector{Distribution}
    geometry::G
end

"""
Object to hold (and save) the results of Plasma.solve.

It consists of

plasma – CollisionlessPlasma or ElectrostaticPlasma object
vars – dependent variables
dict_vars – dictionary of dependent variables
phi – trained trial solution that approximates plasma movement
res – result of optimization
initθ – weights of the neural network
domains – domains of the simulation
"""
struct PlasmaSolution{ P <: AbstractPlasma, V, DV, PHI, RE, IN, DO, LO, TI }
    plasma::P
    vars::V
    dict_vars::DV
    phi::PHI
    res::RE
    initθ::IN
    domains::DO
    losses::LO
    times::TI
end
struct Constants{ T <: Number}
    μ_0::T
    ϵ_0::T

    function Constants()
        μ_0 = 1.25663706212e-6 # N A⁻²
        ϵ_0 = 8.8541878128e-12 # F ms⁻¹
        new{typeof(μ_0)}(μ_0, ϵ_0)
    end
end

const species = (
    e = Species(),
    p = Species(1.602176634e-19 ,1.673523647e-27),
    D = Species(1.602176634e-19 ,3.344476425e-27),
    T = Species(1.602176634e-19 ,5.00735588e-27),
    He³ = Species(1.602176634e-19 ,5.00641192e-27),
    He⁴ = Species(1.602176634e-19 ,6.64465620e-27),
)

include("distribution.jl")
include("boundaries.jl")
include("solve.jl")
include("geometry.jl")
include("analyze.jl")

export CollisionlessPlasma, ElectrostaticPlasma, PlasmaSolution
export Distribution, Maxwellian
export Neumann, Dirichlet, Reflective
export Geometry
export Species, species
export Constants

end


text:
### A Pluto.jl notebook ###
# v0.17.2

using Markdown
using InteractiveUtils

# ╔═╡ 48be9ff8-f712-11eb-2c5f-5bcd200ee565
begin
    import Pkg
    Pkg.activate(Base.current_project())

	using IntrinsicDecoherence
end

# ╔═╡ c57eeb5f-f310-44ed-be9c-6692f46424c5
begin
	using PyPlot
	using LaTeXStrings
	ion()
	rc("text", usetex = true)
end

# ╔═╡ e8c55ba3-262e-459a-a101-fc7f4461fb90
begin
	const α = 4
	const ω = 4
end;

# ╔═╡ fb33fbf6-73e2-4e8f-891e-19b7fb8db5dd
t1 = range(0, stop = 7, length = 500);

# ╔═╡ aa43212b-f5f9-4fad-909d-5081ede80e21
begin
	tann1 = [quad_a(α, 0.1, ω, 10, t1[τ]) for τ in 1:length(t1)];
	tann2 = [quad_a(α, 0.7, ω, 10, t1[τ]) for τ in 1:length(t1)];
	tann3 = [quad_a(α, 1.5, ω, 10, t1[τ]) for τ in 1:length(t1)];
end;

# ╔═╡ 84e0e33b-d58f-4b85-a770-cec5da2d59d1
begin
	figreim1 = figure(figsize = (10, 6))
	axreim1 = gca()

	axreim1.plot(t1, real(tann1), "r", lw = 3, label = L"\lambda = 0.1")
	axreim1.plot(t1, real(tann2), "g", lw = 3, label = L"\lambda = 0.7")
	axreim1.plot(t1, real(tann3), "b", lw = 3, label = L"\lambda = 1.5")

	#axreim1.set_ylim([-9, 9])

	axreim1.legend(fontsize = 18)
	axreim1.set_ylabel(L"\textrm{Amplitude}", fontsize = 20)
	axreim1.set_xlabel(L"t\; [s]", fontsize = 18)
	setp(axreim1.get_xticklabels(), fontsize = 18)
	setp(axreim1.get_yticklabels(), fontsize = 18)
	axreim1.set_title(L"Expectation value of $\langle\hat{a}^{\dagger}+\hat{a}\rangle$", fontsize = 18)

	tight_layout()

	#savefig("quadex.pdf", dpi = 600)
end

# ╔═╡ 98a14d54-30c0-4526-b791-8991d86c8ceb
begin
	tnum1 = [num_a(α, 0.1, ω, 10, t1[τ]) for τ in 1:length(t1)];
	tnum2 = [num_a(α, 0.7, ω, 10, t1[τ]) for τ in 1:length(t1)];
	tnum3 = [num_a(α, 1.5, ω, 10, t1[τ]) for τ in 1:length(t1)];
end;

# ╔═╡ 526a3122-2c23-4939-a4d6-b89e4bfb8c92
begin
	fignum = figure(figsize = (10, 6))
	axnum = gca()

	axnum.plot(t1, real(tnum1), "r", lw = 3, label = L"\lambda = 0.1")
	axnum.plot(t1, real(tnum2), "g", lw = 3, label = L"\lambda = 0.7")
	axnum.plot(t1, real(tnum3), "b", lw = 3, label = L"\lambda = 1.5")

	axnum.set_ylim([16, 21.5])

	axnum.legend(fontsize = 18)
	axnum.set_ylabel(L"\textrm{Number of Photons}", fontsize = 20)
	axnum.set_xlabel(L"t\; [s]", fontsize = 18)
	setp(axnum.get_xticklabels(), fontsize = 18)
	setp(axnum.get_yticklabels(), fontsize = 18)
	axnum.set_title(L"Expectation value of $\langle\hat{a}^{\dagger}\hat{a}\rangle$", fontsize = 20)

	tight_layout()

	#savefig("nex.pdf", dpi = 600)
end

# ╔═╡ Cell order:
# ╠═48be9ff8-f712-11eb-2c5f-5bcd200ee565
# ╠═c57eeb5f-f310-44ed-be9c-6692f46424c5
# ╠═e8c55ba3-262e-459a-a101-fc7f4461fb90
# ╠═fb33fbf6-73e2-4e8f-891e-19b7fb8db5dd
# ╠═aa43212b-f5f9-4fad-909d-5081ede80e21
# ╠═84e0e33b-d58f-4b85-a770-cec5da2d59d1
# ╠═98a14d54-30c0-4526-b791-8991d86c8ceb
# ╠═526a3122-2c23-4939-a4d6-b89e4bfb8c92

max_stars_repo_name: rurz/IntrinsicDecoherence

max_issues_repo_name: rurz/IntrinsicDecoherence

max_forks_repo_name: rurz/IntrinsicDecoherence


text:
using Revise
using PyCall
using PyPlot
using Infiltrator
using Bem2d
ow = pyimport("okada_wrapper") # from okada_wrapper import dc3dwrapper

"""
    plotformat(fontsize)

Standard plot formatting.
"""
function plotformat(fontsize)
    # gca().set_xlim([-5, 5]); gca().set_ylim([-1.0, 1.0])
    # gca().set_xticks([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5])
    # gca().set_yticks([-1.00, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00])
    legend(fontsize=fontsize)
    gca().tick_params("both", labelsize=fontsize)
    xlabel(L"$x$ (m)", fontsize=fontsize)
    return nothing
end

"""
    okadalocal(xokada)

Okada profile for a 45 dipping fault.
"""
function okadalocal(xokada)
    uxokada = zeros(length(xokada))
    uyokada = zeros(length(xokada))

    for i in 1:length(xokada)
        # Fault dipping at 45 degrees
        _, u, _ = ow.dc3dwrapper(
            2.0 / 3.0,
            [0, xokada[i] + 0.5, 0],
            0.5,
            45,  # 135
            [-1000, 1000],
            [-sqrt(2) / 2, sqrt(2) / 2],
            [0.0, 1.0, 0.0],
        )
        uxokada[i] = u[2]
        uyokada[i] = u[3]
    end
    return uxokada, uyokada
end

"""
    okadalocalinterior(xokada)

Okada profile for a 45 dipping fault.
"""
function okadalocalinterior(x, y)
    uxokada = zeros(length(x))
    uyokada = zeros(length(x))

    for i in 1:length(x) # Fault dipping at 45 degrees
        _, u, _ = ow.dc3dwrapper(
            2.0 / 3.0,
            [0, x[i] + 10e3 * 0.5, y[i]],
            10e3 * 0.5,
            45,  # 135
            [-1000e3, 1000e3],
            [-10e3 * sqrt(2) / 2, 10e3 * sqrt(2) / 2],
            [0.0, 1.0, 0.0],
        )
        uxokada[i] = u[2]
        uyokada[i] = u[3]
    end

    return uxokada, uyokada
end

"""
    hackybem(els, mu, nu)

Hacky BEM approximation to Okada profile for a 45 dipping fault.
The purpose of keeping this is that while a little "hacky" it
demonstrates the conceptual behind a mechanical interpretation of
the indirect BEM for the okada problem
"""
function hackybem(els, idx, faultslip, mu, nu)
    Tfaultsurface, _, Hfaultsurface = partialsconstdispstress(slip2dispstress, els, idx["fault"], idx["surface"], mu, nu)
    Tsurfacesurface, _, Hsurfacesurface = partialsconstdispstress(slip2dispstress, els, idx["surface"], idx["surface"], mu, nu)
    ufullspacehacky = Tfaultsurface * faultslip
    usurfacehacky = inv(Hsurfacesurface) * (Hfaultsurface * faultslip)
    return ufullspacehacky, usurfacehacky
end

"""
    okadaindirect()

Comparison of surface displacements near a thrust fault dipping
at 45 degrees.  Includes both constant and quadratic elements.
"""
function okadaindirect()
    close("all")
    mu = 30e9
    nu = 0.25

    # 45 degree dipping fault
    els = Elements(Int(1e5))
    nfault = 20
    x1, y1, x2, y2 = discretizedline(-10e3, -10e3, 0, 0, nfault)
    for i in 1:length(x1)
        els.x1[els.endidx + i] = x1[i]
        els.y1[els.endidx + i] = y1[i]
        els.x2[els.endidx + i] = x2[i]
        els.y2[els.endidx + i] = y2[i]
        els.name[els.endidx + i] = "fault"
    end
    standardize_elements!(els)

    # Free surface
    nfreesurf = 100
    # x1, y1, x2, y2 = discretizedline(-5, 0, 5, 0, nfreesurf)
    x1, y1, x2, y2 = discretizedline(-200e3, 0, 200e3, 0, nfreesurf)
    for i in 1:length(x1)
        els.x1[els.endidx + i] = x1[i]
        els.y1[els.endidx + i] = y1[i]
        els.x2[els.endidx + i] = x2[i]
        els.y2[els.endidx + i] = y2[i]
        els.name[els.endidx + i] = "surface"
    end
    standardize_elements!(els)
    idx = getidxdict(els)

    #! Parameters for BEM solutions
    xbem = els.xcenter[idx["surface"]]

    #! Hacky BEM
    ufullspacehacky, uhalfspacehacky = hackybem(els, idx, sqrt(2)/2 .* ones(2*nfault), mu, nu)

    #! Indirect BEM
    T_psurface_qfault, H_psurface_qfault = PUTC(slip2dispstress, els, idx["surface"], idx["fault"], mu, nu)
    T_psurface_qsurface, H_psurface_qsurface = PUTC(slip2dispstress, els, idx["surface"], idx["surface"], mu, nu)
    bcs = sqrt(2.0)/2.0 * ones(2*nfault)
    ueff = inv(H_psurface_qsurface) * H_psurface_qfault * bcs
    uhalfspaceindirect = ueff

    Usurface, _ = constdispstress(slip2dispstress, xbem, zeros(length(xbem)), els, idx["surface"], ueff[1:2:end], ueff[2:2:end], mu, nu)
    Ufault, _ = constdispstress(slip2dispstress, xbem, zeros(length(xbem)), els, idx["fault"], bcs[1:2:end], bcs[2:2:end], mu, nu)
    uxbemsurface = -Usurface[:, 1] + Ufault[:, 1]
    uybemsurface = -Usurface[:, 2] + Ufault[:, 2]

    #! Interior evaluation both BEM and Okada
    # This does not give the right answer at the surface
    nobs = 50
    x, y = obsgrid(-50e3, -30e3, 50e3, 0, nobs)
    Usurface, Ssurface = constdispstress(slip2dispstress, x, y, els, idx["surface"], ueff[1:2:end], ueff[2:2:end], mu, nu)
    Ufault, Sfault = constdispstress(slip2dispstress, x, y, els, idx["fault"], bcs[1:2:end], bcs[2:2:end], mu, nu)
    uxbem = -Usurface[:, 1] + Ufault[:, 1]
    uybem = -Usurface[:, 2] + Ufault[:, 2]
    uxokadainterior, uyokadainterior = okadalocalinterior(x, y)

    #! 18 panel plot
    fontsize = 20
    markersize = 12
    linewidth = 2.0
    nrows = 3
    ncols = 3
    xmat = reshape(x, nobs, nobs)
    ymat = reshape(y, nobs, nobs)
    contourvec = collect(LinRange(-0.5, 0.5, 50))
    figure(figsize=(30, 20))

    # Okada results
    subplot(nrows, ncols, 1)
    quiver(x, y, uxokadainterior, uyokadainterior)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("u (BEM)", fontsize=fontsize)

    subplot(nrows, ncols, 2)
    umat = reshape(uxokadainterior, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend = "both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("ux (Okada)", fontsize=fontsize)

    subplot(nrows, ncols, 3)
    umat = reshape(uyokadainterior, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend = "both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("uy (Okada)", fontsize=fontsize)

    # IBEM results
    subplot(nrows, ncols, 4)
    quiver(x, y, uxbem, uybem)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("u (BEM)", fontsize=fontsize)

    subplot(nrows, ncols, 5)
    umat = reshape(uxbem, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend="both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("ux (BEM)", fontsize=fontsize)

    subplot(nrows, ncols, 6)
    umat = reshape(uybem, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend="both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("uy (BEM)", fontsize=fontsize)

    # Residuals
    subplot(nrows, ncols, 7)
    quiver(x, y, uxbem .- uxokadainterior, uybem - uyokadainterior)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("u (residual)", fontsize=fontsize)

    subplot(nrows, ncols, 8)
    umat = reshape(uxbem .- uxokadainterior, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend="both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("ux (residual)", fontsize=fontsize)

    subplot(nrows, ncols, 9)
    umat = reshape(uybem .- uyokadainterior, nobs, nobs)
    contourf(xmat, ymat, umat, levels=contourvec)
    cbar = colorbar(fraction=0.05, pad=0.05, extend="both")
    cbar.ax.tick_params(labelsize=fontsize)
    contour(xmat, ymat, umat, levels=contourvec, colors="k", linewidths=0.5)
    gca().set_aspect("equal")
    gca().tick_params(labelsize=fontsize)
    xlabel("x (m)", fontsize=fontsize)
    ylabel("y (m)", fontsize=fontsize)
    title("uy (residual)", fontsize=fontsize)
    tight_layout()
    show()

    # #! Okada solution
    # xokada = collect(LinRange(-5, 5, 1000))
    # uxokada, uyokada = okadalocal(xokada)

    # #! Plot comparison between BEM and Okada
    # figure(figsize = (20, 20))

    # ax = subplot(2, 1, 1)
    # plot(xokada, uxokada, "-k", linewidth=linewidth, label="Okada (halfspace)")
    # plot(xbem, uhalfspacehacky[1:2:end], "bx", markeredgewidth=linewidth, markersize=markersize, label="hacky BEM (halfspace)")
    # plot(xbem, uhalfspaceindirect[1:2:end], "r+", markeredgewidth=linewidth, markersize=markersize, label="indirect BEM (halfspace)")
    # plot(xbem, uxbemsurface, ".g", markeredgewidth=linewidth, markersize=markersize, label = "interior BEM (halfspace)")
    # ylabel(L"$u_x$ (m)", fontsize=fontsize)
    # plotformat(fontsize)

    # ax = subplot(2, 1, 2)
    # plot(xokada, uyokada, "-k", linewidth=linewidth, label="Okada (halfspace)")
    # plot(xbem, uhalfspacehacky[2:2:end], "bx", markeredgewidth=linewidth, markersize=markersize, label = "hacky BEM (halfspace)")
    # plot(xbem, uhalfspaceindirect[2:2:end], "r+", markeredgewidth=linewidth, markersize=markersize, label = "indirect BEM (halfspace)")
    # plot(xbem, uxbemsurface, ".g", markeredgewidth=linewidth, markersize=markersize, label = "interior BEM (halfspace)")
    # ylabel(L"$u_y$ (m)", fontsize=fontsize)
    # plotformat(fontsize)
    # show()
end
okadaindirect()


text:
module ScratchNeuralNetwork

using LinearAlgebra, Plots

include("ActivationFunctions/Sigmoid.jl")
include("ActivationFunctions/Tanh.jl")
include("ActivationFunctions/ReLU.jl")
include("ActivationFunctionDerivatives/SigmoidDerivative.jl")
include("ActivationFunctionDerivatives/TanhDerivative.jl")
include("ActivationFunctionDerivatives/ReLUDerivative.jl")
include("LossFunctions/SumOfSquaresError.jl")
include("LossFunctions/MeanSquareError.jl")
include("LossFunctions/CrossEntropy.jl")
include("Architecture/FeedForward.jl")
include("Architecture/BackPropagation.jl")
include("Architecture/RunNeuralNetwork.jl")
include("Architecture/NeuralNetwork.jl")
#include("Plotting/PlotLossFunction.jl")

# Exports

export Sigmoid
export Tanh
export ReLU
export SigmoidDerivative
export TanhDerivative
export ReLUDerivative
export SumOfSquaresError
export MeanSquareError
export CrossEntropy
export FeedForward
export BackPropagation
export RunNeuralNetwork
export NeuralNetwork
#export PlotLossFunction

end


text:
module TestExamplesLiftMacro
using LiterateTest.AssertAsTest: @assert
include("../examples/lift-macro.jl")
end  # module