2023-01-07 05:27:20 -05:00
|
|
|
Require Import thue_morse.
|
|
|
|
|
|
|
|
Require Import Coq.Lists.List.
|
|
|
|
Require Import PeanoNat.
|
|
|
|
Require Import Nat.
|
|
|
|
Require Import Bool.
|
|
|
|
|
|
|
|
Import ListNotations.
|
|
|
|
|
|
|
|
|
2023-01-11 03:19:23 -05:00
|
|
|
(**
|
|
|
|
The following lemma, while not of truly general use, is
|
|
|
|
used in several proofs and has therefore its own dedicated
|
|
|
|
section here.
|
|
|
|
*)
|
|
|
|
|
2023-01-10 12:04:42 -05:00
|
|
|
Lemma tm_step_consecutive_identical :
|
|
|
|
forall (n : nat) (hd a tl : list bool) (b1 b2 : bool),
|
|
|
|
tm_step n = hd ++ (b1::b1::nil) ++ a ++ (b2::b2::nil) ++ tl
|
|
|
|
-> even (length a) = true.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl b1 b2. intros H.
|
|
|
|
assert (I: even (length hd) = false).
|
|
|
|
assert (J: {even (length hd) = false} + { ~ (even (length hd)) = false}).
|
|
|
|
apply bool_dec. destruct J. assumption. apply not_false_is_true in n0.
|
2023-01-10 13:09:56 -05:00
|
|
|
assert (K: count_occ Bool.bool_dec hd true
|
|
|
|
= count_occ Bool.bool_dec hd false).
|
|
|
|
generalize n0. generalize H. apply tm_step_count_occ.
|
2023-01-10 12:04:42 -05:00
|
|
|
rewrite app_assoc in H.
|
2023-01-10 13:09:56 -05:00
|
|
|
assert (L: count_occ Bool.bool_dec (hd ++ [b1;b1]) true
|
2023-01-10 12:04:42 -05:00
|
|
|
= count_occ Bool.bool_dec (hd ++ [b1;b1]) false).
|
|
|
|
assert (even (length (hd ++ [b1;b1])) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add_even. assumption.
|
|
|
|
simpl. apply Nat.EvenT_Even. apply Nat.even_EvenT. reflexivity.
|
|
|
|
generalize H0. generalize H. apply tm_step_count_occ.
|
2023-01-10 13:09:56 -05:00
|
|
|
rewrite count_occ_app in L. rewrite count_occ_app in L.
|
|
|
|
rewrite K in L. rewrite Nat.add_cancel_l in L.
|
|
|
|
destruct b1. simpl in L. inversion L. simpl in L. inversion L.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-10 13:09:56 -05:00
|
|
|
assert (J: {even (length (hd ++ [b1;b1] ++ a))
|
|
|
|
= false} + { ~ (even (length (hd ++ [b1;b1] ++ a))) = false}).
|
|
|
|
apply bool_dec. destruct J.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-10 13:09:56 -05:00
|
|
|
rewrite app_length in e. rewrite app_length in e.
|
|
|
|
rewrite Nat.add_assoc in e. rewrite Nat.add_shuffle0 in e.
|
|
|
|
rewrite Nat.even_add_even in e. rewrite Nat.even_add in e.
|
|
|
|
rewrite I in e. destruct (Nat.even (length a)). reflexivity.
|
|
|
|
simpl in e. inversion e. simpl.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. reflexivity.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-10 13:09:56 -05:00
|
|
|
apply not_false_is_true in n0.
|
|
|
|
assert (K: even (length (hd ++ [b1;b1] ++ a ++ [b2;b2])) = true).
|
|
|
|
replace (hd ++ [b1;b1] ++ a ++ [b2;b2])
|
|
|
|
with ((hd ++ [b1;b1] ++ a) ++ [b2;b2]).
|
|
|
|
rewrite app_length. rewrite Nat.even_add.
|
|
|
|
rewrite n0. reflexivity.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-10 13:09:56 -05:00
|
|
|
assert (N: count_occ Bool.bool_dec (hd ++ [b1;b1] ++ a ++ [b2;b2]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [b1;b1] ++ a ++ [b2;b2]) false).
|
|
|
|
replace (hd ++ [b1;b1] ++ a ++ [b2;b2] ++ tl)
|
|
|
|
with ((hd ++ [b1;b1] ++ a ++ [b2;b2]) ++ tl) in H.
|
|
|
|
generalize K. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-10 13:09:56 -05:00
|
|
|
assert (M: count_occ Bool.bool_dec (hd ++ [b1;b1] ++ a) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [b1;b1] ++ a) false).
|
|
|
|
replace (hd ++ [b1;b1] ++ a ++ [b2;b2] ++ tl)
|
|
|
|
with ((hd ++ [b1;b1] ++ a) ++ [b2;b2] ++ tl) in H.
|
|
|
|
generalize n0. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
|
|
|
|
replace (hd ++ [b1;b1] ++ a ++ [b2;b2])
|
|
|
|
with ((hd ++ [b1;b1] ++ a) ++ [b2;b2]) in N.
|
|
|
|
rewrite count_occ_app in N. symmetry in N.
|
|
|
|
rewrite count_occ_app in N. rewrite M in N.
|
|
|
|
rewrite Nat.add_cancel_l in N.
|
|
|
|
destruct b2. simpl in N. inversion N. simpl in N. inversion N.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
Qed.
|
|
|
|
|
|
|
|
|
2023-01-11 03:19:23 -05:00
|
|
|
(**
|
|
|
|
The following lemmas and theorems are all related to
|
|
|
|
squares of odd length in the Thue-Morse sequence.
|
2023-01-11 05:34:08 -05:00
|
|
|
All squared factors of odd length have length 1 or 3.
|
2023-01-11 03:19:23 -05:00
|
|
|
*)
|
|
|
|
|
2023-01-10 18:16:29 -05:00
|
|
|
Lemma tm_step_factor5 : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ tl -> length a = 5
|
|
|
|
-> a <> [ true; false; true; false; true].
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
|
|
|
|
destruct n.
|
|
|
|
assert (length (tm_step 0) = length (tm_step 0)). reflexivity.
|
|
|
|
rewrite H in H0 at 2. simpl in H0.
|
|
|
|
rewrite app_length in H0. rewrite app_length in H0.
|
|
|
|
rewrite I in H0. rewrite Nat.add_shuffle3 in H0.
|
|
|
|
apply Nat.succ_inj in H0. inversion H0.
|
|
|
|
|
|
|
|
assert (even (length (tm_step (S n))) = true).
|
|
|
|
rewrite tm_size_power2. rewrite Nat.pow_succ_r. apply Nat.even_mul.
|
|
|
|
apply Nat.le_0_l.
|
|
|
|
|
|
|
|
assert (J: even (length hd) = negb (even (length tl))).
|
|
|
|
rewrite H in H0. rewrite app_length in H0. rewrite app_length in H0.
|
|
|
|
rewrite I in H0. rewrite Nat.even_add in H0. rewrite Nat.even_add in H0.
|
|
|
|
destruct (even (length hd)); destruct (even (length tl)).
|
|
|
|
inversion H0. reflexivity. reflexivity. inversion H0.
|
|
|
|
|
|
|
|
assert (K: {a=[true; false; true; false; true]}
|
|
|
|
+ {~ a=[ true; false; true; false; true]}).
|
|
|
|
apply list_eq_dec. apply bool_dec. destruct K.
|
|
|
|
|
|
|
|
assert ({even (length hd) = true} + {even (length hd) <> true}).
|
|
|
|
apply bool_dec. destruct H1.
|
|
|
|
|
|
|
|
(* case length hd is even *)
|
|
|
|
rewrite e0 in J. rewrite Nat.negb_even in J.
|
|
|
|
destruct tl. inversion J.
|
|
|
|
destruct b.
|
|
|
|
|
|
|
|
assert (count_occ Bool.bool_dec hd true = count_occ Bool.bool_dec hd false).
|
|
|
|
generalize e0. generalize H. apply tm_step_count_occ.
|
|
|
|
|
|
|
|
assert (count_occ Bool.bool_dec (hd ++ a ++ [true]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ a ++ [true]) false).
|
|
|
|
assert (even (length (hd ++ a ++ [true])) = true).
|
|
|
|
rewrite app_length. rewrite app_length.
|
|
|
|
rewrite Nat.even_add. rewrite Nat.even_add.
|
|
|
|
rewrite e0. rewrite e. reflexivity.
|
|
|
|
replace (hd ++ a ++ true :: tl) with ((hd ++ a ++ [true]) ++ tl) in H.
|
|
|
|
generalize H2. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
|
|
|
|
rewrite count_occ_app in H2. rewrite H1 in H2.
|
|
|
|
symmetry in H2.
|
|
|
|
rewrite count_occ_app in H2. rewrite Nat.add_cancel_l in H2.
|
|
|
|
|
|
|
|
rewrite count_occ_app in H2. rewrite count_occ_app in H2.
|
|
|
|
rewrite e in H2. simpl in H2. inversion H2.
|
|
|
|
|
|
|
|
replace (hd ++ a ++ false::tl)
|
|
|
|
with (hd ++ [true; false] ++ [true; false] ++ [true; false] ++ tl) in H.
|
|
|
|
apply tm_step_cubefree in H. contradiction H. reflexivity.
|
|
|
|
simpl. apply Nat.lt_0_2.
|
|
|
|
|
|
|
|
rewrite e. reflexivity.
|
|
|
|
|
|
|
|
(* case length hd is odd *)
|
|
|
|
apply not_true_is_false in n0.
|
|
|
|
rewrite app_removelast_last with (l := hd) (d := true) in H.
|
|
|
|
rewrite app_removelast_last with (l := hd) (d := true) in n0.
|
|
|
|
rewrite app_length in n0. simpl in n0.
|
|
|
|
rewrite Nat.add_1_r in n0. rewrite Nat.even_succ in n0.
|
|
|
|
rewrite <- Nat.negb_even in n0. rewrite negb_false_iff in n0.
|
|
|
|
|
|
|
|
destruct (last hd true).
|
|
|
|
rewrite <- app_assoc in H.
|
|
|
|
assert (count_occ Bool.bool_dec (removelast hd) true
|
|
|
|
= count_occ Bool.bool_dec (removelast hd) false).
|
|
|
|
generalize n0. generalize H. apply tm_step_count_occ.
|
|
|
|
replace (removelast hd ++ [true] ++ a ++ tl)
|
|
|
|
with ((removelast hd ++ [true; true]) ++ [false;true;false;true] ++ tl) in H.
|
|
|
|
assert (count_occ Bool.bool_dec (removelast hd ++ [true;true]) true
|
|
|
|
= count_occ Bool.bool_dec (removelast hd ++ [true;true]) false).
|
|
|
|
assert (even (length (removelast hd ++ [true;true])) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add_even. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. reflexivity.
|
|
|
|
generalize H2. generalize H. apply tm_step_count_occ.
|
|
|
|
|
|
|
|
rewrite count_occ_app in H2. rewrite count_occ_app in H2.
|
|
|
|
rewrite H1 in H2. rewrite Nat.add_cancel_l in H2.
|
|
|
|
simpl in H2. inversion H2.
|
|
|
|
|
|
|
|
rewrite e. rewrite app_assoc_reverse. reflexivity.
|
|
|
|
|
|
|
|
replace ((removelast hd ++ [false]) ++ a ++ tl)
|
|
|
|
with (removelast hd ++ [false; true] ++ [false; true] ++ [false;true] ++ tl) in H.
|
|
|
|
apply tm_step_cubefree in H. contradiction H. reflexivity.
|
|
|
|
simpl. apply Nat.lt_0_2.
|
|
|
|
|
|
|
|
rewrite e. rewrite app_assoc_reverse. reflexivity.
|
|
|
|
|
|
|
|
assert (length hd <> 0). destruct hd. inversion n0.
|
|
|
|
simpl. apply Nat.neq_succ_0. rewrite <- length_zero_iff_nil. assumption.
|
|
|
|
assert (length hd <> 0). destruct hd. inversion n0.
|
|
|
|
simpl. apply Nat.neq_succ_0. rewrite <- length_zero_iff_nil. assumption.
|
|
|
|
|
|
|
|
assumption.
|
|
|
|
Qed.
|
|
|
|
|
|
|
|
Lemma tm_step_factor5' : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ tl -> length a = 5
|
|
|
|
-> a <> [ false; true; false; true; false].
|
|
|
|
Proof.
|
2023-01-10 18:25:33 -05:00
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (K: {a=[false; true; false; true; false]}
|
|
|
|
+ {~ a=[false; true; false; true; false]}).
|
|
|
|
apply list_eq_dec. apply bool_dec. destruct K.
|
|
|
|
assert (tm_step (S n) = hd ++ a ++ tl
|
|
|
|
++ (map negb hd) ++ [ true; false; true; false; true ]
|
|
|
|
++ (map negb tl)).
|
|
|
|
rewrite tm_build. rewrite H.
|
|
|
|
rewrite map_app. rewrite map_app.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. rewrite e. reflexivity.
|
|
|
|
rewrite app_assoc in H0. rewrite app_assoc in H0.
|
|
|
|
rewrite app_assoc in H0. apply tm_step_factor5 in H0.
|
|
|
|
contradiction H0. reflexivity.
|
|
|
|
reflexivity. assumption.
|
|
|
|
Qed.
|
2023-01-10 18:16:29 -05:00
|
|
|
|
|
|
|
|
2023-01-11 02:38:38 -05:00
|
|
|
Lemma tm_step_consecutive_identical_length :
|
2023-01-10 18:16:29 -05:00
|
|
|
forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ tl -> length a = 5
|
|
|
|
-> exists (b c : list bool) (d : bool), a = b ++ [d;d] ++ c.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
destruct a. inversion I. destruct a. inversion I.
|
|
|
|
destruct a. inversion I. destruct a. inversion I.
|
|
|
|
destruct a. inversion I.
|
|
|
|
|
|
|
|
assert (a = nil). simpl in I.
|
|
|
|
apply Nat.succ_inj in I. apply Nat.succ_inj in I.
|
|
|
|
apply Nat.succ_inj in I. apply Nat.succ_inj in I.
|
|
|
|
apply Nat.succ_inj in I.
|
|
|
|
apply length_zero_iff_nil in I. assumption.
|
|
|
|
rewrite H0. rewrite H0 in H. rewrite H0 in I.
|
|
|
|
|
|
|
|
destruct b; destruct b0; destruct b1; destruct b2; destruct b3.
|
|
|
|
|
|
|
|
exists nil. exists (true::true::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (true::true::false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (true::false::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (true::false::false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (false::true::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (false::true::false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (false::false::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists nil. exists (false::false::false::nil). exists true. simpl. reflexivity.
|
|
|
|
|
|
|
|
exists (true::false::nil). exists (true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (true::false::nil). exists (false::nil). exists true. simpl. reflexivity.
|
2023-01-10 18:34:54 -05:00
|
|
|
apply tm_step_factor5 in H. contradiction H. reflexivity. reflexivity.
|
|
|
|
exists (true::false::true::nil). exists (nil). exists false. simpl. reflexivity.
|
|
|
|
exists (true::false::false::nil). exists (nil). exists true. simpl. reflexivity.
|
|
|
|
exists (true::nil). exists (true::false::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (true::nil). exists (false::true::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (true::false::nil). exists (false::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (false::nil). exists (true::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (false::nil). exists (true::false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (false::nil). exists (false::true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (false::nil). exists (false::false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (false::true::false::nil). exists (nil). exists true. simpl. reflexivity.
|
|
|
|
apply tm_step_factor5' in H. contradiction H. reflexivity. reflexivity.
|
|
|
|
exists (false::true::nil). exists (true::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (false::true::nil). exists (false::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (false::false::nil). exists (true::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (false::false::nil). exists (false::nil). exists true. simpl. reflexivity.
|
|
|
|
exists (nil). exists (true::false::true::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (nil). exists (true::false::false::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (nil). exists (false::true::true::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (nil). exists (false::true::false::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (nil). exists (false::false::true::nil). exists false. simpl. reflexivity.
|
|
|
|
exists (nil). exists (false::false::false::nil). exists false. simpl. reflexivity.
|
|
|
|
Qed.
|
2023-01-10 18:16:29 -05:00
|
|
|
|
2023-01-11 02:38:38 -05:00
|
|
|
Lemma tm_step_consecutive_identical_length' :
|
|
|
|
forall (n : nat) (hd a tl : list bool),
|
2023-01-11 03:03:32 -05:00
|
|
|
tm_step n = hd ++ a ++ tl -> 4 < length a
|
2023-01-11 02:38:38 -05:00
|
|
|
-> exists (b c : list bool) (d : bool), a = b ++ [d;d] ++ c.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
rewrite <- firstn_skipn with (l := a) (n := 5).
|
|
|
|
assert (length (firstn 5 a) = 5).
|
|
|
|
apply firstn_length_le. apply Nat.le_succ_l. apply I.
|
|
|
|
rewrite <- firstn_skipn with (l := a) (n := 5) in H.
|
|
|
|
rewrite <- app_assoc in H.
|
|
|
|
assert (exists (b1 c1 : list bool) (d1 : bool),
|
|
|
|
firstn 5 a = b1 ++ [d1; d1] ++ c1).
|
|
|
|
generalize H0. generalize H. apply tm_step_consecutive_identical_length.
|
|
|
|
destruct H1. destruct H1. destruct H1. rewrite H1.
|
|
|
|
exists x. exists (x0 ++ (skipn 5 a)). exists x1.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
Qed.
|
|
|
|
|
2023-01-10 18:16:29 -05:00
|
|
|
|
2023-01-11 03:19:23 -05:00
|
|
|
Theorem tm_step_odd_square : forall (n : nat) (hd a tl : list bool),
|
2023-01-11 03:03:32 -05:00
|
|
|
tm_step n = hd ++ a ++ a ++ tl -> odd (length a) = true -> length a < 4.
|
2023-01-10 12:04:42 -05:00
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
2023-01-11 03:03:32 -05:00
|
|
|
assert (J: 4 < length a \/ length a <= 4).
|
|
|
|
apply Nat.lt_ge_cases. destruct J.
|
|
|
|
assert (exists b c d, a = b ++ [d;d] ++ c).
|
|
|
|
generalize H0. generalize H. apply tm_step_consecutive_identical_length'.
|
|
|
|
destruct H1. destruct H1. destruct H1. rewrite H1 in H.
|
|
|
|
|
|
|
|
replace (hd ++ (x ++ [x1; x1] ++ x0) ++ (x ++ [x1; x1] ++ x0) ++ tl)
|
|
|
|
with ((hd ++ x) ++ [x1;x1] ++ (x0++x) ++ [x1;x1] ++ (x0 ++ tl)) in H.
|
|
|
|
apply tm_step_consecutive_identical in H.
|
|
|
|
|
|
|
|
assert (J: even (length (x0 ++ x)) = false).
|
|
|
|
rewrite H1 in I. rewrite app_length in I. rewrite app_length in I.
|
|
|
|
rewrite Nat.add_shuffle3 in I. rewrite Nat.add_comm in I.
|
|
|
|
rewrite Nat.odd_add_even in I.
|
|
|
|
rewrite app_length. rewrite Nat.add_comm. rewrite <- Nat.negb_odd.
|
|
|
|
rewrite I. reflexivity. apply Nat.EvenT_Even. apply Nat.even_EvenT.
|
|
|
|
reflexivity. rewrite H in J. inversion J.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-11 03:03:32 -05:00
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
reflexivity.
|
2023-01-07 05:27:20 -05:00
|
|
|
|
2023-01-11 03:03:32 -05:00
|
|
|
apply Nat.le_lteq in H0. destruct H0. assumption.
|
|
|
|
rewrite H0 in I. inversion I.
|
|
|
|
Qed.
|
2023-01-07 05:27:20 -05:00
|
|
|
|
|
|
|
|
2023-01-11 03:19:23 -05:00
|
|
|
(**
|
2023-01-11 08:50:03 -05:00
|
|
|
New following lemmas and theorems are related to the size
|
|
|
|
of squares in the Thue-Morse sequence, namely lengths of
|
|
|
|
2^n or 3 * 2^n only.
|
2023-01-11 03:19:23 -05:00
|
|
|
*)
|
2023-01-07 05:27:20 -05:00
|
|
|
|
2023-01-11 05:34:08 -05:00
|
|
|
Lemma tm_step_shift_odd_prefix_even_squares :
|
|
|
|
forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> even (length a) = true
|
|
|
|
-> odd (length hd) = true
|
|
|
|
-> exists (hd' b tl': list bool), tm_step n = hd' ++ b ++ b ++ tl'
|
|
|
|
/\ even (length hd') = true /\ length a = length b.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I J.
|
|
|
|
|
|
|
|
assert (W: {hd=nil} + {~ hd=nil}). apply list_eq_dec. apply bool_dec.
|
|
|
|
destruct W. rewrite e in J. simpl in J. rewrite Nat.odd_0 in J.
|
|
|
|
inversion J.
|
|
|
|
|
|
|
|
assert (Z: {a=nil} + {~ a=nil}). apply list_eq_dec. apply bool_dec.
|
|
|
|
destruct Z.
|
|
|
|
exists (removelast hd). exists nil. exists ((last hd true)::nil++tl).
|
|
|
|
split. rewrite app_nil_l. rewrite app_nil_l. rewrite app_nil_l.
|
|
|
|
replace ((last hd true)::tl) with ([last hd true] ++ tl).
|
|
|
|
rewrite app_assoc. rewrite <- app_removelast_last.
|
|
|
|
rewrite H. rewrite e. rewrite app_nil_l. rewrite app_nil_l. reflexivity.
|
|
|
|
assumption.
|
|
|
|
split. rewrite app_removelast_last with (l := hd) (d := last hd true) in J.
|
|
|
|
rewrite app_length in J. rewrite Nat.add_1_r in J. rewrite Nat.odd_succ in J.
|
|
|
|
rewrite J. split. reflexivity. rewrite e. reflexivity. assumption.
|
|
|
|
|
|
|
|
rewrite app_removelast_last with (l := hd) (d := true) in H.
|
|
|
|
rewrite app_removelast_last with (l := a) (d := true) in H.
|
|
|
|
rewrite app_assoc_reverse in H.
|
|
|
|
rewrite app_removelast_last with (l := hd) (d := true) in J.
|
|
|
|
rewrite app_length in J. rewrite Nat.add_1_r in J. rewrite Nat.odd_succ in J.
|
|
|
|
rewrite app_removelast_last with (l := a) (d := true) in I.
|
|
|
|
rewrite app_length in I. rewrite Nat.add_1_r in I.
|
|
|
|
exists (removelast hd).
|
|
|
|
rewrite app_assoc_reverse in H. rewrite app_assoc_reverse in H.
|
|
|
|
replace (
|
|
|
|
removelast hd ++ [last hd true] ++
|
|
|
|
removelast a ++ [last a true] ++ removelast a ++ [last a true] ++ tl)
|
|
|
|
with (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a) ++
|
|
|
|
([last a true] ++ tl)) in H.
|
|
|
|
assert (K: count_occ Bool.bool_dec (removelast hd) true
|
|
|
|
= count_occ Bool.bool_dec (removelast hd) false).
|
|
|
|
generalize J. generalize H. apply tm_step_count_occ.
|
|
|
|
assert (L: count_occ Bool.bool_dec (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a)) true
|
|
|
|
= count_occ Bool.bool_dec (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a)) false).
|
|
|
|
assert (M: even (length (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a))) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add_even. apply J.
|
|
|
|
rewrite app_length. apply Nat.EvenT_Even. apply Nat.even_EvenT.
|
|
|
|
rewrite Nat.even_add_even. rewrite app_length.
|
|
|
|
rewrite Nat.add_1_l. assumption.
|
|
|
|
rewrite app_length. apply Nat.EvenT_Even. apply Nat.even_EvenT.
|
|
|
|
rewrite Nat.add_1_l. assumption.
|
|
|
|
generalize M.
|
|
|
|
replace (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a) ++
|
|
|
|
([last a true] ++ tl))
|
|
|
|
with ((
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a) ++ ([last a true] ++ removelast a)) ++
|
|
|
|
([last a true] ++ tl)) in H.
|
|
|
|
generalize H. apply tm_step_count_occ.
|
|
|
|
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
|
|
|
|
assert (M: count_occ Bool.bool_dec (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a)) true
|
|
|
|
= count_occ Bool.bool_dec (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a)) false).
|
|
|
|
assert (N: even (length (
|
|
|
|
removelast hd ++
|
|
|
|
([last hd true] ++ removelast a))) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add_even. assumption.
|
|
|
|
rewrite app_length. apply Nat.EvenT_Even. apply Nat.even_EvenT.
|
|
|
|
rewrite Nat.add_1_l. assumption.
|
|
|
|
generalize N.
|
|
|
|
rewrite app_assoc in H. generalize H. apply tm_step_count_occ.
|
|
|
|
|
|
|
|
rewrite count_occ_app in M. symmetry in M. rewrite count_occ_app in M.
|
|
|
|
rewrite K in M. rewrite Nat.add_cancel_l in M.
|
|
|
|
|
|
|
|
rewrite count_occ_app in L. symmetry in L. rewrite count_occ_app in L.
|
|
|
|
rewrite K in L. rewrite Nat.add_cancel_l in L.
|
|
|
|
rewrite count_occ_app in L. symmetry in L. rewrite count_occ_app in L.
|
|
|
|
rewrite M in L. rewrite Nat.add_cancel_l in L.
|
|
|
|
|
|
|
|
assert (O: forall (m: nat), m <> S (S m)).
|
|
|
|
induction m. easy. apply not_eq_S. assumption.
|
|
|
|
|
|
|
|
assert (N: last hd true = last a true).
|
|
|
|
destruct (last hd true); destruct (last a true).
|
|
|
|
reflexivity.
|
|
|
|
rewrite count_occ_app in L. rewrite count_occ_app in L. simpl in L.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M. simpl in M.
|
|
|
|
rewrite L in M. apply O in M. contradiction M.
|
|
|
|
rewrite count_occ_app in L. rewrite count_occ_app in L. simpl in L.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M. simpl in M.
|
|
|
|
rewrite <- L in M. symmetry in M. apply O in M. contradiction M.
|
|
|
|
reflexivity.
|
|
|
|
|
|
|
|
rewrite N in H. exists ([last a true] ++ removelast a).
|
|
|
|
exists ([last a true] ++ tl). rewrite H.
|
|
|
|
|
|
|
|
split. reflexivity.
|
|
|
|
split. assumption.
|
|
|
|
rewrite app_length. rewrite app_removelast_last with (l := a) (d := true).
|
|
|
|
rewrite app_length. rewrite last_last. rewrite removelast_app.
|
|
|
|
rewrite Nat.add_1_r. rewrite app_nil_r. reflexivity. easy.
|
|
|
|
|
|
|
|
assumption.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff. reflexivity.
|
|
|
|
assumption. assumption. assumption. assumption.
|
|
|
|
Qed.
|
|
|
|
|
2023-01-11 07:54:07 -05:00
|
|
|
Lemma tm_step_normalize_prefix_even_squares :
|
|
|
|
forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> even (length a) = true
|
|
|
|
-> exists (hd' b tl': list bool), tm_step n = hd' ++ b ++ b ++ tl'
|
|
|
|
/\ even (length hd') = true /\ length a = length b.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (odd (length hd) = true \/ odd (length hd) = false).
|
|
|
|
destruct (odd (length hd)). left. reflexivity. right. reflexivity.
|
|
|
|
destruct H0.
|
|
|
|
generalize H0. generalize I. generalize H.
|
|
|
|
apply tm_step_shift_odd_prefix_even_squares.
|
|
|
|
exists hd. exists a. exists tl.
|
|
|
|
split. assumption. split. rewrite <- Nat.negb_odd. rewrite H0.
|
|
|
|
reflexivity. reflexivity.
|
|
|
|
Qed.
|
2023-01-07 05:27:20 -05:00
|
|
|
|
|
|
|
|
2023-01-11 07:54:07 -05:00
|
|
|
Lemma tm_step_square_half : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step (S n) = hd ++ a ++ a ++ tl
|
|
|
|
-> even (length a) = true
|
|
|
|
-> exists (hd' a' tl' : list bool), tm_step n = hd' ++ a' ++ a' ++ tl'
|
|
|
|
/\ length a = Nat.double (length a').
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (
|
|
|
|
exists (hd' b tl': list bool), tm_step (S n) = hd' ++ b ++ b ++ tl'
|
|
|
|
/\ even (length hd') = true /\ length a = length b).
|
|
|
|
generalize I. generalize H. apply tm_step_normalize_prefix_even_squares.
|
|
|
|
destruct H0. destruct H0. destruct H0.
|
|
|
|
destruct H0. destruct H1. rewrite H2 in I.
|
|
|
|
rewrite <- tm_step_lemma in H0.
|
|
|
|
assert (x = tm_morphism (firstn (Nat.div2 (length x)) (tm_step n))).
|
|
|
|
apply tm_morphism_app2 with (tl := x0 ++ x0 ++ x1). apply H0.
|
|
|
|
assumption.
|
|
|
|
assert (x0 ++ x0 ++ x1 = tm_morphism (skipn (Nat.div2 (length x)) (tm_step n))).
|
|
|
|
apply tm_morphism_app3. apply H0. assumption.
|
|
|
|
|
|
|
|
assert (Z := H0).
|
|
|
|
|
|
|
|
assert (H7: length (tm_morphism (tm_step n)) = length (tm_morphism (tm_step n))).
|
|
|
|
reflexivity. rewrite Z in H7 at 2. rewrite tm_morphism_length in H7.
|
|
|
|
rewrite app_length in H7.
|
|
|
|
rewrite app_length in H7.
|
|
|
|
rewrite Nat.Even_double with (n := length x) in H7.
|
|
|
|
rewrite Nat.Even_double with (n := length x0) in H7.
|
|
|
|
rewrite Nat.Even_double with (n := length (x0 ++ x1)) in H7.
|
|
|
|
rewrite Nat.double_twice in H7.
|
|
|
|
rewrite Nat.double_twice in H7.
|
|
|
|
rewrite Nat.double_twice in H7.
|
|
|
|
rewrite <- Nat.mul_add_distr_l in H7.
|
|
|
|
rewrite <- Nat.mul_add_distr_l in H7.
|
|
|
|
rewrite Nat.mul_cancel_l in H7.
|
|
|
|
|
|
|
|
assert (x0 = tm_morphism (firstn (Nat.div2 (length x0)) (skipn (Nat.div2 (length x)) (tm_step n)))).
|
|
|
|
apply tm_morphism_app2 with (tl := x0 ++ x1). symmetry. assumption.
|
|
|
|
assumption.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
2023-01-11 07:54:07 -05:00
|
|
|
assert (x1 = tm_morphism (skipn (Nat.div2 (length (x0++x0)))
|
|
|
|
(skipn (Nat.div2 (length x)) (tm_step n)))).
|
|
|
|
apply tm_morphism_app3. symmetry. rewrite app_assoc_reverse. apply H4.
|
|
|
|
rewrite app_length. rewrite Nat.even_add_even. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
|
|
|
|
rewrite H3 in H0. rewrite H5 in H0. rewrite H6 in H0.
|
|
|
|
rewrite <- tm_morphism_app in H0.
|
|
|
|
rewrite <- tm_morphism_app in H0.
|
|
|
|
rewrite <- tm_morphism_app in H0.
|
|
|
|
rewrite <- tm_morphism_eq in H0.
|
|
|
|
rewrite H0.
|
|
|
|
exists (firstn (Nat.div2 (length x)) (tm_step n)).
|
|
|
|
exists (firstn (Nat.div2 (length x0)) (skipn (Nat.div2 (length x)) (tm_step n))).
|
|
|
|
exists (skipn (Nat.div2 (length (x0 ++ x0))) (skipn (Nat.div2 (length x)) (tm_step n))).
|
|
|
|
split. reflexivity.
|
|
|
|
rewrite firstn_length_le. rewrite <- Nat.Even_double. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
rewrite skipn_length.
|
|
|
|
|
|
|
|
rewrite H7. rewrite Nat.add_sub_swap. rewrite Nat.sub_diag.
|
|
|
|
rewrite Nat.add_0_l. rewrite <- Nat.add_0_r at 1.
|
|
|
|
rewrite <- Nat.add_le_mono_l.
|
|
|
|
apply le_0_n. apply le_n. easy.
|
|
|
|
|
|
|
|
rewrite <- Nat.Even_double in H7. rewrite <- Nat.Even_double in H7.
|
|
|
|
rewrite Nat.add_assoc in H7.
|
|
|
|
assert (Nat.even (2 * (length (tm_step n))) = true).
|
|
|
|
apply Nat.even_mul. rewrite H7 in H5.
|
|
|
|
rewrite Nat.even_add in H5.
|
|
|
|
rewrite Nat.even_add in H5.
|
|
|
|
rewrite I in H5. rewrite H1 in H5.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT.
|
|
|
|
destruct (Nat.even (length (x0 ++ x1))). reflexivity.
|
|
|
|
inversion H5.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. assumption.
|
|
|
|
Qed.
|
2023-01-10 12:04:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-11 08:50:03 -05:00
|
|
|
Theorem tm_step_square_size : forall (n k j : nat) (hd a tl : list bool),
|
2023-01-11 08:43:04 -05:00
|
|
|
tm_step (S n) = hd ++ a ++ a ++ tl
|
|
|
|
-> length a = (S (Nat.double k)) * 2^j
|
|
|
|
-> (k = 0 \/ k = 1).
|
|
|
|
Proof.
|
|
|
|
intros n k j hd a tl.
|
|
|
|
generalize hd. generalize a. generalize tl. induction j.
|
|
|
|
- intros tl0 a0 hd0. intros H I. simpl in I. rewrite Nat.mul_1_r in I.
|
|
|
|
assert (odd (length a0) = true). rewrite I.
|
|
|
|
rewrite Nat.odd_succ. rewrite Nat.double_twice.
|
|
|
|
apply Nat.even_mul.
|
|
|
|
assert (J: length a0 < 4). generalize H0. generalize H.
|
|
|
|
apply tm_step_odd_square.
|
|
|
|
rewrite I in J.
|
|
|
|
destruct k. left. reflexivity.
|
|
|
|
destruct k. right. reflexivity.
|
|
|
|
apply Nat.succ_lt_mono in J.
|
|
|
|
apply Nat.lt_lt_succ_r in J.
|
|
|
|
rewrite Nat.double_twice in J. replace (4) with (2*2) in J.
|
|
|
|
rewrite <- Nat.mul_lt_mono_pos_l in J.
|
|
|
|
apply Nat.succ_lt_mono in J.
|
|
|
|
apply Nat.succ_lt_mono in J.
|
|
|
|
apply Nat.nlt_0_r in J. contradiction J.
|
|
|
|
apply Nat.lt_0_2. reflexivity.
|
|
|
|
- intros tl0 a0 hd0. intros H I.
|
|
|
|
assert (exists (hd' a' tl' : list bool), tm_step n = hd' ++ a' ++ a' ++ tl'
|
|
|
|
/\ length a0 = Nat.double (length a')).
|
|
|
|
assert (even (length a0) = true).
|
|
|
|
rewrite I. rewrite Nat.pow_succ_r'. rewrite Nat.mul_comm.
|
|
|
|
rewrite <- Nat.mul_assoc. apply Nat.even_mul.
|
|
|
|
generalize H0. generalize H. apply tm_step_square_half.
|
|
|
|
destruct H0. destruct H0. destruct H0. destruct H0.
|
|
|
|
rewrite H1 in I. rewrite Nat.pow_succ_r' in I. rewrite Nat.mul_comm in I.
|
|
|
|
rewrite <- Nat.mul_assoc in I. rewrite Nat.double_twice in I.
|
|
|
|
rewrite Nat.mul_cancel_l in I. rewrite Nat.mul_comm in I.
|
|
|
|
generalize I.
|
|
|
|
assert (tm_step (S n) = x ++ x0 ++ x0 ++ x1 ++ (map negb (tm_step n))).
|
|
|
|
rewrite tm_build. rewrite H0.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
generalize H2. apply IHj. easy.
|
|
|
|
Qed.
|
2023-01-11 10:55:50 -05:00
|
|
|
|
2023-01-12 12:18:17 -05:00
|
|
|
(**
|
|
|
|
This section contains lemmas and theorems related to the length of the
|
|
|
|
prefix being odd or even in front of a squared pattern.
|
|
|
|
*)
|
|
|
|
|
|
|
|
Lemma tm_step_odd_prefix_square_1 : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> length a = 1 -> even (length hd) = false.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (J: Nat.even (length hd) || Nat.odd (length hd) = true).
|
|
|
|
apply Nat.orb_even_odd. apply orb_prop in J. destruct J.
|
|
|
|
- assert (K: count_occ Bool.bool_dec hd true
|
|
|
|
= count_occ Bool.bool_dec hd false).
|
|
|
|
generalize H0. generalize H. apply tm_step_count_occ.
|
|
|
|
assert (L: even (length (hd ++ a ++ a)) = true).
|
|
|
|
rewrite app_length. rewrite app_length. rewrite I.
|
|
|
|
rewrite Nat.even_add_even. assumption. rewrite Nat.add_1_r.
|
|
|
|
apply Nat.EvenT_Even. apply Nat.even_EvenT. easy.
|
|
|
|
assert (M: count_occ Bool.bool_dec (hd ++ a ++ a) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ a ++ a) false).
|
|
|
|
generalize L. generalize H.
|
|
|
|
replace (hd ++ a ++ a ++ tl) with ((hd ++ a ++ a) ++ tl).
|
|
|
|
apply tm_step_count_occ.
|
|
|
|
rewrite <- app_assoc. apply app_inv_head_iff.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
rewrite count_occ_app in M. symmetry in M.
|
|
|
|
rewrite count_occ_app in M. rewrite K in M.
|
|
|
|
rewrite Nat.add_cancel_l in M. destruct a.
|
|
|
|
+ inversion I.
|
|
|
|
+ destruct b; simpl in I; apply Nat.succ_inj in I;
|
|
|
|
rewrite length_zero_iff_nil in I; rewrite I in M;
|
|
|
|
simpl in M; inversion M.
|
|
|
|
- rewrite <- Nat.negb_odd. rewrite H0. reflexivity.
|
|
|
|
Qed.
|
|
|
|
|
|
|
|
Lemma tm_step_odd_prefix_square_3 : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> length a = 3 -> even (length hd) = false.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (J: Nat.even (length hd) || Nat.odd (length hd) = true).
|
|
|
|
apply Nat.orb_even_odd. apply orb_prop in J. destruct J.
|
|
|
|
assert (Z: a = [true;false;true] \/ a = [false;true;false]).
|
|
|
|
destruct a. inversion I. destruct a. inversion I.
|
|
|
|
destruct a. inversion I. destruct a.
|
|
|
|
- destruct b; destruct b0; destruct b1.
|
|
|
|
+ replace ([true;true;true] ++ [true;true;true] ++ tl)
|
|
|
|
with ([true;true] ++ [true] ++ [true;true] ++ [true] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
reflexivity.
|
|
|
|
+ replace ([true;true;false] ++ [true;true;false] ++ tl)
|
|
|
|
with ([true;true] ++ [false] ++ [true;true] ++ [false] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
reflexivity.
|
|
|
|
+ left. reflexivity.
|
|
|
|
+ replace (hd ++ [true;false;false] ++ [true;false;false] ++ tl)
|
|
|
|
with ((hd ++ [true]) ++ [false; false] ++ [true] ++ [false;false] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
+ replace (hd ++ [false;true;true] ++ [false;true;true] ++ tl)
|
|
|
|
with ((hd ++ [false]) ++ [true; true] ++ [false] ++ [true;true] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
+ right. reflexivity.
|
|
|
|
+ replace ([false;false;true] ++ [false;false;true] ++ tl)
|
|
|
|
with ([false;false] ++ [true] ++ [false;false] ++ [true] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
reflexivity.
|
|
|
|
+ replace ([false;false;false] ++ [false;false;false] ++ tl)
|
|
|
|
with ([false;false] ++ [false] ++ [false;false] ++ [false] ++ tl) in H.
|
|
|
|
apply tm_step_consecutive_identical in H. inversion H.
|
|
|
|
reflexivity.
|
|
|
|
- inversion I.
|
|
|
|
- assert (K: count_occ Bool.bool_dec hd true
|
|
|
|
= count_occ Bool.bool_dec hd false).
|
|
|
|
generalize H0. generalize H. apply tm_step_count_occ.
|
|
|
|
destruct Z; rewrite H1 in H.
|
|
|
|
replace (hd ++ [true;false;true] ++ [true;false;true] ++ tl)
|
|
|
|
with ((hd ++ [true;false;true;true]) ++ [false;true] ++ tl) in H.
|
|
|
|
assert (even (length (hd ++ [true;false;true;true])) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add. rewrite H0. reflexivity.
|
|
|
|
assert (M: count_occ Bool.bool_dec (hd ++ [true;false;true;true]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [true;false;true;true]) false).
|
|
|
|
generalize H2. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite count_occ_app in M. symmetry in M. rewrite count_occ_app in M.
|
|
|
|
rewrite K in M. rewrite Nat.add_cancel_l in M. inversion M.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
replace (hd ++ [false;true;false] ++ [false;true;false] ++ tl)
|
|
|
|
with ((hd ++ [false;true;false;false]) ++ [true;false] ++ tl) in H.
|
|
|
|
assert (even (length (hd ++ [false;true;false;false])) = true).
|
|
|
|
rewrite app_length. rewrite Nat.even_add. rewrite H0. reflexivity.
|
|
|
|
assert (M: count_occ Bool.bool_dec (hd ++ [false;true;false;false]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [false;true;false;false]) false).
|
|
|
|
generalize H2. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite count_occ_app in M. symmetry in M. rewrite count_occ_app in M.
|
|
|
|
rewrite K in M. rewrite Nat.add_cancel_l in M. inversion M.
|
|
|
|
rewrite <- app_assoc. reflexivity.
|
|
|
|
- rewrite <- Nat.negb_odd. rewrite H0. reflexivity.
|
|
|
|
Qed.
|
|
|
|
|
|
|
|
Lemma tm_step_odd_prefix_square : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> odd (length a) = true -> even (length hd) = false.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
assert (length a < 4).
|
|
|
|
generalize I. generalize H. apply tm_step_odd_square.
|
|
|
|
destruct a. inversion I.
|
|
|
|
destruct a.
|
|
|
|
apply tm_step_odd_prefix_square_1 with (n := n) (a := [b]) (tl := tl).
|
|
|
|
assumption. reflexivity.
|
|
|
|
destruct a. inversion I.
|
|
|
|
destruct a.
|
|
|
|
apply tm_step_odd_prefix_square_3 with (n := n) (a := [b;b0;b1]) (tl := tl).
|
|
|
|
assumption. reflexivity.
|
|
|
|
simpl in H0.
|
|
|
|
rewrite <- Nat.succ_lt_mono in H0.
|
|
|
|
rewrite <- Nat.succ_lt_mono in H0.
|
|
|
|
rewrite <- Nat.succ_lt_mono in H0.
|
|
|
|
rewrite <- Nat.succ_lt_mono in H0.
|
|
|
|
apply Nat.nlt_0_r in H0. contradiction H0.
|
|
|
|
Qed.
|
|
|
|
|
|
|
|
|
|
|
|
Theorem tm_step_square_pos_even : forall (n : nat) (hd a tl : list bool),
|
|
|
|
tm_step n = hd ++ a ++ a ++ tl
|
|
|
|
-> 0 < length a -> even (length (hd ++ a)) = true.
|
|
|
|
Proof.
|
|
|
|
intros n hd a tl. intros H I.
|
|
|
|
|
|
|
|
rewrite app_length. rewrite Nat.even_add.
|
|
|
|
assert (J: Nat.even (length a) || Nat.odd (length a) = true).
|
|
|
|
apply Nat.orb_even_odd. apply orb_prop in J. destruct J.
|
|
|
|
- rewrite H0.
|
2023-01-13 15:40:23 -05:00
|
|
|
assert (J: Nat.even (length hd) || Nat.odd (length hd) = true).
|
|
|
|
apply Nat.orb_even_odd. apply orb_prop in J. destruct J.
|
|
|
|
rewrite H1. reflexivity.
|
|
|
|
|
|
|
|
(* proof that tl is not nil *)
|
|
|
|
destruct tl. rewrite app_nil_r in H.
|
|
|
|
assert (length (tm_step n) = length (tm_step n)). reflexivity.
|
|
|
|
rewrite H in H2 at 2.
|
|
|
|
assert (even (length (tm_step n)) = even (length (tm_step n))). reflexivity.
|
|
|
|
rewrite H in H3 at 2. rewrite app_length in H3. rewrite app_length in H3.
|
|
|
|
rewrite Nat.even_add in H3.
|
|
|
|
rewrite Nat.even_add in H3.
|
|
|
|
rewrite H0 in H3. symmetry in H3.
|
|
|
|
rewrite <- Nat.negb_odd in H3. rewrite H1 in H3. simpl in H3.
|
|
|
|
rewrite tm_size_power2 in H3. destruct n.
|
|
|
|
assert (1 < length (hd ++ a ++ a)). rewrite app_length.
|
|
|
|
apply Nat.lt_lt_add_l. rewrite app_length.
|
|
|
|
rewrite <- Nat.le_succ_l in I. rewrite <- Nat.le_succ_l.
|
|
|
|
rewrite <- Nat.add_1_r. apply Nat.add_le_mono; assumption.
|
|
|
|
rewrite <- H2 in H4. apply Nat.lt_irrefl in H4. contradiction H4.
|
|
|
|
rewrite Nat.pow_succ_r' in H3. rewrite Nat.even_mul in H3.
|
|
|
|
simpl in H3. inversion H3.
|
|
|
|
|
|
|
|
(* proof that a is not nil *)
|
|
|
|
destruct a. inversion I.
|
|
|
|
|
|
|
|
replace (hd ++ (b0 :: a) ++ (b0 :: a) ++ b :: tl)
|
|
|
|
with ((hd ++ [b0]) ++ a ++ (b0::a) ++ b::tl) in H.
|
|
|
|
assert (even (length (hd ++ [b0])) = true).
|
|
|
|
rewrite app_length. rewrite Nat.add_1_r. rewrite Nat.even_succ.
|
|
|
|
assumption.
|
|
|
|
assert (L: count_occ Bool.bool_dec (hd ++ [b0]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [b0]) false).
|
|
|
|
generalize H2. generalize H. apply tm_step_count_occ.
|
|
|
|
|
|
|
|
replace ((hd ++ [b0]) ++ a ++ (b0::a) ++ b::tl)
|
|
|
|
with ((hd ++ [b0] ++ a ++ [b0] ++ a ++ [b]) ++ tl) in H.
|
|
|
|
assert (even (length (hd ++ [b0] ++ a ++ [b0] ++ a ++ [b])) = true).
|
|
|
|
rewrite <- app_assoc_reverse. rewrite app_length.
|
|
|
|
rewrite Nat.even_add. rewrite H2.
|
|
|
|
rewrite app_length. rewrite app_length. rewrite app_length.
|
|
|
|
rewrite Nat.add_1_r. rewrite <- Nat.add_succ_comm.
|
|
|
|
rewrite Nat.even_add.
|
|
|
|
destruct (even (S (length a))); reflexivity.
|
|
|
|
assert (M: count_occ Bool.bool_dec (hd ++ [b0]++a++[b0]++a++[b]) true
|
|
|
|
= count_occ Bool.bool_dec (hd ++ [b0]++a++[b0]++a++[b]) false).
|
|
|
|
generalize H3. generalize H. apply tm_step_count_occ.
|
|
|
|
rewrite app_assoc in M. rewrite count_occ_app in M.
|
|
|
|
symmetry in M. rewrite count_occ_app in M. rewrite L in M.
|
|
|
|
rewrite Nat.add_cancel_l in M.
|
|
|
|
|
|
|
|
assert (forall x , x + x = 2*x).
|
|
|
|
intro x. rewrite <- Nat.mul_1_l with (n := x).
|
|
|
|
rewrite <- Nat.mul_add_distr_r. rewrite Nat.add_1_r.
|
|
|
|
rewrite Nat.mul_1_l. reflexivity.
|
|
|
|
Opaque even. simpl in H0. Transparent even.
|
|
|
|
assert (b = b0). destruct b0; destruct b.
|
|
|
|
+ reflexivity.
|
|
|
|
+ rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
simpl in M. rewrite Nat.add_1_r in M. rewrite Nat.add_0_r in M.
|
|
|
|
rewrite Nat.add_succ_r in M. rewrite Nat.add_succ_r in M.
|
|
|
|
inversion M.
|
|
|
|
rewrite H4 in H6. rewrite H4 in H6.
|
|
|
|
rewrite Nat.mul_cancel_l in H6.
|
|
|
|
apply count_occ_bool_list2 in H6.
|
|
|
|
rewrite <- H0 in H6. rewrite Nat.even_succ in H6.
|
|
|
|
rewrite <- Nat.negb_even in H6.
|
|
|
|
destruct (even (length a)); inversion H6. easy.
|
|
|
|
+ rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
rewrite count_occ_app in M. rewrite count_occ_app in M.
|
|
|
|
simpl in M. rewrite Nat.add_1_r in M. rewrite Nat.add_0_r in M.
|
|
|
|
rewrite Nat.add_succ_r in M. rewrite Nat.add_succ_r in M.
|
|
|
|
inversion M.
|
|
|
|
rewrite H4 in H6. rewrite H4 in H6.
|
|
|
|
rewrite Nat.mul_cancel_l in H6.
|
|
|
|
apply count_occ_bool_list2 in H6.
|
|
|
|
rewrite <- H0 in H6. rewrite Nat.even_succ in H6.
|
|
|
|
rewrite <- Nat.negb_even in H6.
|
|
|
|
destruct (even (length a)); inversion H6. easy.
|
|
|
|
+ reflexivity.
|
|
|
|
+ rewrite H5 in H.
|
2023-01-11 10:55:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-12 12:37:20 -05:00
|
|
|
(* TODO: utiliser tm_step_odd_prefix_square pour le cas impair *)
|
2023-01-13 15:40:23 -05:00
|
|
|
(* TODO: la taille du facteur divise la taille du préfixe ? *)
|
|
|
|
|
|
|
|
Admitted.
|
2023-01-12 12:37:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
|