mbazs

Coq basic operators

Aug 14th, 2020 (edited)
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.83 KB | None | 0 0
  1. (* adding two natural numbers *)
  2. Fixpoint nat_add (m n: nat): nat :=
  3.   match m with
  4.   | O => n
  5.   | S m' => S (nat_add m' n)
  6.   end.
  7.  
  8. (* multiplying two natural numbers *)
  9. Fixpoint nat_mul (m n: nat): nat :=
  10.   match m with
  11.   | O => O
  12.   | S m' => nat_add n (nat_mul m' n)
  13.   end.
  14.  
  15. (* power of two natural numbers *)
  16. Fixpoint nat_exp (base power: nat): nat :=
  17.   match power with
  18.   | O => S O
  19.   | S power => nat_mul base (nat_exp base power)
  20.   end.
  21.  
  22. Theorem test_nat_add: (nat_add 5 6) = 11.
  23. Proof. reflexivity. Qed.
  24.  
  25. Theorem test_nat_mul: (nat_mul 5 6) = 30.
  26. Proof. reflexivity. Qed.
  27.  
  28. Theorem test_nat_exp: (nat_exp 2 3) = 8.
  29. Proof. reflexivity. Qed.
  30.  
  31. (* GROUP THEORY ?? *)
  32.  
  33. Theorem test_0: forall n: nat, nat_add 0 n = n.
  34. Proof. reflexivity. Qed.
  35. Theorem test_1: forall n: nat, nat_mul 0 n = 0.
  36. Proof. reflexivity. Qed.
  37.  
Add Comment
Please, Sign In to add comment