-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.qmd
143 lines (115 loc) ยท 3.56 KB
/
example.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
title: "An Example"
format:
julia-color-html: default
julia-color-pdf:
pdf-engine: xelatex
papersize: a4
code-block-bg: "#e0e0e0"
code-block-border-left: "#008000"
output-file: "example-latex.pdf"
julia-color-typst: default
execute:
cache: true
preserve-ansi: true
keep-ipynb: true
keep-md: true
keep-tex: true
keep-typ: true
---
## The JuliaMono font
Code example making heavy use of Unicode from [https://github.com/JuliaArrays/StaticArrays.jl/issues/537#issuecomment-439863841](https://github.com/JuliaArrays/StaticArrays.jl/issues/537#issuecomment-439863841)
```julia
function T(๐::AbstractArray,
๐::Tuple{AbstractArray,
Vararg{AbstractArray}},
๐::Tuple{AbstractArray, Vararg{AbstractArray}})
โ = kron
l = length(๐)
๐โ = SMatrix{l,l}(1.0I)
๐โ = SMatrix{1,1}(1.0I)
๐ = @SMatrix zeros(l,l)
N = length(๐[1])
โณ, โณสน = ๐
ฮโ, ฮโ = ๐
๐ฒโ = @MMatrix zeros(4,4)
๐โ = @SMatrix [1.0; 0.0; 0.0]
๐โ = @SMatrix [0.0; 1.0; 0.0]
for n = 1:N
index = SVector(1,2)
๐ฒโ[1:2,1:2] .= ฮโ[n][index,index]
๐ฒโ[3:4,3:4] .= ฮโ[n][index,index]
๐ฆ = hom(โณ[n])
๐ฆสน = hom(โณสน[n])
๐โ = (๐ฆ โ ๐ฆสน)
โโ๐ฎโ = [(๐โ โ ๐ฆสน) (๐โ โ ๐ฆสน) (๐ฆ โ ๐โ) (๐ฆ โ ๐โ)]
๐โ = โโ๐ฎโ * ๐ฒโ * โโ๐ฎโ'
๐บโ = ๐' * ๐โ * ๐
๐บโโปยน = inv(๐บโ)
๐โ = @SMatrix zeros(Float64,l,l)
for k = 1:l
๐โ = ๐โ[:,k]
โ๐โ๐บโ = (๐โ โ ๐โ') * ๐โ * (๐โ โ ๐) + (๐โ โ ๐') * ๐โ * (๐โ โ ๐โ)
# Accumulating the result in ๐โ allocates memory,
# even though the two terms in the
# summation are both SArrays.
๐โ = ๐โ + ๐โ * ๐บโโปยน * (โ๐โ๐บโ) * ๐บโโปยน * ๐โ' * ๐ * ๐โ'
end
๐ = ๐ + ๐โ
end
๐
end
```
## Colored console graphs produced by `Benchmarktools.jl`
```{julia}
using BenchmarkTools
@benchmark sum(rand(1000))
```
## Some output using ANSI escape codes
```{julia}
println("Some tests:")
printstyled("- Red ", color=:red)
printstyled("Green ", color=:green)
print("Black and ")
printstyled("Bold underline green\n", color=:green, bold=true, underline=true)
printstyled("- Normal black for comparison\n")
printstyled("- Hidden is implemented as light/dimmed\n", hidden=true)
printstyled("- Hidden is implemented as light/dimmed\n", hidden=true, italic=true)
printstyled("- Green background\n", color=:green, reverse=true)
printstyled("- A 256 bit color\n", color=142)
printstyled("- Some italic\n", italic=true)
printstyled("- and blue bold italic\n", italic=true, bold=true, color=:blue)
```
## Structure of floating point numbers
```{julia}
function printbitsf64(x::Float64)
s = bitstring(x)
printstyled(s[1], color = :blue, reverse=true)
printstyled(s[2:12], color = :green, reverse=true)
printstyled(s[13:end], color=:red, bold=true, reverse=true)
print("\n")
end
printbitsf64(27.56640625)
```
### Machine epsilon
```{julia}
Eps=0.5
while 1 != 1 + Eps
Eps /= 2
printbitsf64(1+Eps)
end
```
## Errors and Warnings
```{julia}
#| error: true
#| warn: true
3 < "four"
```
The `@warn` macro writes to the `stderr` channel:
```{julia}
#| error: true
#| warn: true
println(ฯ^2)
@warn "Last warning!"
1 + 41
```