# Shapes of homological complexes #

We define a structure `ComplexShape ι`

for describing the shapes of homological complexes
indexed by a type `ι`

.
This is intended to capture chain complexes and cochain complexes, indexed by either `ℕ`

or `ℤ`

,
as well as more exotic examples.

Rather than insisting that the indexing type has a `succ`

function
specifying where differentials should go,
inside `c : ComplexShape`

we have `c.Rel : ι → ι → Prop→ ι → Prop→ Prop`

,
and when we define `HomologicalComplex`

we only allow nonzero differentials `d i j`

from `i`

to `j`

if `c.Rel i j`

.
Further, we require that `{ j // c.Rel i j }`

and `{ i // c.Rel i j }`

are subsingletons.
This means that the shape consists of some union of lines, rays, intervals, and circles.

Convenience functions `c.next`

and `c.prev`

provide these related elements
when they exist, and return their input otherwise.

This design aims to avoid certain problems arising from dependent type theory.
In particular we never have to ensure morphisms `d i : X i ⟶ X (succ i)⟶ X (succ i)`

compose as
expected (which would often require rewriting by equations in the indexing type).
Instead such identities become separate proof obligations when verifying that a
complex we've constructed is of the desired shape.

If `α`

is an `AddRightCancelSemigroup`

, then we define `up α : ComplexShape α`

,
the shape appropriate for cohomology, so `d : X i ⟶ X j⟶ X j`

is nonzero only when `j = i + 1`

,
as well as `down α : ComplexShape α`

, appropriate for homology,
so `d : X i ⟶ X j⟶ X j`

is nonzero only when `i = j + 1`

.
(Later we'll introduce `CochainComplex`

and `ChainComplex`

as abbreviations for
`HomologicalComplex`

with one of these shapes baked in.)

Nonzero differentials

`X i ⟶ X j⟶ X j`

shall be allowed on homological complexes when`Rel i j`

holds.Rel : ι → ι → PropThere is at most one nonzero differential from

`X i`

.next_eq : ∀ {i j j' : ι}, Rel i j → Rel i j' → j = j'There is at most one nonzero differential to

`X j`

.prev_eq : ∀ {i i' j : ι}, Rel i j → Rel i' j → i = i'

A `c : ComplexShape ι`

describes the shape of a chain complex,
with chain groups indexed by `ι`

.
Typically `ι`

will be `ℕ`

, `ℤ`

, or `Fin n`

.

There is a relation `Rel : ι → ι → Prop→ ι → Prop→ Prop`

,
and we will only allow a non-zero differential from `i`

to `j`

when `Rel i j`

.

There are axioms which imply `{ j // c.Rel i j }`

and `{ i // c.Rel i j }`

are subsingletons.
This means that the shape consists of some union of lines, rays, intervals, and circles.

Below we define `c.next`

and `c.prev`

which provide these related elements.

## Instances For

The complex shape where only differentials from each `X.i`

to itself are allowed.

This is mostly only useful so we can describe the relation of "related in `k`

steps" below.

The reverse of a `ComplexShape`

.

## Equations

- One or more equations did not get rendered due to their size.

The "composition" of two `ComplexShape`

s.

We need this to define "related in k steps" later.

## Equations

- One or more equations did not get rendered due to their size.

An arbitary choice of index `j`

such that `Rel i j`

, if such exists.
Returns `i`

otherwise.

## Equations

- ComplexShape.next c i = if h : ∃ j, ComplexShape.Rel c i j then Exists.choose h else i

An arbitary choice of index `i`

such that `Rel i j`

, if such exists.
Returns `j`

otherwise.

## Equations

- ComplexShape.prev c j = if h : ∃ i, ComplexShape.Rel c i j then Exists.choose h else j

The `ComplexShape`

allowing differentials from `X i`

to `X (i+a)`

.
(For example when `a = 1`

, a cohomology theory indexed by `ℕ`

or `ℤ`

)

The `ComplexShape`

allowing differentials from `X (j+a)`

to `X j`

.
(For example when `a = 1`

, a homology theory indexed by `ℕ`

or `ℤ`

)

The `ComplexShape`

appropriate for cohomology, so `d : X i ⟶ X j⟶ X j`

only when `j = i + 1`

.

## Equations

The `ComplexShape`

appropriate for homology, so `d : X i ⟶ X j⟶ X j`

only when `i = j + 1`

.