-
Notifications
You must be signed in to change notification settings - Fork 0
/
parking.v
59 lines (44 loc) · 2.06 KB
/
parking.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From mathcomp Require Import all_ssreflect all_algebra.
Import GRing.Theory.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Section Parking.
(* Une grille est une fonction qui prend deux nombres et retourne un booléen *)
Definition grid n := 'I_n -> 'I_n -> bool.
(* La somme sur une ligne *)
Definition sumL n (g : grid n) i := \sum_(j < n) g i j.
(* La somme sur une colonne *)
Definition sumC n (g : grid n) j := \sum_(i < n) g i j.
(* Deux petites propriétés pour pouvoir utiliser des arguments d'injectivité *)
Lemma leq_sumL n (g : grid n) i : sumL g i < n.+1.
Proof.
have {2}<-: \sum_(i < n) 1 = n by rewrite -[X in _ = X]card_ord sum1_card.
by apply: leq_sum => k; case: (g _ _).
Qed.
Lemma leq_sumC n (g : grid n) j : sumC g j < n.+1.
Proof.
have {2}<-: \sum_(i < n) 1 = n by rewrite -[X in _ = X]card_ord sum1_card.
by apply: leq_sum => k; case: (g _ _).
Qed.
(* Dans une grille non vide, deux lignes ou deux colonnes, ou une ligne et une
colonne ont la même somme *)
Lemma inl_inj {A B} : injective (@inl A B). Proof. by move=> ?? []. Qed.
Lemma inr_inj {A B} : injective (@inr A B). Proof. by move=> ?? []. Qed.
Lemma result n (g : grid n) : 0 < n ->
exists i, exists j,
[\/ (i != j) /\ (sumL g i = sumL g j),
(i != j) /\ (sumC g i = sumC g j) | sumL g i = sumC g j].
Proof.
case: n g => [//|[|n]] g _.
by exists ord0, ord0; apply: Or33; rewrite /sumL /sumC !big_ord1.
pose sLC i := match i with | inl i => Ordinal (leq_sumL g i)
| inr i => Ordinal (leq_sumC g i) end.
have [sC_inj|/injectivePn] := altP (injectiveP sLC).
have := max_card (mem (codom sLC)); rewrite card_codom // card_sum !card_ord.
by rewrite !addnS !addSn !ltnS -ltn_subRL subnn ltn0.
move=> [[i|i] [[j|j] //=]]; [| |move: i j => j i|];
rewrite ?(inj_eq inj_inl, inj_eq inj_inr) => neq_ij [];
by exists i, j; do ?[exact: Or31|exact: Or32|exact: Or33].
Qed.
End Parking.