introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.65 kB
import OAI.Computability.SpaceSimulation.Register.Arithmetic
namespace OAI
namespace Fifths
namespace Scan
def all (p : β„• β†’ Bool) : β„• β†’ Bool
| 0 => true
| n+1 => all p n && p n
theorem all_iff (p : β„• β†’ Bool) (n) : all p n = true ↔ βˆ€ j < n, p j = true := by
induction n with
| zero => simp [all]
| succ n ih =>
rw [all, Bool.and_eq_true, ih]
constructor
· rintro ⟨a,b⟩ j l
by_cases e : j < n
Β· exact a _ e
Β· rw [show j = n by omega]
exact b
· exact fun a => ⟨fun j e => a _ (by omega), a n (by omega)⟩
def pick (p : β„• β†’ Bool) : β„• β†’ β„•
| 0 => 0
| n+1 => if p n then n else pick p n
theorem pick_le (p : β„• β†’ Bool) (n) : pick p n ≀ n := by
induction n with
| zero => rfl
| succ n ih => simp only [pick]; split <;> omega
theorem pick_spec (p : β„• β†’ Bool) (n) (e : βˆƒ j < n, p j = true) :
pick p n < n ∧ p (pick p n) = true := by
induction n with
| zero => simp at e
| succ n ih =>
unfold pick
split
next h => exact ⟨by omega,h⟩
next h =>
suffices g : βˆƒ j < n, p j = true from ⟨by have := (ih g).1; omega,(ih g).2⟩
obtain ⟨j,a,b⟩ := e
refine ⟨j,?_,b⟩
by_contra! v
have l : j = n := by omega
subst j
contradiction
end Scan
namespace Comp
variable {X I : Type} {x : I β†’ List X} {S a b : I β†’ β„•}
theorem scanAll (p : I β†’ β„• β†’ Bool) (q : Comp x S a b)
(h : βˆ€ e : Before b β†’ β„•, Comp (fun i => x i.1.1) (fun i => S i.1.1) e
(fun i => a i.1.1) β†’ Comp (fun i => x i.1.1) (fun i => S i.1.1) e (fun i => i.1.2)
β†’ Comp (fun i => x i.1.1) (fun i => S i.1.1) e
(fun i => (p i.1.1 i.1.2).toNat)) :
Comp x S a (fun i => (Scan.all (p i) (b i)).toNat) := by
apply fold (fun i j => (Scan.all (p i) j).toNat) q
(Comp.constant q.source 1)
Β· exact (Fits.const _ 1).mono (fun _ => Bool.toNat_le _)
Β· intro e i j r
exact r.both (h e i j)
theorem scanPick (p : I β†’ β„• β†’ Bool) (q : Comp x S a b)
(h : βˆ€ e : Before b β†’ β„•, Comp (fun i => x i.1.1) (fun i => S i.1.1) e
(fun i => a i.1.1) β†’ Comp (fun i => x i.1.1) (fun i => S i.1.1) e (fun i => i.1.2)
β†’ Comp (fun i => x i.1.1) (fun i => S i.1.1) e
(fun i => (p i.1.1 i.1.2).toNat)) :
Comp x S a (fun i => Scan.pick (p i) (b i)) := by
apply fold (fun i j => Scan.pick (p i) j) q
(Comp.constant q.source 0)
Β· let f : Through b β†’ I := fun i => i.1.1
exact (q.target.pull f).mono (fun i => (Scan.pick_le _ _).trans i.2)
Β· intro e i j r
exact (h e i j).iteB j r
end Comp
end Fifths
end OAI