Guest User

Untitled

a guest
Jul 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Inductive id : Type :=
  2. | Id : nat -> id.
  3.  
  4. Definition beq_id (x1 x2 : id) :=
  5. match x1, x2 with
  6. | Id n1, Id n2 => beq_nat n1 n2
  7. end.
  8.  
  9. Theorem beq_id_refl : forall x, true = beq_id x x.
  10. Proof.
  11. intros.
  12. destruct x.
  13. simpl.
  14. apply beq_nat_refl.
  15. Qed.
  16.  
  17. Module PartialMap.
  18. Export NatList.
  19.  
  20. Inductive partial_map : Type :=
  21. | empty : partial_map
  22. | record : id -> nat -> partial_map -> partial_map.
  23.  
  24. Fixpoint update (d : partial_map)
  25. (x : id) (value : nat)
  26. : partial_map :=
  27. match d with
  28. | empty => record x value empty
  29. | record i n xs => match beq_id x i with
  30. | true => record i value xs
  31. | false => record i n (update xs x value)
  32. end
  33. end.
  34.  
  35. Fixpoint find (x : id) (d : partial_map) : natoption :=
  36. match d with
  37. | empty => None
  38. | record y v d' => if beq_id x y
  39. then Some v
  40. else find x d'
  41. end.
  42.  
  43. Theorem update_eq :
  44. forall (d : partial_map) (x : id) (v: nat),
  45. find x (update d x v) = Some v.
  46. Proof.
  47. intros.
  48. simpl.
  49. induction d.
  50. - simpl.
  51. rewrite <- beq_id_refl.
  52. reflexivity.
  53. - simpl.
  54. case (beq_id x i).
  55. + simpl.
  56. (* if beq_id x i then Some v else find x d *)
  57. Qed.
Add Comment
Please, Sign In to add comment