|
67 | 67 | -- ∧ trace.last ≡ x ∧ f x ≡ y`. The current `EchoS` projects from |
68 | 68 | -- that by collapsing the trace to its terminal index. |
69 | 69 | -- |
70 | | --- * A *bounded-search-is-decidable* lemma in the presence of |
71 | | --- decidable equality on `B`: search up to `n` either yields an |
| 70 | +-- * (LANDED) A *bounded-search-is-decidable* lemma in the presence |
| 71 | +-- of decidable equality on `B`: search up to `n` either yields an |
72 | 72 | -- `EchoS enum f y n` or proves `¬ EchoS enum f y n`. This is the |
73 | | --- concrete bridge to `EchoDecidable`, kept as a separate slice |
74 | | --- because it needs a `_≟_` on `B` and a finite-walk recursion. |
| 73 | +-- concrete bridge to `EchoDecidable`; it needs a `_≟_` on `B` and a |
| 74 | +-- finite-walk recursion on the budget. See `bounded-search-is-decidable` |
| 75 | +-- at the bottom of this module. |
75 | 76 |
|
76 | 77 | module EchoSearch where |
77 | 78 |
|
78 | 79 | open import Function.Base using (_∘_; id) |
79 | 80 | open import Data.Nat.Base using (ℕ; zero; suc; _≤_; _<_; z≤n; s≤s) |
80 | | -open import Data.Nat.Properties using (≤-<-trans; <-≤-trans) |
| 81 | +open import Data.Nat.Properties |
| 82 | + using (≤-<-trans; <-≤-trans; <-cmp; <-trans; ≤-trans; ≤-refl; <-irrefl) |
81 | 83 | open import Data.Empty using (⊥; ⊥-elim) |
82 | 84 | open import Data.Product.Base using (Σ; _,_; _×_; proj₁; proj₂) |
83 | | -open import Relation.Nullary using (¬_) |
| 85 | +open import Relation.Nullary using (¬_; Dec; yes; no) |
| 86 | +open import Relation.Binary.Definitions using (Tri; tri<; tri≈; tri>) |
84 | 87 | open import Relation.Binary.PropositionalEquality |
85 | 88 | using (_≡_; refl; sym; trans; cong) |
86 | 89 |
|
@@ -156,3 +159,38 @@ echo-search-postcompose : |
156 | 159 | EchoS enum f y n → EchoS enum (g ∘ f) (g y) n |
157 | 160 | echo-search-postcompose enum f g (k , k<n , eq) = |
158 | 161 | k , k<n , cong g eq |
| 162 | + |
| 163 | +---------------------------------------------------------------------- |
| 164 | +-- Decidability bridge |
| 165 | +---------------------------------------------------------------------- |
| 166 | + |
| 167 | +-- Bounded search is decidable under decidable equality on the codomain. |
| 168 | +-- Because `EchoS enum f y n` is exactly the bounded existential |
| 169 | +-- `Σ k. (k < n) × (f (enum k) ≡ y)`, searching up to the budget `n` |
| 170 | +-- either produces a bound-`n` search echo or refutes one. This is the |
| 171 | +-- concrete bridge from EchoSearch to `EchoDecidable` (axis 8(3)): no |
| 172 | +-- machine model is required, only the step budget and a `_≟_` on `B`. |
| 173 | +-- Structural recursion on `n`; the `suc` step tests the new index `n` |
| 174 | +-- and otherwise recurses, using trichotomy to refute every index below |
| 175 | +-- `suc n` in the negative case. |
| 176 | +bounded-search-is-decidable : |
| 177 | + ∀ {a b} {A : Set a} {B : Set b} |
| 178 | + (_≟_ : (x y : B) → Dec (x ≡ y)) |
| 179 | + (enum : SearchStrategy A) (f : A → B) (y : B) (n : ℕ) → |
| 180 | + Dec (EchoS enum f y n) |
| 181 | +bounded-search-is-decidable _≟_ enum f y zero = |
| 182 | + no (echo-search-bound-zero enum f y) |
| 183 | +bounded-search-is-decidable _≟_ enum f y (suc n) with f (enum n) ≟ y |
| 184 | +... | yes eq = yes (n , ≤-refl , eq) |
| 185 | +... | no ¬eq with bounded-search-is-decidable _≟_ enum f y n |
| 186 | +... | yes (k , k<n , eqk) = yes (k , <-trans k<n ≤-refl , eqk) |
| 187 | +... | no ¬below = no λ { (k , k<1+n , eqk) → contra k k<1+n eqk } |
| 188 | + where |
| 189 | + -- No index below `suc n` can witness `y`: indices below `n` are |
| 190 | + -- refuted by `¬below`, the index `n` itself by `¬eq`, and there is |
| 191 | + -- no index strictly between `n` and `suc n`. |
| 192 | + contra : ∀ k → k < suc n → f (enum k) ≡ y → ⊥ |
| 193 | + contra k (s≤s k≤n) eqk with <-cmp k n |
| 194 | + ... | tri< k<n _ _ = ¬below (k , k<n , eqk) |
| 195 | + ... | tri≈ _ k≡n _ = ¬eq (trans (sym (cong (λ j → f (enum j)) k≡n)) eqk) |
| 196 | + ... | tri> _ _ n<k = <-irrefl refl (≤-trans n<k k≤n) |
0 commit comments