Skip to content
Snippets Groups Projects
Commit ac2a288c authored by Sergey Bozhko's avatar Sergey Bozhko :eyes:
Browse files

clean up in util/lcmseq.v

parent c68ae072
No related branches found
No related tags found
No related merge requests found
...@@ -20,11 +20,7 @@ Section Hyperperiod. ...@@ -20,11 +20,7 @@ Section Hyperperiod.
Lemma hyperperiod_int_mult_of_any_task: Lemma hyperperiod_int_mult_of_any_task:
exists (k : nat), exists (k : nat),
hyperperiod ts = k * task_period tsk. hyperperiod ts = k * task_period tsk.
Proof. Proof. by apply/dvdnP; apply lcm_seq_is_mult_of_all_ints, map_f, H_tsk_in_ts. Qed.
apply lcm_seq_is_mult_of_all_ints.
apply map_f.
now apply H_tsk_in_ts.
Qed.
End Hyperperiod. End Hyperperiod.
......
...@@ -2,47 +2,41 @@ From mathcomp Require Export ssreflect seq div ssrbool ssrnat eqtype ssrfun. ...@@ -2,47 +2,41 @@ From mathcomp Require Export ssreflect seq div ssrbool ssrnat eqtype ssrfun.
Require Export prosa.util.tactics. Require Export prosa.util.tactics.
(** A function to calculate the least common multiple (** A function to calculate the least common multiple
of all integers in a sequence [xs], denoted by [lcml xs] **) of all integers in a sequence [xs], denoted by [lcml xs]. *)
Definition lcml (xs : seq nat) : nat := foldr lcmn 1 xs. Definition lcml (xs : seq nat) : nat := foldr lcmn 1 xs.
(** Any integer [a] that is contained in the sequence [xs] divides [lcml xs]. **) (** First we show that [x] divides [lcml (x :: xs)] for any [x] and [xs]. *)
Lemma int_divides_lcm_in_seq: Lemma int_divides_lcm_in_seq:
forall (a : nat) (xs : seq nat), a %| lcml (a :: xs). forall (x : nat) (xs : seq nat), x %| lcml (x :: xs).
Proof. Proof.
intros. induction xs.
rewrite /lcml. - by apply dvdn_lcml.
induction xs. - rewrite /lcml -cat1s foldr_cat /foldr.
- rewrite /foldr.
now apply dvdn_lcml.
- rewrite -cat1s.
rewrite foldr_cat /foldr.
by apply dvdn_lcml. by apply dvdn_lcml.
Qed. Qed.
(** Also, [lcml xs1] divides [lcml xs2] if [xs2] contains one extra element as compared to [xs1]. *) (** Similarly, [lcml xs] divides [lcml (x :: xs)] for any [x] and [xs]. *)
Lemma lcm_seq_divides_lcm_super: Lemma lcm_seq_divides_lcm_super:
forall (x : nat) (xs : seq nat), forall (x : nat) (xs : seq nat),
lcml xs %| lcml (x :: xs). lcml xs %| lcml (x :: xs).
Proof. Proof.
intros.
rewrite /lcml.
induction xs; first by auto. induction xs; first by auto.
rewrite -cat1s foldr_cat /foldr. rewrite /lcml -cat1s foldr_cat /foldr.
by apply dvdn_lcmr. by apply dvdn_lcmr.
Qed. Qed.
(** All integers in a sequence [xs] divide [lcml xs]. *) (** Given a sequence [xs], any integer [x \in xs] divides [lcml xs]. *)
Lemma lcm_seq_is_mult_of_all_ints: Lemma lcm_seq_is_mult_of_all_ints:
forall (sq : seq nat) (a : nat), a \in sq -> exists k, lcml sq = k * a. forall (x : nat) (xs: seq nat), x \in xs -> x %| lcml xs.
Proof. Proof.
intros xs x IN. intros x xs IN; apply/dvdnP.
induction xs as [ | z sq IH_DIVIDES]; first by easy. induction xs as [ | z sq IH_DIV]; first by done.
rewrite in_cons in IN. rewrite in_cons in IN.
move : IN => /orP [/eqP EQ | IN]. move : IN => /orP [/eqP EQ | IN].
+ apply /dvdnP. - apply /dvdnP.
rewrite EQ /lcml. rewrite EQ /lcml.
by apply int_divides_lcm_in_seq. by apply int_divides_lcm_in_seq.
+ move : (IH_DIVIDES IN) => [k EQ]. + move : (IH_DIV IN) => [k EQ].
exists ((foldr lcmn 1 (z :: sq)) %/ (foldr lcmn 1 sq) * k). exists ((foldr lcmn 1 (z :: sq)) %/ (foldr lcmn 1 sq) * k).
rewrite -mulnA -EQ divnK /lcml //. rewrite -mulnA -EQ divnK /lcml //.
by apply lcm_seq_divides_lcm_super. by apply lcm_seq_divides_lcm_super.
...@@ -51,18 +45,14 @@ Qed. ...@@ -51,18 +45,14 @@ Qed.
(** The LCM of all elements in a sequence with only positive elements is positive. *) (** The LCM of all elements in a sequence with only positive elements is positive. *)
Lemma all_pos_implies_lcml_pos: Lemma all_pos_implies_lcml_pos:
forall (xs : seq nat), forall (xs : seq nat),
(forall b, b \in xs -> b > 0) -> (forall x, x \in xs -> x > 0) ->
lcml xs > 0. lcml xs > 0.
Proof. Proof.
intros * POS. intros * POS.
induction xs; first by easy. induction xs; first by easy.
rewrite /lcml -cat1s => //. rewrite /lcml -cat1s //= lcmn_gt0.
simpl; rewrite lcmn_gt0. apply/andP; split => //.
apply /andP; split => //. - by apply POS; rewrite in_cons eq_refl.
+ apply POS; rewrite in_cons; apply /orP; left. - apply: IHxs; intros b B_IN.
now apply /eqP. by apply POS; rewrite in_cons; apply /orP; right => //.
+ feed_n 1 IHxs.
- intros b B_IN.
now apply POS; rewrite in_cons; apply /orP; right => //.
- now rewrite /lcml in IHxs.
Qed. Qed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment