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.4549162368293085
 0.18555488079076976
 0.8732218430935036
 0.443186080789584
 0.4485617940234884
 0.0867203230810758
 0.2665887697877637
 0.4984134024697735
 0.26151335814150023
 0.9945090773793526
 0.039246956710461856
 0.18350203599335912

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.14061469595528675 
 0.18555488079076976 
 0.5589203022194819  
 0.443186080789584   
 ────────────────────
 0.32484169486424175 
 0.0867203230810758  
 0.2665887697877637  
 0.37469330331052686 
 ────────────────────
 0.6995349981747686  
 0.9945090773793526  
 0.039246956710461856
 0.18350203599335912 

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)
0.0