Advertisement
Guest User

Basic.v

a guest
Mar 9th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Inductive binnat: Type :=
  2. | BO: binnat
  3. | BDbl: binnat -> binnat
  4. | BSDbl: binnat -> binnat.
  5.  
  6. Fixpoint binc (n: binnat) : binnat :=
  7. match n with
  8. | BO => BSDbl BO
  9. | BDbl m => BSDbl m
  10. | BSDbl m => BDbl (binc m)
  11. end.
  12.  
  13. Fixpoint bin_to_nat (n: binnat) : nat :=
  14. match n with
  15. | BO => O
  16. | BDbl m => 2 * (bin_to_nat m)
  17. | BSDbl m => (2 * (bin_to_nat m)) + 1
  18. end.
  19.  
  20. Require Import Coq.Arith.Plus.
  21.  
  22. Theorem bin_sound:
  23. ∀ (b: binnat), bin_to_nat (binc b) = (bin_to_nat b) + 1 .
  24. Proof.
  25. intros b.
  26. induction b.
  27. simpl.
  28. reflexivity.
  29. simpl.
  30. reflexivity.
  31. simpl.
  32. replace (bin_to_nat (binc b)) with ((bin_to_nat b) + 1) .
  33. generalize (bin_to_nat b) as n.
  34. intros n.
  35. replace (n + 1 + 0) with (n + 1).
  36. replace (n + 0) with n.
  37. replace (n + 1 + (n + 1)) with (n + n + (1 + 1)).
  38. apply plus_assoc.
  39. apply plus_permute_2_in_4.
  40. replace (n + 0) with (0 + n).
  41. apply plus_0_l .
  42. apply plus_comm.
  43. generalize (n + 1) as m .
  44. intros m.
  45. replace (m + 0) with (0 + m).
  46. apply plus_0_l.
  47. apply plus_comm.
  48. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement