2024-09-04 12:41:00 +02:00
|
|
|
|
From Coq Require Import Strings.String.
|
|
|
|
|
Require Import terms.
|
|
|
|
|
Require Import subst.
|
|
|
|
|
Require Import equiv.
|
|
|
|
|
Require Import subtype.
|
2024-09-05 12:47:30 +02:00
|
|
|
|
Require Import context.
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
(* Given a context, there is a morphism path from τ to τ' *)
|
|
|
|
|
Reserved Notation "Γ '|-' σ '~>' τ" (at level 101, σ at next level, τ at next level).
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-18 11:15:20 +02:00
|
|
|
|
Open Scope ladder_expr_scope.
|
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
Inductive morphism_path : context -> type_term -> type_term -> Prop :=
|
|
|
|
|
| M_Sub : forall Γ τ τ',
|
|
|
|
|
(τ :<= τ') ->
|
|
|
|
|
(Γ |- τ ~> τ')
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
| M_Single : forall Γ h τ τ',
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(context_contains Γ h [< τ ->morph τ' >]) ->
|
2024-09-05 12:47:30 +02:00
|
|
|
|
(Γ |- τ ~> τ')
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
| M_Chain : forall Γ τ τ' τ'',
|
|
|
|
|
(Γ |- τ ~> τ') ->
|
|
|
|
|
(Γ |- τ' ~> τ'') ->
|
|
|
|
|
(Γ |- τ ~> τ'')
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-08 15:29:47 +02:00
|
|
|
|
| M_Lift : forall Γ σ τ τ',
|
|
|
|
|
(Γ |- τ ~> τ') ->
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(Γ |- [< σ ~ τ >] ~> [< σ ~ τ' >])
|
2024-09-08 15:29:47 +02:00
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
| M_MapSeq : forall Γ τ τ',
|
|
|
|
|
(Γ |- τ ~> τ') ->
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(Γ |- [< [τ] >] ~> [< [τ'] >])
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-05 12:47:30 +02:00
|
|
|
|
where "Γ '|-' s '~>' t" := (morphism_path Γ s t).
|
2024-09-04 12:41:00 +02:00
|
|
|
|
|
2024-09-18 11:15:20 +02:00
|
|
|
|
Lemma id_morphism_path : forall Γ τ, Γ |- τ ~> τ.
|
|
|
|
|
Proof.
|
|
|
|
|
intros.
|
|
|
|
|
apply M_Sub, TSubRepr_Refl, TEq_Refl.
|
|
|
|
|
Qed.
|
2024-09-08 15:30:09 +02:00
|
|
|
|
|
|
|
|
|
Inductive translate_morphism_path : context -> type_term -> type_term -> expr_term -> Prop :=
|
2024-09-18 11:15:20 +02:00
|
|
|
|
| Translate_Descend : forall Γ τ τ',
|
2024-09-08 15:30:09 +02:00
|
|
|
|
(τ :<= τ') ->
|
|
|
|
|
(translate_morphism_path Γ τ τ'
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(expr_morph "x" τ [{ %"x"% des τ' }]))
|
2024-09-08 15:30:09 +02:00
|
|
|
|
|
|
|
|
|
| Translate_Lift : forall Γ σ τ τ' m,
|
|
|
|
|
(Γ |- τ ~> τ') ->
|
|
|
|
|
(translate_morphism_path Γ τ τ' m) ->
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(translate_morphism_path Γ [< σ ~ τ >] [< σ ~ τ' >]
|
|
|
|
|
(expr_morph "x" [< σ ~ τ >] [{ (m (%"x"% des τ)) as σ }]))
|
2024-09-08 15:30:09 +02:00
|
|
|
|
|
|
|
|
|
| Translate_Single : forall Γ h τ τ',
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(context_contains Γ h [< τ ->morph τ' >]) ->
|
|
|
|
|
(translate_morphism_path Γ τ τ' [{ %h% }])
|
2024-09-08 15:30:09 +02:00
|
|
|
|
|
|
|
|
|
| Translate_Chain : forall Γ τ τ' τ'' m1 m2,
|
|
|
|
|
(translate_morphism_path Γ τ τ' m1) ->
|
|
|
|
|
(translate_morphism_path Γ τ' τ'' m2) ->
|
|
|
|
|
(translate_morphism_path Γ τ τ''
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(expr_morph "x" τ [{ m2 (m1 %"x"%) }]))
|
2024-09-08 15:30:09 +02:00
|
|
|
|
|
|
|
|
|
| Translate_MapSeq : forall Γ τ τ' m,
|
|
|
|
|
(translate_morphism_path Γ τ τ' m) ->
|
2024-09-18 11:15:20 +02:00
|
|
|
|
(translate_morphism_path Γ [< [τ] >] [< [τ'] >]
|
|
|
|
|
[{
|
|
|
|
|
λ"xs",[τ] ↦morph (%"map"% # τ # τ' m %"xs"%)
|
|
|
|
|
}])
|
2024-09-08 15:30:09 +02:00
|
|
|
|
.
|
|
|
|
|
|
|
|
|
|
Example morphism_paths :
|
|
|
|
|
(ctx_assign "degrees-to-turns" [< $"Angle"$~$"Degrees"$~$"ℝ"$ ->morph $"Angle"$~$"Turns"$~$"ℝ"$ >]
|
|
|
|
|
(ctx_assign "turns-to-radians" [< $"Angle"$~$"Turns"$~$"ℝ"$ ->morph $"Angle"$~$"Radians"$~$"ℝ"$ >]
|
|
|
|
|
ctx_empty))
|
|
|
|
|
|
2024-09-18 11:15:20 +02:00
|
|
|
|
|- [< [ $"Hue"$~$"Angle"$~$"Degrees"$~$"ℝ"$ ] >]
|
|
|
|
|
~> [< [ $"Hue"$~$"Angle"$~$"Radians"$~$"ℝ"$ ] >]
|
2024-09-08 15:30:09 +02:00
|
|
|
|
.
|
|
|
|
|
Proof.
|
|
|
|
|
intros.
|
|
|
|
|
apply M_MapSeq.
|
|
|
|
|
apply M_Lift.
|
|
|
|
|
apply M_Chain with (τ':=[<$"Angle"$~$"Turns"$~$"ℝ"$>]).
|
|
|
|
|
apply M_Single with (h:="degrees-to-turns"%string).
|
|
|
|
|
apply C_take.
|
|
|
|
|
|
|
|
|
|
apply M_Single with (h:="turns-to-radians"%string).
|
|
|
|
|
apply C_shuffle.
|
|
|
|
|
apply C_take.
|
|
|
|
|
Qed.
|