Cellular Sheaf DSL

The DSL provides a macro and associated types for constructing cellular sheaves in a declarative manner. Below are the primary symbols exported by the parser module.

using CellularSheaves using CellularSheaves.NetworkSheaves

CellularSheaves.NetworkSheaves.CellularSheafParser.@cellular_sheafMacro

cellular_sheaf(expr...)

This macro abstracts functions such as:

  1. julia EuclideanSheaf(vertex_stalks::Vector{Int})
  2. julia add_sheaf_edge!(s::AbstractCellularSheaf, v1::Int, v2::Int, rm1::AbstractMatrix, rm2::AbstractMatrix)

It accepts restriction map matrices as argument parameters and allows a user to declare vertex stalks and linear relations representing edges in the cellular sheaf. For instance, a user can represent a triangular sheaf using the following julia code:


# Define restriction maps as matrices
A = [1 0 0 0]
B = [1 0 0 0]
C = [1 0 0 0]

# You can pass in the maps as follows: 

triangle = @cellular_sheaf A, B, C begin
    # You can define vertex stalks using the format: name::Stalk{dimension}
    x::Stalk{4}, y::Stalk{4}, z::Stalk{4}

    # Then, you can define your relations as equations:

    # For instance, in "A(x) == B(y)", x and y are incident vertices. A maps x to the shared edge stalk. B maps y to the shared edge stalk.
    A(x) == B(y)
    A(x) == C(z)
    B(y) == C(z)

end

The previous code is the same as writing:


c = EuclideanSheaf([4, 4, 4])
add_sheaf_edge!(c, 1, 2, A, B)
add_sheaf_edge!(c, 1, 3, A, C)
add_sheaf_edge!(c, 2, 3, B, C)

While the first example may appear like more lines of code, it is far easier to understand the pattern that is occurring, making it easier for developers to quickly construct cellular sheaves. Likewise, because edge stalk dimensions are inferred, this provides a more disciplined approach to building sheaves, leaving less room for errors.

For future reference, the DSL makes use of the following formal grammar:

– Top Level – SheafExpr ::= Line* Line ::= Statement EOL Statement ::= Declaration+ | Equation+

– Declarations – Declaration ::= TypedDeclaration | UntypedDeclaration TypedDeclaration ::= Identifier "::" TypeName UntypedDeclaration ::= Identifier TypeName ::= "Stalk" "{" Digit "}" Digit ::= "[0-9]+"

– Equation System – Equation ::= Product "==" Product Product ::= (RestrictionMap "(" VertexStalk ")") | RestrictionMap "*" VertexStalk RestrictionMap ::= Identifier VertexStalk ::= Identifier

source