You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is what I came up with with a very basic Semigroup & Monoid example rather than
the bigger one involving Ring:
||| Inclusion of one signature into another.-- Do we already have this somewhere?public export
OpMorph: (p, q : Signature) ->TypeOpMorph p q = {n:Nat} -> p .OpWithArity n -> q .OpWithArity n
Semigroup is what you'd expect. Notice that I have lifted axiom to the
toplevel instead of having MkPresentation _ _ $ \case (...) and that it
takes an OpMorph as an argument: if you can make sense of a semigroup's
operations in a larger context then you can make sense of its axioms too.
||| The syntax and axioms for semigroupsmodule Frexlet.Semigroup.Theory
import Frex
public export
dataOperation:Nat->TypewhereProduct: Operation 2
public export
Signature: Signature
Signature=MkSignatureOperationpublic export
dataAxiom=Associativitypublic export
axiom: {sig : _} -> OpMorph Signature sig -> Axiom -> Equation sig
axiom interp Associativity= associativity (interp Product)
public export
SemigroupTheory: Presentation
SemigroupTheory=MkPresentationTheory.SignatureTheory.Axiom (axiom id)
And this is the refactored Monoid.Theory. Notice how theSemigroup is
used to focus on Product only out of all the operations.
||| The syntax and axioms for monoidsmodule Frexlet.Monoid.Theory
import Frexlet.Semigroup.Theory as Semigroupimport Frex
public export
dataOperation:Nat->TypewhereNeutral: Operation 0
Product: Operation 2
public export
Signature: Signature
Signature=MkSignatureMonoid.Theory.Operationpublic export
dataAxiom=LftNeutrality|RgtNeutrality|SemigroupSemigroup.AxiomtheSemigroup: OpMorph Semigroup.Signature Monoid.Theory.Signature
theSemigroup Semigroup.Product=Monoid.Theory.Productpublic export
axiom: {sig : _} -> OpMorph Monoid.Theory.Signature sig ->
Monoid.Theory.Axiom -> Equation sig
axiom interp LftNeutrality= lftNeutrality (interp Neutral) (interp Product)
axiom interp RgtNeutrality= rgtNeutrality (interp Neutral) (interp Product)
axiom interp (Semigroup ax) =Semigroup.axiom (interp . theSemigroup) ax
public export
MonoidTheory: Presentation
MonoidTheory=MkPresentationMonoid.Theory.SignatureMonoid.Theory.Axiom (axiom id)
This example is a bit degenerate, but roughly. I would also try to re-use the operation Product rather than duplicate it like we do in the code snippet.
Semigroup is a little different than semiring because we're adding to the single binary operation.
In a semiring, I would try to have two copies of a semigroup (additive and multiplicative), both for the operations and the axioms, and then only add the interaction laws between them.
You're right that there might be other ways to organise the data, both in terms of operations and in terms of axioms, and that using one way might bias the structure against another one, while a flat representation for the operations and types is going to be unbiased. But I worry that this unbiased approach would make all developments equally miserable, rather than making some things easy, and some things hard.
Riffing off #12 (comment)
This is what I came up with with a very basic
Semigroup
&Monoid
example rather thanthe bigger one involving
Ring
:Semigroup is what you'd expect. Notice that I have lifted
axiom
to thetoplevel instead of having
MkPresentation _ _ $ \case (...)
and that ittakes an
OpMorph
as an argument: if you can make sense of a semigroup'soperations in a larger context then you can make sense of its axioms too.
And this is the refactored
Monoid.Theory
. Notice howtheSemigroup
isused to focus on
Product
only out of all the operations.Is this the kind of stuff you had in mind @ohad?
The text was updated successfully, but these errors were encountered: