feat: 3234 week 4

This commit is contained in:
2024-02-20 11:31:16 +08:00
parent 3287079e24
commit d9315b13c4
6 changed files with 2022 additions and 5 deletions

View File

@@ -33,7 +33,13 @@ Theorem O_is_left_neutral_for_recursive_addition :
recursive_specification_of_addition add ->
forall n : nat,
add 0 n = n.
Admitted.
Proof.
intros add.
unfold recursive_specification_of_addition.
intros [S_add_O S_add_S].
exact (S_add_O).
Qed.
(* ********** *)
@@ -79,6 +85,7 @@ Proof.
Admitted.
Property O_is_left_absorbing_wrt_multiplication_alt :
forall mul : nat -> nat -> nat,
recursive_specification_of_multiplication mul ->
@@ -190,6 +197,19 @@ Theorem addition_is_commutative :
forall n1 n2 : nat,
add n1 n2 = add n2 n1.
Proof.
intros add S_add.
assert (S_tmp := S_add).
unfold recursive_specification_of_addition in S_tmp.
destruct S_tmp as [S_add_O S_add_S].
intro x.
induction x as [| x' IHx'].
- intro y.
rewrite -> (S_add_O y).
rewrite -> (O_is_right_neutral_wrt_addition add S_add y).
reflexivity.
- intro y.
rewrite -> (S_add_S x' y).
rewrite -> (IHx' y).
Admitted.
Property SO_is_right_neutral_wrt_multiplication :
@@ -322,12 +342,60 @@ Proof.
Check (multiplication_is_right_distributive_over_addition add S_add mul S_mul).
rewrite -> (multiplication_is_right_distributive_over_addition add S_add mul S_mul (mul x' y) y z).
reflexivity.
Show Proof.
Qed.
(* ********** *)
(* Exercise 05 *)
Check Nat.mul_0_r.
Theorem addition_is_associative :
forall add : nat -> nat -> nat,
recursive_specification_of_addition add ->
forall x y z : nat,
add (add x y) z = add x (add y z).
Proof.
Admitted.
Lemma commutativity_of_recursive_multiplication_S :
forall add : nat -> nat -> nat,
recursive_specification_of_addition add ->
forall mul : nat -> nat -> nat,
recursive_specification_of_multiplication mul ->
forall x y : nat,
mul x (S y) = add (mul x y) x.
Proof.
intros add S_add mul S_mul.
assert (S_tmp := S_mul).
unfold recursive_specification_of_multiplication in S_tmp.
destruct (S_tmp add S_add) as [S_mul_O S_mul_S].
clear S_tmp.
assert (S_tmp := S_add).
unfold recursive_specification_of_addition in S_tmp.
destruct S_tmp as [S_add_O S_add_S].
intro x.
induction x as [| x' IHx'].
- intro y.
rewrite -> (S_mul_O (S y)).
rewrite -> (S_mul_O y).
rewrite -> (S_add_O 0).
reflexivity.
- intro y.
rewrite -> (addition_is_commutative add S_add (mul (S x') y) (S x')).
rewrite -> (S_add_S x' (mul (S x') y)).
rewrite -> (S_mul_S x' y).
rewrite -> (S_mul_S x' (S y)).
rewrite -> (IHx' y).
rewrite -> (addition_is_commutative add S_add (add (mul x' y) x') (S y)).
rewrite -> (S_add_S y (add (mul x' y) x')).
rewrite -> (addition_is_commutative add S_add (add (mul x' y) x') (S y)).
rewrite -> (addition_is_associative )
Property multiplication_is_commutative :
forall add : nat -> nat -> nat,
recursive_specification_of_addition add ->
@@ -344,7 +412,6 @@ Proof.
assert (S_tmp := S_add).
unfold recursive_specification_of_addition in S_tmp.
destruct S_tmp as [S_add_O S_add_S].
intro x.
induction x as [| x' IHx'].
- intro y.
@@ -352,12 +419,49 @@ Proof.
rewrite -> (O_is_right_absorbing_wrt_multiplication add S_add mul S_mul y).
reflexivity.
- intro y.
(* rewrite -> (S_mul_S x' y). *)
(* rewrite -> (addition_is_commutative add S_add (mul x' y) y). *)
(* rewrite -> (IHx' y). *)
(* rewrite <- (SO_is_right_neutral_wrt_multiplication add S_add mul S_mul x') at 1. *)
(* rewrite -> (multiplication_is_associative add S_add mul S_mul y x' 1). *)
(* rewrite <- (IHx' y). *)
(* rewrite <- (multiplication_is_associative add S_add mul S_mul x' y 1). *)
(* rewrite -> (SO_is_right_neutral_wrt_multiplication add S_add mul S_mul y). *)
rewrite -> (S_mul_S x' y).
rewrite -> (IHx' y).
Check (multiplication_is_right_distributive_over_addition add S_add mul S_mul).
Check (add (mul x' y) y).
(* TODO FINISH THIS *)
Admitted. (* <-- needed for later on *)
Lemma S_mul_S_reversed :
forall add : nat -> nat -> nat,
recursive_specification_of_addition add ->
forall mul : nat -> nat -> nat,
recursive_specification_of_multiplication mul ->
forall x y : nat,
mul y (S x) = add (mul x y) y.
Proof.
intros add S_add mul S_mul.
assert (S_tmp := S_mul).
unfold recursive_specification_of_multiplication in S_tmp.
destruct (S_tmp add S_add) as [S_mul_O S_mul_S].
clear S_tmp.
assert (S_tmp := S_add).
unfold recursive_specification_of_addition in S_tmp.
destruct S_tmp as [S_add_O S_add_S].
intro x.
induction x as [| x' IHx'].
- intro y.
rewrite -> (S_mul_O y).
rewrite -> (SO_is_right_neutral_wrt_multiplication add S_add mul S_mul y).
rewrite -> (S_add_O y).
reflexivity.
- intro y.
Abort.
Qed. (* <-- needed for later on *)
(* ********** *)