circuits
Safe HaskellNone
LanguageGHC2024

Circuit.FinRel

Description

Finite-dimensional linear relations over GF(2).

This is a reference semantics for boolean signal-flow graphs: objects are natural numbers (encoded as FinObj), morphisms are GF(2)-linear relations presented as the row space of a matrix with (n+m) columns.

Values are Bool, addition is xor, multiplication is &&. The category carries the cartesian monoidal structure (,), is traced, and supports the copydiscardplus/zero generators that Net uses for wiring.

This module is intentionally small and self-contained: it is the minimal reference category needed to decide equality on wiring diagrams over a two- element field.

Synopsis

Objects

data FinObj (n :: Nat) Source #

Object token for a finite-dimensional space of dimension n.

Constructors

FinObj 

Instances

Instances details
KnownNat n => Discard FinRel (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

discard :: FinRel (FinObj n) () Source #

KnownNat n => Zero FinRel (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

zero :: FinRel () (FinObj n) Source #

KnownNat n => Copy FinRel (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

copy :: FinRel (FinObj n) (FinObj n, FinObj n) Source #

KnownNat n => Merge FinRel (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

plus :: FinRel (FinObj n, FinObj n) (FinObj n) Source #

KnownNat n => KnownDim (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

dimVal :: Proxy (FinObj n) -> Int Source #

Eq (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

(==) :: FinObj n -> FinObj n -> Bool #

(/=) :: FinObj n -> FinObj n -> Bool #

Ord (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

compare :: FinObj n -> FinObj n -> Ordering #

(<) :: FinObj n -> FinObj n -> Bool #

(<=) :: FinObj n -> FinObj n -> Bool #

(>) :: FinObj n -> FinObj n -> Bool #

(>=) :: FinObj n -> FinObj n -> Bool #

max :: FinObj n -> FinObj n -> FinObj n #

min :: FinObj n -> FinObj n -> FinObj n #

Show (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

showsPrec :: Int -> FinObj n -> ShowS #

show :: FinObj n -> String #

showList :: [FinObj n] -> ShowS #

class KnownDim (a :: k) where Source #

Dimension evidence for objects closed under the (,) tensor.

() has dimension 0, 'FinObj n' has dimension n, and pairs add.

Methods

dimVal :: Proxy a -> Int Source #

Instances

Instances details
KnownDim () Source # 
Instance details

Defined in Circuit.FinRel

Methods

dimVal :: Proxy () -> Int Source #

KnownNat n => KnownDim (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

dimVal :: Proxy (FinObj n) -> Int Source #

(KnownDim a, KnownDim b) => KnownDim ((a, b) :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

dimVal :: Proxy (a, b) -> Int Source #

Morphisms

data FinRel n m Source #

A GF(2)-linear relation n -> m.

Internally a matrix whose rows span the relation:

  { (take n v, drop n v) | v in row space }

The stored dimensions are trusted; the matrix is kept in reduced row echelon form for canonical equality.

Constructors

FinRel 

Fields

Instances

Instances details
Copy FinRel () Source # 
Instance details

Defined in Circuit.FinRel

Methods

copy :: FinRel () ((), ()) Source #

Merge FinRel () Source # 
Instance details

Defined in Circuit.FinRel

Methods

plus :: FinRel ((), ()) () Source #

Discard FinRel () Source # 
Instance details

Defined in Circuit.FinRel

Methods

discard :: FinRel () () Source #

Zero FinRel () Source # 
Instance details

Defined in Circuit.FinRel

Methods

zero :: FinRel () () Source #

KnownNat n => Discard FinRel (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

discard :: FinRel (FinObj n) () Source #

KnownNat n => Zero FinRel (FinObj n :: Type) Source # 
Instance details

Defined in Circuit.FinRel

Methods

zero :: FinRel () (FinObj n) Source #

KnownNat n => Copy FinRel (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

copy :: FinRel (FinObj n) (FinObj n, FinObj n) Source #

KnownNat n => Merge FinRel (FinObj n) Source # 
Instance details

Defined in Circuit.FinRel

Methods

plus :: FinRel (FinObj n, FinObj n) (FinObj n) Source #

Eq (FinRel n m) Source # 
Instance details

Defined in Circuit.FinRel

Methods

(==) :: FinRel n m -> FinRel n m -> Bool #

(/=) :: FinRel n m -> FinRel n m -> Bool #

Show (FinRel n m) Source # 
Instance details

Defined in Circuit.FinRel

Methods

showsPrec :: Int -> FinRel n m -> ShowS #

show :: FinRel n m -> String #

showList :: [FinRel n m] -> ShowS #

Smart constructors

compFinRel :: forall a b c. FinRel b c -> FinRel a b -> FinRel a c Source #

parFinRel :: FinRel a b -> FinRel c d -> FinRel (a, c) (b, d) Source #

unitlFinRel :: KnownDim a => FinRel ((), a) a Source #

unitl'FinRel :: KnownDim a => FinRel a ((), a) Source #

unitrFinRel :: KnownDim a => FinRel (a, ()) a Source #

unitr'FinRel :: KnownDim a => FinRel a (a, ()) Source #

swapFinRel :: (KnownDim a, KnownDim b) => FinRel (a, b) (b, a) Source #

assocFinRel :: (KnownDim a, KnownDim b, KnownDim c) => FinRel ((a, b), c) (a, (b, c)) Source #

assoc'FinRel :: (KnownDim a, KnownDim b, KnownDim c) => FinRel (a, (b, c)) ((a, b), c) Source #

slideFinRel :: (KnownDim a, KnownDim b, KnownDim c) => FinRel (a, (b, c)) (b, (a, c)) Source #

strengthFinRel :: KnownDim a => FinRel b c -> FinRel (a, b) (a, c) Source #

traceFinRel :: (KnownDim a, KnownDim b, KnownDim c) => FinRel (a, b) (a, c) -> FinRel b c Source #

finCopy :: forall (n :: Nat). KnownNat n => FinRel (FinObj n) (FinObj n, FinObj n) Source #

finDiscard :: forall (n :: Nat). KnownNat n => FinRel (FinObj n) () Source #

finPlus :: forall (n :: Nat). KnownNat n => FinRel (FinObj n, FinObj n) (FinObj n) Source #

finZero :: forall (n :: Nat). KnownNat n => FinRel () (FinObj n) Source #

finScalar :: forall (n :: Nat). KnownNat n => Bool -> FinRel (FinObj n) (FinObj n) Source #

wiring :: (KnownDim a, KnownDim b) => (Int -> Int) -> FinRel a b Source #

Build a wiring isomorphism from a permutation.