|
| 1 | +import Autoomaton.Buchi |
| 2 | +import Autoomaton.NatRF |
| 3 | +import Autoomaton.Path |
| 4 | +import Autoomaton.succeeds |
| 5 | + |
| 6 | + |
| 7 | +namespace ordinal2 |
| 8 | +variable {S A: Type} [Preorder A] [WellFoundedLT A] {a : Automaton S} (r : Run a) |
| 9 | + |
| 10 | +universe u |
| 11 | + |
| 12 | +/-- An ordinal-valued ranking function for a Büchi automaton maps states to ordinals. |
| 13 | +The rank must not increase along transitions. If the source state of a transition is fair, the rank must strictly decrease. |
| 14 | +This is a more general form of a ranking function. |
| 15 | +-/ |
| 16 | +structure OrdinalRankingFunction {S: Type} (A : Type u) [Preorder A] [WellFoundedLT A] (a : Automaton S) : Type u where |
| 17 | + /-- The ranking function $W: S \to \text{Ordinal}$. -/ |
| 18 | + rank : S → A |
| 19 | + reach : S → Prop |
| 20 | + init_reach : (s : S) → a.I s → reach s |
| 21 | + next_reach (s1 s2 : S) : a.R s1 s2 → reach s1 → reach s2 |
| 22 | + /-- The condition on the ranking function: for all transitions $(s_1, s_2) \in R$, |
| 23 | + $W(s_2) + \mathbb{I}(s_1 \in F) \le W(s_1)$, where $\mathbb{I}$ is the indicator function. -/ |
| 24 | + rank_le_of_rel_fair : ∀ s1 s2, a.R s1 s2 → reach s1 → a.F s1 → rank s2 < rank s1 |
| 25 | + rank_le_of_rel_unfair : ∀ s1 s2, a.R s1 s2 → reach s1 → rank s2 ≤ rank s1 |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +variable (W : OrdinalRankingFunction A a) |
| 31 | +theorem run_reachable2 (n : Nat) : W.reach (r.f n) := by |
| 32 | + induction' n with m ih |
| 33 | + · exact W.init_reach (r.f 0) (r.is_init) |
| 34 | + · exact W.next_reach (r.f m) (r.f (m + 1)) (r.is_valid m) ih |
| 35 | + |
| 36 | +/-- The sequence of ranks at the times of fair visits. |
| 37 | +`ordSeq r W n` is the rank of the state at the `n`-th fair visit, i.e., $W(r.f(\text{nth_visit}(r, n)))$. -/ |
| 38 | +noncomputable def ordSeq (n : Nat) : A := W.rank (r.f (nth_visit r n)) |
| 39 | + |
| 40 | +/-- If a run `r` is fair, then the set of its fair visits is infinite. This is a direct consequence of the definition of a fair run. -/ |
| 41 | +theorem fair_infinite (r_fair : r.IsFair) : Set.Infinite (fairVisits r) := by |
| 42 | + simp only [Set.infinite_iff_exists_gt, Set.mem_setOf_eq] |
| 43 | + intro a |
| 44 | + rcases (r_fair a) with ⟨k, k_gt_a, k_fair⟩ |
| 45 | + exact ⟨k, ⟨k_fair, by omega⟩⟩ |
| 46 | + |
| 47 | +/-- If a run `r` is fair, then the state at the `n`-th fair visit is indeed a fair state. |
| 48 | +$r.f(\text{nth_visit}(r, n)) \in F$. -/ |
| 49 | +theorem is_fair_at_nth_visit (n : Nat) (r_fair : r.IsFair) : a.F (r.f (nth_visit r n)) := Nat.nth_mem_of_infinite (fair_infinite r r_fair) n |
| 50 | + |
| 51 | +/-- The sequence of ranks along a run is antitone (non-increasing). |
| 52 | +The function $n \mapsto W(r.f(n))$ is an antitone function from $\mathbb{N}$ to the ordinals. -/ |
| 53 | +theorem rank_antitone : Antitone (fun n => W.rank (r.f n)) := antitone_nat_of_succ_le (fun n => by |
| 54 | + have cf := W.rank_le_of_rel_fair (r.f n) (r.f (n + 1)) (r.is_valid n) |
| 55 | + have cu := W.rank_le_of_rel_unfair (r.f n) (r.f (n + 1)) (r.is_valid n) |
| 56 | + by_cases is_fair : a.F (r.f n) |
| 57 | + <;> simp only [is_fair, ↓reduceIte, Ordinal.add_one_eq_succ, Order.succ_le_iff, Bool.false_eq_true, add_zero] at cf |
| 58 | + · exact LT.lt.le (W.rank_le_of_rel_fair (r.f n) (r.f (n + 1)) (r.is_valid n) (run_reachable2 r W n) is_fair) |
| 59 | + · exact cu (run_reachable2 r W n)) |
| 60 | + |
| 61 | +/-- For a fair run, the sequence of ranks at fair visits is strictly decreasing. |
| 62 | +$W(r.f(\text{nth_visit}(r, n+1))) < W(r.f(\text{nth_visit}(r, n)))$. -/ |
| 63 | +theorem ordSeq_strict_anti (r_fair : r.IsFair) : StrictAnti (ordSeq r W) := strictAnti_nat_of_succ_lt (fun n => by |
| 64 | + have : nth_visit r n < nth_visit r (n + 1) := @Nat.nth_strictMono (fun (x : Nat) => a.F (r.f x)) (fair_infinite r r_fair) n (n + 1) (by omega) |
| 65 | + have yf := W.rank_le_of_rel_fair (r.f (nth_visit r n)) (r.f (nth_visit r (n) + 1)) (r.is_valid (nth_visit r n)) (run_reachable2 r W (nth_visit r n)) (is_fair_at_nth_visit r n r_fair) |
| 66 | + have yu := W.rank_le_of_rel_unfair (r.f (nth_visit r n)) (r.f (nth_visit r (n) + 1)) (r.is_valid (nth_visit r n)) |
| 67 | + |
| 68 | + simp only [is_fair_at_nth_visit r n r_fair, ↓reduceIte, Ordinal.add_one_eq_succ, |
| 69 | + Order.succ_le_iff] at yf |
| 70 | + exact LE.le.trans_lt (by |
| 71 | + apply rank_antitone |
| 72 | + omega) yf) |
| 73 | + |
| 74 | +/-- The comparison of ranks in the `ordSeq` is equivalent to the reversed comparison of their indices. |
| 75 | +This is a property of strictly antitone sequences. |
| 76 | +For $m, n \in \mathbb{N}$, $W(r.f(\text{nth_visit}(r, m))) < W(r.f(\text{nth_visit}(r, n))) \iff n < m$. -/ |
| 77 | +theorem ordSeq_lt_iff_lt (r_fair : r.IsFair) {m n : ℕ} : ordSeq r W m < ordSeq r W n ↔ n < m := StrictAnti.lt_iff_lt (ordSeq_strict_anti r W r_fair) |
| 78 | + |
| 79 | + |
| 80 | +/- |
| 81 | +If `a` has no fair runs, then `stateSucceeds a` is well-founded. |
| 82 | +-/ |
| 83 | +theorem succeeds_wf (a : Automaton S) (fe : a.IsFairEmpty) : WellFounded (stateSucceeds a) := by |
| 84 | + simp only [WellFounded.wellFounded_iff_no_descending_seq] |
| 85 | + by_contra c |
| 86 | + simp only [not_isEmpty_iff, nonempty_subtype] at c |
| 87 | + rcases c with ⟨s, y⟩ |
| 88 | + exact fe (vardiRun s y) (vardiRun_fair s y) |
| 89 | + |
| 90 | + |
| 91 | +/- |
| 92 | +Provide the `IsWellFounded` instance for `stateSucceeds` from `succeeds_wf`. |
| 93 | +-/ |
| 94 | +instance n {S : Type} (a : Automaton S) (fe : a.IsFairEmpty) : IsWellFounded S (stateSucceeds a) where |
| 95 | + wf := succeeds_wf a fe |
| 96 | + |
| 97 | +/-- The main theorem for ordinal-valued ranking functions. |
| 98 | +If an ordinal-valued ranking function `W` exists for an automaton `a`, then `a` has no fair runs. |
| 99 | +This is proven by showing that a fair run would imply an infinite decreasing sequence of ordinals, which is impossible. -/ |
| 100 | +theorem isFairEmpty_of_ordinalRankingFunction (W : OrdinalRankingFunction A a) : a.IsFairEmpty := fun r r_fair => |
| 101 | + (RelEmbedding.not_wellFounded_of_decreasing_seq ⟨⟨ordSeq r W, |
| 102 | + StrictAnti.injective (ordSeq_strict_anti r W r_fair) |
| 103 | + ⟩, by |
| 104 | + intros m n |
| 105 | + simp only [Function.Embedding.coeFn_mk, gt_iff_lt] |
| 106 | + exact ordSeq_lt_iff_lt r W r_fair⟩) (wellFounded_lt) |
| 107 | + |
| 108 | +#print axioms isFairEmpty_of_ordinalRankingFunction |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +/- |
| 113 | +Completeness: construct an ordinal ranking from emptiness of fair runs. |
| 114 | +
|
| 115 | +Given `fe : a.IsFairEmpty`, the relation `stateSucceeds a` is well-founded, and we |
| 116 | +define `W` to be the `WellFounded.rank` on this relation. This yields an |
| 117 | +`OrdinalRankingFunction a` whose rank strictly decreases on fair steps and never |
| 118 | +increases otherwise. In particular, for every transition `s1 → s2` we have |
| 119 | +$$ |
| 120 | + W(s_2) + \mathbb{I}(s_1 \in F) \le W(s_1), |
| 121 | +$$ |
| 122 | +where `\mathbb{I}` is the indicator of fairness. This is the converse direction |
| 123 | +to `isFairEmpty_of_ordinalRankingFunction`. |
| 124 | +-/ |
| 125 | +noncomputable def ordinalRankingFunction_of_isFairEmpty (fe : a.IsFairEmpty) : (OrdinalRankingFunction (Ordinal.{0}) a) := { |
| 126 | + reach := fun s => State.IsReachable (a := a) s, |
| 127 | + init_reach := init_reachable, |
| 128 | + next_reach := next_reachable, |
| 129 | + rank := @IsWellFounded.rank S (stateSucceeds a) (n a fe), |
| 130 | + rank_le_of_rel_fair := fun s1 s2 rel => by |
| 131 | + intro s1_reachable s1_fair |
| 132 | + apply IsWellFounded.rank_lt_of_rel (hwf := n a fe) |
| 133 | + rcases s1_reachable with ⟨i, i_to_s1, i_initial⟩ |
| 134 | + use s1, i |
| 135 | + simp only [i_initial, i_to_s1, s1_fair, true_and] |
| 136 | + rw [Relation.ReflTransGen.cases_head_iff, Relation.transGen_iff] |
| 137 | + simp only [true_or, rel, and_self] |
| 138 | + , |
| 139 | + rank_le_of_rel_unfair := by |
| 140 | + intros s1 s2 s1_r_s2 s1_reachable |
| 141 | + by_contra c |
| 142 | + simp only [not_le] at c |
| 143 | + repeat rw [IsWellFounded.rank_eq] at c |
| 144 | + have : sSup (Set.range fun (b : { b // stateSucceeds a b s2 }) ↦ Order.succ (IsWellFounded.rank (hwf := n a fe) (stateSucceeds a) ↑b)) ≤ sSup (Set.range fun (b : { b // stateSucceeds a b s1 }) ↦ Order.succ (IsWellFounded.rank (hwf := n a fe) (stateSucceeds a) ↑b)) := csSup_le_csSup (by |
| 145 | + simp only [BddAbove, Set.Nonempty, upperBounds, Set.mem_range, Subtype.exists, exists_prop, |
| 146 | + forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Order.succ_le_iff, Set.mem_setOf_eq] |
| 147 | + use IsWellFounded.rank (hwf := n a fe) (stateSucceeds a) s1 |
| 148 | + intros s3 |
| 149 | + exact IsWellFounded.rank_lt_of_rel (hwf := n a fe)) |
| 150 | + (by |
| 151 | + by_cases n : (∃ (f : S), stateSucceeds a f s2 ) |
| 152 | + · rcases n with ⟨f, f_suc_s2 ⟩ |
| 153 | + apply Set.range_nonempty (ι := { b // stateSucceeds a b s2 }) (h := by use f) |
| 154 | + · simp only [not_exists] at n |
| 155 | + have : IsEmpty { b // stateSucceeds a b s2 } := ⟨ fun ⟨ a, a_succ ⟩ => n a a_succ⟩ |
| 156 | + simp only [ciSup_of_empty, Ordinal.bot_eq_zero, Ordinal.not_lt_zero] at c |
| 157 | + ) |
| 158 | + (by |
| 159 | + intro s s_in_b |
| 160 | + simp only [Set.mem_range, Subtype.exists, exists_prop] at s_in_b |
| 161 | + rcases s_in_b with ⟨ n, n_suc_s2, ord_suc⟩ |
| 162 | + simp only [Set.mem_range, Subtype.exists, exists_prop] |
| 163 | + use n |
| 164 | + simp only [ord_suc, and_true] |
| 165 | + exact succeeds_concat4 s1 s2 n a s1_r_s2 n_suc_s2 s1_reachable |
| 166 | + ) |
| 167 | + have := LT.lt.not_ge c |
| 168 | + contradiction |
| 169 | + } |
| 170 | + |
| 171 | +--info: 'ordinalRankingFunction_of_isFairEmpty' depends on axioms: [propext, Classical.choice, Quot.sound] |
| 172 | +#print axioms ordinalRankingFunction_of_isFairEmpty |
0 commit comments