playground/coq/unfinished/embeddings.v

150 lines
2.2 KiB
Coq

Check mult.
Inductive exp : Set :=
| Const : nat -> exp
| Plus : exp -> exp -> exp
| Mult : exp -> exp -> exp.
Fixpoint expDenote (e : exp) : nat :=
match e with
| Const n => n
| Plus e1 e2 => plus (expDenote e1) (expDenote e2)
| Mult e1 e2 => mult (expDenote e1) (expDenote e2)
end.
(*
(* Deep 2 *)
Inductive exp : Set :=
| Const : nat -> exp
| Plus : exp -> exp -> exp.
Fixpoint expDenote (e : exp) : nat :=
match e with
| Const n => n
| Plus e1 e2 => plus (expDenote e1) (expDenote e2)
end.
Compute (expDenote (Plus (Const 3) (Const 2))).
(*
#+BEGIN_OUTPUT (Info)
= 5
: nat
#+END_OUTPUT (Info) *)
Compute (expDenote (Plus (Plus (Const 1) (Const 3)) (Const 2))).
(*
#+BEGIN_OUTPUT (Info)
= 6
: nat
#+END_OUTPUT (Info) *)
Reset expDenote.
Reset Plus.
Reset Const.
*)
(*
(* Deep 1 *)
Inductive oprtr : Set :=
| Plus.
Definition opDenote (op : oprtr) : nat -> nat -> nat :=
match op with
| Plus => plus
end.
Compute (opDenote Plus) 3 2.
Inductive exp : Set :=
| Const : nat -> exp
| Oprtr : oprtr -> nat -> nat -> exp.
Definition expDenote (e : exp) : nat :=
match e with
| Const n => n
| Oprtr op n1 n2 => (opDenote op) n1 n2
end.
Compute (Plus (Const 3) (Const 2)).
*)
(*
(* Shallow *)
Definition Plus := plus.
Definition Const (n : nat) := n.
Compute (Plus (Const 3) (Const 2)).
Compute (Plus (Plus (Const 1) (Const 3)) (Const 2)).
*)
(*
(* Shallow: new construct *)
Definition Const (n : nat) := n.
Definition Plus := plus.
Definition Mult := mult.
Compute (Mult (Const 3) (Const 2)).
Compute (Plus (Const 2) (Mult (Const 5) (Const 3))).
*)
Inductive shape : Type :=
| Circule : nat -> region.
with
Inductive region : Type :=
| Circle : nat -> region
| Outside : region -> region
| Intersect : region -> region -> region
| Union : region -> region -> region.
Fixpoint regionDenote (r : region) :=
match
(* Deep *)
Inductive exp : Type :=
| Const : nat -> exp
| Plus : nat -> nat -> exp.
Fixpoint expDenote (e : exp) : nat :=
match e with
| Const n => n
| Plus e1 e2 => e1 + e2
end.
Compute (expDenote (Plus (Const 2) (Const 3))).
(* Shallow *)
Definition Const' (n : nat) : nat := n.
Definition Plus' (e1 e2 : nat) : nat := e1 + e2.
Compute Plus' (Const' 2) (Const' 3).