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.9540738628514973
 0.8370593662497772
 0.6190063533880474
 0.7607341302484811
 0.8370788684931866
 0.44347198286432654
 0.8685120521675052
 0.4607703376403004
 0.8340486705899713
 0.7850677918756505
 0.9698305354475946
 0.188834800762671

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.7349121001758467 
 0.8370593662497772 
 0.39984459071239686
 0.7607341302484811 
 ───────────────────
 0.7555326108705649 
 0.44347198286432654
 0.8685120521675052 
 0.37922408001767866
 ───────────────────
 1.1347566908882436 
 0.7850677918756505 
 0.9698305354475946 
 0.188834800762671  

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)
5.551115123125783e-17