-
How to instantiate a typeclass?
Take
CoeOutas an example :/-- `CoeOut α β` is for coercions that are applied from left-to-right. -/ class CoeOut (α : Sort u) (β : semiOutParam (Sort v)) where /-- Coerces a value of type `α` to type `β`. Accessible by the notation `↑x`, or by double type ascription `((x : α) : β)`. -/ coe : α → βthere is only one field to be filled, which is
coeinstance : CoeOut MyType MyOtherType := { coe := myCoerceFunction }or
instance : CoeOut MyType MyOtherType := ⟨myCoerceFunction⟩ -
How to define and instantiate a subtype?
Take
MySubtypeas an example:def MySubtype := { x : MyType // x.property }Here,
MySubtypeis a subtype ofMyTypeconsisting of elementsxthat satisfyx.property.To instantiate a value of
MySubtype, you need to provide a value ofMyTypealong with a proof that it satisfies the property:def mySubtypeInstance : MySubtype := ⟨myValueOfMyType, myProofThatItSatisfiesProperty⟩ -
How to define a linear map?
For example :
def RSEvalLinear [Semiring F] (α : ι → F) : F[X] →ₗ[F] ι → F where toFun := RSEval α -- `simp` uses registered theorem `Eval_add` map_add' := by intro p q simp -- `simp` uses registered theorem `Eval_smul` map_smul' := by intro c p simplinear map is a homomorphism between vector spaces, preserving both vector addition and scalar multiplication. So besides defining the function itself
toFun, you also need to provide proofs that it respects addition and scalar multiplication, which aremap_add'andmap_smul'in theLinearMapstructure.
Recent Comments