Code Example

This is an example of adding a code example compiled with Literate.jl in the docs.

First we want to load our package with using

using CellularSheaves
using LinearAlgebra

Using the Package

Here is a simple example of creating a sheaf using the @cellular_sheaf macro.

A = [1.0 0.0 1.0 0.0]
B = [1.0 0.0 0.0 1.0]
C = [1.0 0.0 0.0 0.0]

sheaf = @cellular_sheaf A, B, C begin
    x::Stalk{4}, y::Stalk{4}, z::Stalk{4}

    A(x) == B(y)
    A(x) == C(z)
    B(y) == C(z)

end
A network sheaf with 3 vertex stalks and 3 edge stalks.

Let's compute a global section of this sheaf. We start with a random 0-cochain:

x0 = rand(sum(vertex_stalks(sheaf)))
12-element Vector{Float64}:
 0.8303343310857842
 0.5731317625378068
 0.1766250878128448
 0.1149352976286987
 0.786400165183776
 0.8925975682484205
 0.45201517659689416
 0.2068733032049488
 0.28658165197963514
 0.9189161789750877
 0.9910709743724717
 0.7968313251885976

We use the deterministic direct LDLt backend to guarantee a result.

global_section = nearest_global_section(sheaf, x0; method=:ldl)
3-blocked 12-element BlockVector{Float64}:
  0.6485291455422977  
  0.5731317625378068  
 -0.005180097730641764
  0.1149352976286987  
 ─────────────────────
  0.6114379548952416  
  0.8925975682484205  
  0.45201517659689416 
  0.03191109291641436 
 ─────────────────────
  0.6433490478116561  
  0.9189161789750877  
  0.9910709743724717  
  0.7968313251885976  

Now we can check that this is indeed a global section by verifying that the coboundary map applied to it is zero.

d = coboundary_map(sheaf)

norm(d * global_section)
3.1401849173675503e-16