Last active
July 10, 2020 18:07
-
-
Save MasonProtter/4c5de8afc431dea3596cf803bc91fffb to your computer and use it in GitHub Desktop.
Revisions
-
MasonProtter revised this gist
Jul 10, 2020 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,4 +33,20 @@ Bra(a::Vector) = a' #+RESULTS: : 2×2 Array{Int64,2}: : 1 0 : 0 -1 #+BEGIN_SRC julia → = d`(|↑⟩ + |↓⟩)/√2` ← = d`(|↑⟩ - |↓⟩)/√2` d``` [⟨→|*σz*|→⟩ ⟨→|*σz*|←⟩ ⟨←|*σz*|→⟩ ⟨←|*σz*|←⟩] ``` #+END_SRC #+RESULTS: : 2×2 Array{Float64,2}: : 0.0 1.0 : 1.0 0.0 -
MasonProtter created this gist
Jul 10, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #+BEGIN_SRC julia const ketpat = r"\|.*?\>" ketrep(str) = "Ket("*(match(r"(?<=\|).*?(?=>)", str).match)*")" const brapat = r"\<.*?\|" brarep(str) = "Bra("*(match(r"(?<=<).*?(?=\|)", str).match)*")" function rep_braket(str) replace(replace(str, brapat => brarep), ketpat => ketrep) end parse_braket(str) = Meta.parse(rep_braket(str)) macro d_cmd(str) esc(parse_braket(str)) end Ket(args...) = [args...] Ket(a::Vector) = a Bra(args...) = [args...]' Bra(a::Vector) = a' Ket(a::Vector) = a Bra(a::Vector) = a' ↑ = [1, 0] ↓ = [0, 1]; σz = d`|↑>*<↑| - |↓>*<↓|` #+END_SRC #+RESULTS: : 2×2 Array{Int64,2}: : 1 0 : 0 -1