Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starting Nelson's exercise solutions #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.quarto/
_site
tikz_*.svg
.DS_Store
22 changes: 22 additions & 0 deletions solutions:nelson-niu/finite-sets.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
struct FinSet
n::Int
end

struct FinFunction
dom::FinSet
codom::FinSet
values::Vector{Int}
end

A, B = FinSet(3), FinSet(2)
f = FinFunction(A, B, [1,2,2])

function product(X::FinSet, Y::FinSet)
x, y = X.n, Y.n
P = FinSet(x * y)

proj_left = FinFunction(P, X, [i for i in 1:X.n for j in 1:Y.n])
proj_right = FinFunction(P, Y, [j for i in 1:X.n for j in 1:Y.n])

return P, proj_left, proj_right
end
10 changes: 10 additions & 0 deletions solutions:nelson-niu/graphs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Catlab, Catlab.CategoricalAlgebra

@present GrphDiagram(FreeSchema) begin
E :: Ob
V :: Ob
src::Hom(E, V)
tgt::Hom(E, V)
end

@acset_type Grph(GrphDiagram, index=[:src,:tgt])
1 change: 1 addition & 0 deletions solutions:nelson-niu/helloworld.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
println("Hello World")
8 changes: 8 additions & 0 deletions solutions:nelson-niu/rabbits.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Catlab, AlgebraicDynamics, AlgebraicDynamics.UWDDynam

rabbits = ContinuousResourceSharer{Float64}(
1,
1,
(R, p, t) -> p.α*R,
[1]
)
10 changes: 10 additions & 0 deletions solutions:nelson-niu/uwd-data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Catlab.Programs.RelationalPrograms
using Catlab.Graphics.GraphvizGraphs

my_uwd = @relation (x, y, z) where (w, x, y, z) begin
R(x, w)
S(y, w)
T(z, w)
end

to_graphviz(R, box_labels=:name)