Algebraic networks

using Catlab.Programs

import TikzPictures
using Catlab.Graphics
R = Ob(AlgebraicNet, "\\mathbb{R}")
f_sin = Hom(:sin, R, R)
f_cos = Hom(:cos, R, R)
display(f_sin)
display(f_cos)
f = compose(mcopy(R),otimes(f_sin,f_cos),mmerge(R))
\[\Delta_{\mathbb{R},2} ; \left(\mathrm{sin} \otimes \mathrm{cos}\right) ; \nabla_{\mathbb{R},2} : \mathbb{R} \to \mathbb{R}\]
to_tikz(f, labels=true)
compile_expr(f; args=[:x])
(:(function (x,)
      v1 = sin.(x)
      v2 = cos.(x)
      v3 = v1 .+ v2
      return v3
  end), Symbol[])
to_formula(f, [:x])
\[\sin\left(x\right) + \cos\left(x\right)\]
f = compose(mcopy(R,3), otimes(f_sin, f_cos, f_sin))
\[\Delta_{\mathbb{R},3} ; \left(\mathrm{sin} \otimes \mathrm{cos} \otimes \mathrm{sin}\right) : \mathbb{R} \to \mathbb{R} \otimes \mathbb{R} \otimes \mathbb{R}\]
to_tikz(f)
compile_expr(f; args=[:x])
(:(function (x,)
      v1 = sin.(x)
      v2 = cos.(x)
      v3 = sin.(x)
      return (v1, v2, v3)
  end), Symbol[])
f = compose(linear(2,R,R), f_sin, linear(2,R,R))
\[\mathop{\mathrm{linear}}\left[2\right] ; \mathrm{sin} ; \mathop{\mathrm{linear}}\left[2\right] : \mathbb{R} \to \mathbb{R}\]
to_tikz(f)
compile_expr(f; args=[:x])
(:(function (x,)
      v1 = 2x
      v2 = sin.(v1)
      v3 = 2v2
      return v3
  end), Symbol[])
to_formula(f, [:x])
\[2 \sin\left(2 x\right)\]
f = compose(mcopy(R), otimes(id(R),Hom(:cos,R,R)), Hom(:*,otimes(R,R),R))
\[\Delta_{\mathbb{R},2} ; \left(\mathrm{id}_{\mathbb{R}} \otimes \mathrm{cos}\right) ; * : \mathbb{R} \to \mathbb{R}\]
to_tikz(f)
compile_expr(f; args=[:x])
(:(function (x,)
      v1 = cos.(x)
      v2 = (*).(x, v1)
      return v2
  end), Symbol[])
to_formula(f, [:x])
\[x \cos\left(x\right)\]