fact stringlengths 6 3.84k | type stringclasses 11 values | library stringclasses 32 values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
stepSet (S : Set σ) (a : α) : Set σ :=
⋃ s ∈ S, M.εClosure (M.step s a)
variable {M}
@[simp] | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | stepSet | `M.stepSet S a` is the union of the ε-closure of `M.step s a` for all `s ∈ S`. |
mem_stepSet_iff : s ∈ M.stepSet S a ↔ ∃ t ∈ S, s ∈ M.εClosure (M.step t a) := by
simp_rw [stepSet, mem_iUnion₂, exists_prop]
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | mem_stepSet_iff | null |
stepSet_empty (a : α) : M.stepSet ∅ a = ∅ := by
simp_rw [stepSet, mem_empty_iff_false, iUnion_false, iUnion_empty]
variable (M) | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | stepSet_empty | null |
evalFrom (start : Set σ) : List α → Set σ :=
List.foldl M.stepSet (M.εClosure start)
@[simp] | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | evalFrom | `M.evalFrom S x` computes all possible paths through `M` with input `x` starting at an element
of `S`. |
evalFrom_nil (S : Set σ) : M.evalFrom S [] = M.εClosure S :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | evalFrom_nil | null |
evalFrom_singleton (S : Set σ) (a : α) : M.evalFrom S [a] = M.stepSet (M.εClosure S) a :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | evalFrom_singleton | null |
evalFrom_append_singleton (S : Set σ) (x : List α) (a : α) :
M.evalFrom S (x ++ [a]) = M.stepSet (M.evalFrom S x) a := by
rw [evalFrom, List.foldl_append, List.foldl_cons, List.foldl_nil]
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | evalFrom_append_singleton | null |
evalFrom_empty (x : List α) : M.evalFrom ∅ x = ∅ := by
induction x using List.reverseRecOn with
| nil => rw [evalFrom_nil, εClosure_empty]
| append_singleton x a ih => rw [evalFrom_append_singleton, ih, stepSet_empty] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | evalFrom_empty | null |
mem_evalFrom_iff_exists {s : σ} {S : Set σ} {x : List α} :
s ∈ M.evalFrom S x ↔ ∃ t ∈ S, s ∈ M.evalFrom {t} x := by
induction x using List.reverseRecOn generalizing s with
| nil => apply mem_εClosure_iff_exists
| append_singleton _ _ ih =>
simp_rw [evalFrom_append_singleton, mem_stepSet_iff, ih]
tauto | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | mem_evalFrom_iff_exists | null |
eval :=
M.evalFrom M.start
@[simp] | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | eval | `M.eval x` computes all possible paths through `M` with input `x` starting at an element of
`M.start`. |
eval_nil : M.eval [] = M.εClosure M.start :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | eval_nil | null |
eval_singleton (a : α) : M.eval [a] = M.stepSet (M.εClosure M.start) a :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | eval_singleton | null |
eval_append_singleton (x : List α) (a : α) : M.eval (x ++ [a]) = M.stepSet (M.eval x) a :=
evalFrom_append_singleton _ _ _ _ | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | eval_append_singleton | null |
accepts : Language α :=
{ x | ∃ S ∈ M.accept, S ∈ M.eval x } | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | accepts | `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. |
@[mk_iff]
IsPath : σ → σ → List (Option α) → Prop
| nil (s : σ) : IsPath s s []
| cons (t s u : σ) (a : Option α) (x : List (Option α)) :
t ∈ M.step s a → IsPath t u x → IsPath s u (a :: x)
@[simp] | inductive | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | IsPath | `M.IsPath` represents a traversal in `M` from a start state to an end state by following a list
of transitions in order. |
isPath_nil : M.IsPath s t [] ↔ s = t := by
rw [isPath_iff]
simp [eq_comm]
alias ⟨IsPath.eq_of_nil, _⟩ := isPath_nil
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | isPath_nil | null |
isPath_singleton {a : Option α} : M.IsPath s t [a] ↔ t ∈ M.step s a where
mp := by
rintro (_ | ⟨_, _, _, _, _, _, ⟨⟩⟩)
assumption
mpr := by tauto
alias ⟨_, IsPath.singleton⟩ := isPath_singleton | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | isPath_singleton | null |
isPath_append {x y : List (Option α)} :
M.IsPath s u (x ++ y) ↔ ∃ t, M.IsPath s t x ∧ M.IsPath t u y where
mp := by
induction x generalizing s with
| nil =>
rw [List.nil_append]
tauto
| cons x a ih =>
rintro (_ | ⟨t, _, _, _, _, _, h⟩)
apply ih at h
tauto
mpr := by
intro ⟨t, hx, _⟩
induction x generalizing s <;> cases hx <;> tauto | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | isPath_append | null |
mem_εClosure_iff_exists_path {s₁ s₂ : σ} :
s₂ ∈ M.εClosure {s₁} ↔ ∃ n, M.IsPath s₁ s₂ (.replicate n none) where
mp h := by
induction h with
| base t =>
use 0
subst t
apply IsPath.nil
| step _ _ _ _ ih =>
obtain ⟨n, _⟩ := ih
use n + 1
rw [List.replicate_add, isPath_append]
tauto
mpr := by
intro ⟨n, h⟩
induction n generalizing s₂
· rw [List.replicate_zero] at h
apply IsPath.eq_of_nil at h
solve_by_elim
· simp_rw [List.replicate_add, isPath_append, List.replicate_one, isPath_singleton] at h
obtain ⟨t, _, _⟩ := h
solve_by_elim [εClosure.step] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | mem_εClosure_iff_exists_path | null |
mem_evalFrom_iff_exists_path {s₁ s₂ : σ} {x : List α} :
s₂ ∈ M.evalFrom {s₁} x ↔ ∃ x', x'.reduceOption = x ∧ M.IsPath s₁ s₂ x' := by
induction x using List.reverseRecOn generalizing s₂ with
| nil =>
rw [evalFrom_nil, mem_εClosure_iff_exists_path]
constructor
· intro ⟨n, _⟩
use List.replicate n none
rw [List.reduceOption_replicate_none]
trivial
· simp_rw [List.reduceOption_eq_nil_iff]
intro ⟨_, ⟨n, rfl⟩, h⟩
exact ⟨n, h⟩
| append_singleton x a ih =>
rw [evalFrom_append_singleton, mem_stepSet_iff]
constructor
· intro ⟨t, ht, h⟩
obtain ⟨x', _, _⟩ := ih.mp ht
rw [mem_εClosure_iff_exists] at h
simp_rw [mem_εClosure_iff_exists_path] at h
obtain ⟨u, _, n, _⟩ := h
use x' ++ some a :: List.replicate n none
rw [List.reduceOption_append, List.reduceOption_cons_of_some,
List.reduceOption_replicate_none, isPath_append]
tauto
· simp_rw [← List.concat_eq_append, List.reduceOption_eq_concat_iff,
List.reduceOption_eq_nil_iff]
intro ⟨_, ⟨x', _, rfl, _, n, rfl⟩, h⟩
rw [isPath_append] at h
obtain ⟨t, _, _ | u⟩ := h
use t
rw [mem_εClosure_iff_exists, ih]
simp_rw [mem_εClosure_iff_exists_path]
tauto | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | mem_evalFrom_iff_exists_path | null |
mem_accepts_iff_exists_path {x : List α} :
x ∈ M.accepts ↔
∃ s₁ s₂ x', s₁ ∈ M.start ∧ s₂ ∈ M.accept ∧ x'.reduceOption = x ∧ M.IsPath s₁ s₂ x' where
mp := by
intro ⟨s₂, _, h⟩
rw [eval, mem_evalFrom_iff_exists] at h
obtain ⟨s₁, _, h⟩ := h
rw [mem_evalFrom_iff_exists_path] at h
tauto
mpr := by
intro ⟨s₁, s₂, x', hs₁, hs₂, h⟩
have := M.mem_evalFrom_iff_exists.mpr ⟨_, hs₁, M.mem_evalFrom_iff_exists_path.mpr ⟨_, h⟩⟩
exact ⟨s₂, hs₂, this⟩
/-! ### Conversions between `εNFA` and `NFA` -/ | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | mem_accepts_iff_exists_path | null |
toNFA : NFA α σ where
step S a := M.εClosure (M.step S a)
start := M.εClosure M.start
accept := M.accept
@[simp] | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toNFA | `M.toNFA` is an `NFA` constructed from an `εNFA` `M`. |
toNFA_evalFrom_match (start : Set σ) :
M.toNFA.evalFrom (M.εClosure start) = M.evalFrom start :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toNFA_evalFrom_match | null |
toNFA_correct : M.toNFA.accepts = M.accepts :=
rfl | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toNFA_correct | null |
pumping_lemma [Fintype σ] {x : List α} (hx : x ∈ M.accepts)
(hlen : Fintype.card (Set σ) ≤ List.length x) :
∃ a b c, x = a ++ b ++ c ∧
a.length + b.length ≤ Fintype.card (Set σ) ∧ b ≠ [] ∧ {a} * {b}∗ * {c} ≤ M.accepts :=
M.toNFA.pumping_lemma hx hlen | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | pumping_lemma | null |
toεNFA (M : NFA α σ) : εNFA α σ where
step s a := a.casesOn' ∅ fun a ↦ M.step s a
start := M.start
accept := M.accept
@[simp] | def | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toεNFA | `M.toεNFA` is an `εNFA` constructed from an `NFA` `M` by using the same start and accept
states and transition functions. |
toεNFA_εClosure (M : NFA α σ) (S : Set σ) : M.toεNFA.εClosure S = S := by
ext a
refine ⟨?_, εNFA.εClosure.base _⟩
rintro (⟨_, h⟩ | ⟨_, _, h, _⟩)
· exact h
· cases h
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toεNFA_εClosure | null |
toεNFA_evalFrom_match (M : NFA α σ) (start : Set σ) :
M.toεNFA.evalFrom start = M.evalFrom start := by
rw [evalFrom, εNFA.evalFrom, toεNFA_εClosure]
suffices εNFA.stepSet (toεNFA M) = stepSet M by rw [this]
ext S s
simp only [stepSet, εNFA.stepSet, exists_prop, Set.mem_iUnion]
apply exists_congr
simp only [and_congr_right_iff]
intro _ _
rw [M.toεNFA_εClosure]
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toεNFA_evalFrom_match | null |
toεNFA_correct (M : NFA α σ) : M.toεNFA.accepts = M.accepts := by
rw [εNFA.accepts, εNFA.eval, toεNFA_evalFrom_match]
rfl | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | toεNFA_correct | null |
@[simp]
step_zero (s a) : (0 : εNFA α σ).step s a = ∅ :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | step_zero | null |
step_one (s a) : (1 : εNFA α σ).step s a = ∅ :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | step_one | null |
start_zero : (0 : εNFA α σ).start = ∅ :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | start_zero | null |
start_one : (1 : εNFA α σ).start = univ :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | start_one | null |
accept_zero : (0 : εNFA α σ).accept = ∅ :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | accept_zero | null |
accept_one : (1 : εNFA α σ).accept = univ :=
rfl | theorem | Computability | [
"Mathlib.Computability.NFA",
"Mathlib.Data.List.ReduceOption"
] | Mathlib/Computability/EpsilonNFA.lean | accept_one | null |
merge' {f g} (hf : Nat.Partrec f) (hg : Nat.Partrec g) :
∃ h, Nat.Partrec h ∧
∀ a, (∀ x ∈ h a, x ∈ f a ∨ x ∈ g a) ∧ ((h a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by
obtain ⟨cf, rfl⟩ := Code.exists_code.1 hf
obtain ⟨cg, rfl⟩ := Code.exists_code.1 hg
have : Nat.Partrec fun n => Nat.rfindOpt fun k => cf.evaln k n <|> cg.evaln k n :=
Partrec.nat_iff.1
(Partrec.rfindOpt <|
Primrec.option_orElse.to_comp.comp
(Code.primrec_evaln.to_comp.comp <| (snd.pair (const cf)).pair fst)
(Code.primrec_evaln.to_comp.comp <| (snd.pair (const cg)).pair fst))
refine ⟨_, this, fun n => ?_⟩
have : ∀ x ∈ rfindOpt fun k ↦ HOrElse.hOrElse (Code.evaln k cf n) fun _x ↦ Code.evaln k cg n,
x ∈ Code.eval cf n ∨ x ∈ Code.eval cg n := by
intro x h
obtain ⟨k, e⟩ := Nat.rfindOpt_spec h
revert e
simp only [Option.mem_def]
rcases e' : cf.evaln k n with - | y <;> simp <;> intro e
· exact Or.inr (Code.evaln_sound e)
· subst y
exact Or.inl (Code.evaln_sound e')
refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩
intro h
rw [Nat.rfindOpt_dom]
simp only [dom_iff_mem, Code.evaln_complete, Option.mem_def] at h
obtain ⟨x, k, e⟩ | ⟨x, k, e⟩ := h
· refine ⟨k, x, ?_⟩
simp only [e, Option.orElse_some, Option.mem_def, Option.orElse_eq_orElse]
· refine ⟨k, ?_⟩
rcases cf.evaln k n with - | y
· exact ⟨x, by simp only [e, Option.mem_def, Option.orElse_eq_orElse, Option.orElse_none]⟩
· exact ⟨y, by simp only [Option.orElse_eq_orElse, Option.orElse_some, Option.mem_def]⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | merge' | null |
merge' {f g : α →. σ} (hf : Partrec f) (hg : Partrec g) :
∃ k : α →. σ,
Partrec k ∧ ∀ a, (∀ x ∈ k a, x ∈ f a ∨ x ∈ g a) ∧ ((k a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by
let ⟨k, hk, H⟩ := Nat.Partrec.merge' (bind_decode₂_iff.1 hf) (bind_decode₂_iff.1 hg)
let k' (a : α) := (k (encode a)).bind fun n => (decode (α := σ) n : Part σ)
refine
⟨k', ((nat_iff.2 hk).comp Computable.encode).bind (Computable.decode.ofOption.comp snd).to₂,
fun a => ?_⟩
have : ∀ x ∈ k' a, x ∈ f a ∨ x ∈ g a := by
intro x h'
simp only [k', mem_coe, mem_bind_iff, Option.mem_def] at h'
obtain ⟨n, hn, hx⟩ := h'
have := (H _).1 _ hn
simp only [decode₂_encode, coe_some, bind_some, mem_map_iff] at this
obtain ⟨a', ha, rfl⟩ | ⟨a', ha, rfl⟩ := this <;> simp only [encodek, Option.some_inj] at hx <;>
rw [hx] at ha
· exact Or.inl ha
· exact Or.inr ha
refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩
intro h
rw [bind_dom]
have hk : (k (encode a)).Dom :=
(H _).2.2 (by simpa only [encodek₂, bind_some, coe_some] using h)
exists hk
simp only [mem_map_iff, mem_coe, mem_bind_iff, Option.mem_def] at H
obtain ⟨a', _, y, _, e⟩ | ⟨a', _, y, _, e⟩ := (H _).1 _ ⟨hk, rfl⟩ <;>
simp only [e.symm, encodek, coe_some, some_dom] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | merge' | null |
merge {f g : α →. σ} (hf : Partrec f) (hg : Partrec g)
(H : ∀ (a), ∀ x ∈ f a, ∀ y ∈ g a, x = y) :
∃ k : α →. σ, Partrec k ∧ ∀ a x, x ∈ k a ↔ x ∈ f a ∨ x ∈ g a :=
let ⟨k, hk, K⟩ := merge' hf hg
⟨k, hk, fun a x =>
⟨(K _).1 _, fun h => by
have : (k a).Dom := (K _).2.2 (h.imp Exists.fst Exists.fst)
refine ⟨this, ?_⟩
rcases h with h | h <;> rcases (K _).1 _ ⟨this, rfl⟩ with h' | h'
· exact mem_unique h' h
· exact (H _ _ h _ h').symm
· exact H _ _ h' _ h
· exact mem_unique h' h⟩⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | merge | null |
cond {c : α → Bool} {f : α →. σ} {g : α →. σ} (hc : Computable c) (hf : Partrec f)
(hg : Partrec g) : Partrec fun a => cond (c a) (f a) (g a) :=
let ⟨cf, ef⟩ := exists_code.1 hf
let ⟨cg, eg⟩ := exists_code.1 hg
((eval_part.comp (Computable.cond hc (const cf) (const cg)) Computable.encode).bind
((@Computable.decode σ _).comp snd).ofOption.to₂).of_eq
fun a => by cases c a <;> simp [ef, eg, encodek]
nonrec theorem sumCasesOn {f : α → β ⊕ γ} {g : α → β →. σ} {h : α → γ →. σ} (hf : Computable f)
(hg : Partrec₂ g) (hh : Partrec₂ h) : @Partrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) :=
option_some_iff.1 <|
(cond (sumCasesOn hf (const true).to₂ (const false).to₂)
(sumCasesOn_left hf (option_some_iff.2 hg).to₂ (const Option.none).to₂)
(sumCasesOn_right hf (const Option.none).to₂ (option_some_iff.2 hh).to₂)).of_eq
fun a => by cases f a <;> simp only [Bool.cond_true, Bool.cond_false] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | cond | null |
ComputablePred {α} [Primcodable α] (p : α → Prop) :=
∃ (_ : DecidablePred p), Computable fun a => decide (p a) | def | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | ComputablePred | A computable predicate is one whose indicator function is computable. |
protected ComputablePred.decide {p : α → Prop} [DecidablePred p] (hp : ComputablePred p) :
Computable (fun a => decide (p a)) := by
convert hp.choose_spec | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | ComputablePred.decide | null |
Computable.computablePred {p : α → Prop} [DecidablePred p]
(hp : Computable (fun a => decide (p a))) : ComputablePred p :=
⟨inferInstance, hp⟩ | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | Computable.computablePred | null |
computablePred_iff_computable_decide {p : α → Prop} [DecidablePred p] :
ComputablePred p ↔ Computable (fun a => decide (p a)) where
mp := ComputablePred.decide
mpr := Computable.computablePred | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | computablePred_iff_computable_decide | null |
PrimrecPred.computablePred {α} [Primcodable α] {p : α → Prop} :
(hp : PrimrecPred p) → ComputablePred p
| ⟨_, hp⟩ => hp.to_comp.computablePred | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | PrimrecPred.computablePred | null |
REPred {α} [Primcodable α] (p : α → Prop) :=
Partrec fun a => Part.assert (p a) fun _ => Part.some () | def | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | REPred | A recursively enumerable predicate is one which is the domain of a computable partial function. |
REPred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : REPred p) (H : ∀ a, p a ↔ q a) :
REPred q :=
(funext fun a => propext (H a) : p = q) ▸ hp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | REPred.of_eq | null |
Partrec.dom_re {α β} [Primcodable α] [Primcodable β] {f : α →. β} (h : Partrec f) :
REPred fun a => (f a).Dom :=
(h.map (Computable.const ()).to₂).of_eq fun n => Part.ext fun _ => by simp [Part.dom_iff_mem] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | Partrec.dom_re | null |
ComputablePred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : ComputablePred p)
(H : ∀ a, p a ↔ q a) : ComputablePred q :=
(funext fun a => propext (H a) : p = q) ▸ hp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | ComputablePred.of_eq | null |
computable_iff {p : α → Prop} :
ComputablePred p ↔ ∃ f : α → Bool, Computable f ∧ p = fun a => (f a : Prop) :=
⟨fun ⟨_, h⟩ => ⟨_, h, funext fun _ => propext (Bool.decide_iff _).symm⟩, by
rintro ⟨f, h, rfl⟩; exact ⟨by infer_instance, by simpa using h⟩⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | computable_iff | null |
protected not {p : α → Prop} :
(hp : ComputablePred p) → ComputablePred fun a => ¬p a
| ⟨_, hp⟩ => Computable.computablePred <| Primrec.not.to_comp.comp hp |>.of_eq <| by simp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | not | null |
ite {f₁ f₂ : ℕ → ℕ} (hf₁ : Computable f₁) (hf₂ : Computable f₂)
{c : ℕ → Prop} [DecidablePred c] (hc : ComputablePred c) :
Computable fun k ↦ if c k then f₁ k else f₂ k := by
simpa [Bool.cond_decide] using hc.decide.cond hf₁ hf₂ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | ite | The computable functions are closed under if-then-else definitions
with computable predicates. |
to_re {p : α → Prop} (hp : ComputablePred p) : REPred p := by
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp
unfold REPred
dsimp only []
refine
(Partrec.cond hf (Decidable.Partrec.const' (Part.some ())) Partrec.none).of_eq fun n =>
Part.ext fun a => ?_
cases a; cases f n <;> simp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | to_re | null |
rice (C : Set (ℕ →. ℕ)) (h : ComputablePred fun c => eval c ∈ C) {f g} (hf : Nat.Partrec f)
(hg : Nat.Partrec g) (fC : f ∈ C) : g ∈ C := by
obtain ⟨_, h⟩ := h
obtain ⟨c, e⟩ :=
fixed_point₂
(Partrec.cond (h.comp fst) ((Partrec.nat_iff.2 hg).comp snd).to₂
((Partrec.nat_iff.2 hf).comp snd).to₂).to₂
simp only [Bool.cond_decide] at e
by_cases H : eval c ∈ C
· simp only [H, if_true] at e
change (fun b => g b) ∈ C
rwa [← e]
· simp only [H, if_false] at e
rw [e] at H
contradiction | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | rice | **Rice's Theorem** |
rice₂ (C : Set Code) (H : ∀ cf cg, eval cf = eval cg → (cf ∈ C ↔ cg ∈ C)) :
(ComputablePred fun c => c ∈ C) ↔ C = ∅ ∨ C = Set.univ := by
classical exact
have hC : ∀ f, f ∈ C ↔ eval f ∈ eval '' C := fun f =>
⟨Set.mem_image_of_mem _, fun ⟨g, hg, e⟩ => (H _ _ e).1 hg⟩
⟨fun h =>
or_iff_not_imp_left.2 fun C0 =>
Set.eq_univ_of_forall fun cg =>
let ⟨cf, fC⟩ := Set.nonempty_iff_ne_empty.2 C0
(hC _).2 <|
rice (eval '' C) (h.of_eq hC)
(Partrec.nat_iff.1 <| eval_part.comp (const cf) Computable.id)
(Partrec.nat_iff.1 <| eval_part.comp (const cg) Computable.id) ((hC _).1 fC),
fun h => by {
obtain rfl | rfl := h <;> simpa [ComputablePred, Set.mem_empty_iff_false] using
Computable.const _}⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | rice₂ | null |
halting_problem_re (n) : REPred fun c => (eval c n).Dom :=
(eval_part.comp Computable.id (Computable.const _)).dom_re | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | halting_problem_re | The Halting problem is recursively enumerable |
halting_problem (n) : ¬ComputablePred fun c => (eval c n).Dom
| h => rice { f | (f n).Dom } h Nat.Partrec.zero Nat.Partrec.none trivial | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | halting_problem | The **Halting problem** is not computable |
computable_iff_re_compl_re {p : α → Prop} [DecidablePred p] :
ComputablePred p ↔ REPred p ∧ REPred fun a => ¬p a :=
⟨fun h => ⟨h.to_re, h.not.to_re⟩, fun ⟨h₁, h₂⟩ =>
⟨‹_›, by
obtain ⟨k, pk, hk⟩ :=
Partrec.merge (h₁.map (Computable.const true).to₂) (h₂.map (Computable.const false).to₂)
(by
intro a x hx y hy
simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop,
and_true, exists_const] at hx hy
cases hy.1 hx.1)
refine Partrec.of_eq pk fun n => Part.eq_some_iff.2 ?_
rw [hk]
simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop, and_true,
true_eq_decide_iff, and_self, exists_const, false_eq_decide_iff]
apply Decidable.em⟩⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | computable_iff_re_compl_re | null |
computable_iff_re_compl_re' {p : α → Prop} :
ComputablePred p ↔ REPred p ∧ REPred fun a => ¬p a := by
classical exact computable_iff_re_compl_re | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | computable_iff_re_compl_re' | null |
halting_problem_not_re (n) : ¬REPred fun c => ¬(eval c n).Dom
| h => halting_problem _ <| computable_iff_re_compl_re'.2 ⟨halting_problem_re _, h⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | halting_problem_not_re | null |
Partrec' : ∀ {n}, (List.Vector ℕ n →. ℕ) → Prop
| prim {n f} : @Primrec' n f → @Partrec' n f
| comp {m n f} (g : Fin n → List.Vector ℕ m →. ℕ) :
Partrec' f → (∀ i, Partrec' (g i)) →
Partrec' fun v => (List.Vector.mOfFn fun i => g i v) >>= f
| rfind {n} {f : List.Vector ℕ (n + 1) → ℕ} :
@Partrec' (n + 1) f → Partrec' fun v => rfind fun n => some (f (n ::ᵥ v) = 0) | inductive | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | Partrec' | A simplified basis for `Partrec`. |
to_part {n f} (pf : @Partrec' n f) : _root_.Partrec f := by
induction pf with
| prim hf => exact hf.to_prim.to_comp
| comp _ _ _ hf hg => exact (Partrec.vector_mOfFn hg).bind (hf.comp snd)
| rfind _ hf =>
have := hf.comp (vector_cons.comp snd fst)
have :=
((Primrec.eq.decide.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
this).to₂.partrec₂
exact _root_.Partrec.rfind this | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | to_part | null |
of_eq {n} {f g : List.Vector ℕ n →. ℕ} (hf : Partrec' f) (H : ∀ i, f i = g i) :
Partrec' g :=
(funext H : f = g) ▸ hf | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | of_eq | null |
of_prim {n} {f : List.Vector ℕ n → ℕ} (hf : Primrec f) : @Partrec' n f :=
prim (Nat.Primrec'.of_prim hf) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | of_prim | null |
head {n : ℕ} : @Partrec' n.succ (@head ℕ n) :=
prim Nat.Primrec'.head | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | head | null |
tail {n f} (hf : @Partrec' n f) : @Partrec' n.succ fun v => f v.tail :=
(hf.comp _ fun i => @prim _ _ <| Nat.Primrec'.get i.succ).of_eq fun v => by
simp; rw [← ofFn_get v.tail]; congr; funext i; simp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | tail | null |
protected bind {n f g} (hf : @Partrec' n f) (hg : @Partrec' (n + 1) g) :
@Partrec' n fun v => (f v).bind fun a => g (a ::ᵥ v) :=
(@comp n (n + 1) g (fun i => Fin.cases f (fun i v => some (v.get i)) i) hg fun i => by
refine Fin.cases ?_ (fun i => ?_) i <;> simp [*]
exact prim (Nat.Primrec'.get _)).of_eq
fun v => by simp [mOfFn, Part.bind_assoc, pure] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | bind | null |
protected map {n f} {g : List.Vector ℕ (n + 1) → ℕ} (hf : @Partrec' n f)
(hg : @Partrec' (n + 1) g) : @Partrec' n fun v => (f v).map fun a => g (a ::ᵥ v) := by
simpa [(Part.bind_some_eq_map _ _).symm] using hf.bind hg | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | map | null |
Vec {n m} (f : List.Vector ℕ n → List.Vector ℕ m) :=
∀ i, Partrec' fun v => (f v).get i
nonrec theorem Vec.prim {n m f} (hf : @Nat.Primrec'.Vec n m f) : Vec f := fun i => prim <| hf i | def | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | Vec | Analogous to `Nat.Partrec'` for `ℕ`-valued functions, a predicate for partial recursive
vector-valued functions. |
protected nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0 | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | nil | null |
protected cons {n m} {f : List.Vector ℕ n → ℕ} {g} (hf : @Partrec' n f)
(hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i =>
Fin.cases (by simpa using hf) (fun i => by simp only [hg i, get_cons_succ]) i | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | cons | null |
idv {n} : @Vec n n id :=
Vec.prim Nat.Primrec'.idv | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | idv | null |
comp' {n m f g} (hf : @Partrec' m f) (hg : @Vec n m g) : Partrec' fun v => f (g v) :=
(hf.comp _ hg).of_eq fun v => by simp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | comp' | null |
comp₁ {n} (f : ℕ →. ℕ) {g : List.Vector ℕ n → ℕ} (hf : @Partrec' 1 fun v => f v.head)
(hg : @Partrec' n g) : @Partrec' n fun v => f (g v) := by
simpa using hf.comp' (Partrec'.cons hg Partrec'.nil) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | comp₁ | null |
rfindOpt {n} {f : List.Vector ℕ (n + 1) → ℕ} (hf : @Partrec' (n + 1) f) :
@Partrec' n fun v => Nat.rfindOpt fun a => ofNat (Option ℕ) (f (a ::ᵥ v)) :=
((rfind <|
(of_prim (Primrec.nat_sub.comp (_root_.Primrec.const 1) Primrec.vector_head)).comp₁
(fun n => Part.some (1 - n)) hf).bind
((prim Nat.Primrec'.pred).comp₁ Nat.pred hf)).of_eq
fun v =>
Part.ext fun b => by
simp only [Nat.rfindOpt, Nat.sub_eq_zero_iff_le, PFun.coe_val, Part.mem_bind_iff,
Part.mem_some_iff, Option.mem_def, Part.mem_coe]
refine
exists_congr fun a => (and_congr (iff_of_eq ?_) Iff.rfl).trans (and_congr_right fun h => ?_)
· congr
funext n
cases f (n ::ᵥ v) <;> simp <;> rfl
· have := Nat.rfind_spec h
simp only [Part.coe_some, Part.mem_some_iff] at this
revert this; rcases f (a ::ᵥ v) with - | c <;> intro this
· cases this
rw [← Option.some_inj, eq_comm]
rfl
open Nat.Partrec.Code | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | rfindOpt | null |
of_part : ∀ {n f}, _root_.Partrec f → @Partrec' n f :=
@(suffices ∀ f, Nat.Partrec f → @Partrec' 1 fun v => f v.head from fun {n f} hf => by
let g := fun n₁ =>
(Part.ofOption (decode (α := List.Vector ℕ n) n₁)).bind (fun a => Part.map encode (f a))
exact
(comp₁ g (this g hf) (prim Nat.Primrec'.encode)).of_eq fun i => by
dsimp only [g]; simp [encodek, Part.map_id']
fun f hf => by
obtain ⟨c, rfl⟩ := exists_code.1 hf
simpa [eval_eq_rfindOpt] using
rfindOpt <|
of_prim <|
Primrec.encode_iff.2 <|
primrec_evaln.comp <|
(Primrec.vector_head.pair (_root_.Primrec.const c)).pair <|
Primrec.vector_head.comp Primrec.vector_tail) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | of_part | null |
part_iff {n f} : @Partrec' n f ↔ _root_.Partrec f :=
⟨to_part, of_part⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | part_iff | null |
part_iff₁ {f : ℕ →. ℕ} : (@Partrec' 1 fun v => f v.head) ↔ _root_.Partrec f :=
part_iff.trans
⟨fun h =>
(h.comp <| (Primrec.vector_ofFn fun _ => _root_.Primrec.id).to_comp).of_eq fun v => by
simp only [id, head_ofFn],
fun h => h.comp vector_head⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | part_iff₁ | null |
part_iff₂ {f : ℕ → ℕ →. ℕ} : (@Partrec' 2 fun v => f v.head v.tail.head) ↔ Partrec₂ f :=
part_iff.trans
⟨fun h =>
(h.comp <| vector_cons.comp fst <| vector_cons.comp snd (const nil)).of_eq fun v => by
simp only [head_cons, tail_cons],
fun h => h.comp vector_head (vector_head.comp vector_tail)⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | part_iff₂ | null |
vec_iff {m n f} : @Vec m n f ↔ Computable f :=
⟨fun h => by simpa only [ofFn_get] using vector_ofFn fun i => to_part (h i), fun h i =>
of_part <| vector_get.comp h (const i)⟩ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Data.Set.Subsingleton"
] | Mathlib/Computability/Halting.lean | vec_iff | null |
Language (α) :=
Set (List α) | def | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | Language | A language is a set of strings over an alphabet. |
instCompleteAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Language α) :=
Set.instCompleteAtomicBooleanAlgebra
variable {l m : Language α} {a b x : List α} | instance | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | instCompleteAtomicBooleanAlgebra | null |
map (f : α → β) : Language α →+* Language β where
toFun := image (List.map f)
map_zero' := image_empty _
map_one' := image_singleton
map_add' := image_union _
map_mul' _ _ := image_image2_distrib <| fun _ _ => map_append
@[simp] | def | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | map | Zero language has no elements. -/
instance : Zero (Language α) :=
⟨(∅ : Set _)⟩
/-- `1 : Language α` contains only one element `[]`. -/
instance : One (Language α) :=
⟨{[]}⟩
instance : Inhabited (Language α) := ⟨(∅ : Set _)⟩
/-- The sum of two languages is their union. -/
instance : Add (Language α) :=
⟨((· ∪ ·) : Set (List α) → Set (List α) → Set (List α))⟩
/-- The product of two languages `l` and `m` is the language made of the strings `x ++ y` where
`x ∈ l` and `y ∈ m`. -/
instance : Mul (Language α) :=
⟨image2 (· ++ ·)⟩
theorem zero_def : (0 : Language α) = (∅ : Set _) :=
rfl
theorem one_def : (1 : Language α) = ({[]} : Set (List α)) :=
rfl
theorem add_def (l m : Language α) : l + m = (l ∪ m : Set (List α)) :=
rfl
theorem mul_def (l m : Language α) : l * m = image2 (· ++ ·) l m :=
rfl
/-- The Kleene star of a language `L` is the set of all strings which can be written by
concatenating strings from `L`. -/
instance : KStar (Language α) := ⟨fun l ↦ {x | ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l}⟩
lemma kstar_def (l : Language α) : l∗ = {x | ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l} :=
rfl
@[ext]
theorem ext {l m : Language α} (h : ∀ (x : List α), x ∈ l ↔ x ∈ m) : l = m :=
Set.ext h
@[simp]
theorem notMem_zero (x : List α) : x ∉ (0 : Language α) :=
id
@[deprecated (since := "2025-05-23")] alias not_mem_zero := notMem_zero
@[simp]
theorem mem_one (x : List α) : x ∈ (1 : Language α) ↔ x = [] := by rfl
theorem nil_mem_one : [] ∈ (1 : Language α) :=
Set.mem_singleton _
theorem mem_add (l m : Language α) (x : List α) : x ∈ l + m ↔ x ∈ l ∨ x ∈ m :=
Iff.rfl
theorem mem_mul : x ∈ l * m ↔ ∃ a ∈ l, ∃ b ∈ m, a ++ b = x :=
mem_image2
theorem append_mem_mul : a ∈ l → b ∈ m → a ++ b ∈ l * m :=
mem_image2_of_mem
theorem mem_kstar : x ∈ l∗ ↔ ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l :=
Iff.rfl
theorem join_mem_kstar {L : List (List α)} (h : ∀ y ∈ L, y ∈ l) : L.flatten ∈ l∗ :=
⟨L, rfl, h⟩
theorem nil_mem_kstar (l : Language α) : [] ∈ l∗ :=
⟨[], rfl, fun _ h ↦ by contradiction⟩
instance instSemiring : Semiring (Language α) where
add := (· + ·)
add_assoc := union_assoc
zero := 0
zero_add := empty_union
add_zero := union_empty
add_comm := union_comm
mul := (· * ·)
mul_assoc _ _ _ := image2_assoc append_assoc
zero_mul _ := image2_empty_left
mul_zero _ := image2_empty_right
one := 1
one_mul l := by simp [mul_def, one_def]
mul_one l := by simp [mul_def, one_def]
natCast n := if n = 0 then 0 else 1
natCast_zero := rfl
natCast_succ n := by cases n <;> simp [add_def, zero_def]
left_distrib _ _ _ := image2_union_right
right_distrib _ _ _ := image2_union_left
nsmul := nsmulRec
@[simp]
theorem add_self (l : Language α) : l + l = l :=
sup_idem _
/-- Maps the alphabet of a language. |
map_id (l : Language α) : map id l = l := by simp [map]
@[simp] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | map_id | null |
map_map (g : β → γ) (f : α → β) (l : Language α) : map g (map f l) = map (g ∘ f) l := by
simp [map, image_image] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | map_map | null |
mem_kstar_iff_exists_nonempty {x : List α} :
x ∈ l∗ ↔ ∃ S : List (List α), x = S.flatten ∧ ∀ y ∈ S, y ∈ l ∧ y ≠ [] := by
constructor
· rintro ⟨S, rfl, h⟩
refine ⟨S.filter fun l ↦ !List.isEmpty l,
by simp [List.flatten_filter_not_isEmpty], fun y hy ↦ ?_⟩
simp only [mem_filter, Bool.not_eq_eq_eq_not, Bool.not_true, isEmpty_eq_false_iff, ne_eq] at hy
exact ⟨h y hy.1, hy.2⟩
· rintro ⟨S, hx, h⟩
exact ⟨S, hx, fun y hy ↦ (h y hy).1⟩ | lemma | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | mem_kstar_iff_exists_nonempty | null |
kstar_def_nonempty (l : Language α) :
l∗ = { x | ∃ S : List (List α), x = S.flatten ∧ ∀ y ∈ S, y ∈ l ∧ y ≠ [] } := by
ext x; apply mem_kstar_iff_exists_nonempty | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | kstar_def_nonempty | null |
le_iff (l m : Language α) : l ≤ m ↔ l + m = m :=
sup_eq_right.symm | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | le_iff | null |
le_mul_congr {l₁ l₂ m₁ m₂ : Language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ * l₂ ≤ m₁ * m₂ := by
intro h₁ h₂ x hx
simp only [mul_def, mem_image2] at hx ⊢
tauto | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | le_mul_congr | null |
le_add_congr {l₁ l₂ m₁ m₂ : Language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ + l₂ ≤ m₁ + m₂ :=
sup_le_sup | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | le_add_congr | null |
mem_iSup {ι : Sort v} {l : ι → Language α} {x : List α} : (x ∈ ⨆ i, l i) ↔ ∃ i, x ∈ l i :=
mem_iUnion | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | mem_iSup | null |
iSup_mul {ι : Sort v} (l : ι → Language α) (m : Language α) :
(⨆ i, l i) * m = ⨆ i, l i * m :=
image2_iUnion_left _ _ _ | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | iSup_mul | null |
mul_iSup {ι : Sort v} (l : ι → Language α) (m : Language α) :
(m * ⨆ i, l i) = ⨆ i, m * l i :=
image2_iUnion_right _ _ _ | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | mul_iSup | null |
iSup_add {ι : Sort v} [Nonempty ι] (l : ι → Language α) (m : Language α) :
(⨆ i, l i) + m = ⨆ i, l i + m :=
iSup_sup | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | iSup_add | null |
add_iSup {ι : Sort v} [Nonempty ι] (l : ι → Language α) (m : Language α) :
(m + ⨆ i, l i) = ⨆ i, m + l i :=
sup_iSup | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | add_iSup | null |
mem_pow {l : Language α} {x : List α} {n : ℕ} :
x ∈ l ^ n ↔ ∃ S : List (List α), x = S.flatten ∧ S.length = n ∧ ∀ y ∈ S, y ∈ l := by
induction n generalizing x with
| zero => simp
| succ n ihn =>
simp only [pow_succ', mem_mul, ihn]
constructor
· rintro ⟨a, ha, b, ⟨S, rfl, rfl, hS⟩, rfl⟩
exact ⟨a :: S, rfl, rfl, forall_mem_cons.2 ⟨ha, hS⟩⟩
· rintro ⟨_ | ⟨a, S⟩, rfl, hn, hS⟩ <;> cases hn
rw [forall_mem_cons] at hS
exact ⟨a, hS.1, _, ⟨S, rfl, rfl, hS.2⟩, rfl⟩ | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | mem_pow | null |
kstar_eq_iSup_pow (l : Language α) : l∗ = ⨆ i : ℕ, l ^ i := by
ext x
simp only [mem_kstar, mem_iSup, mem_pow]
grind
@[simp] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | kstar_eq_iSup_pow | null |
map_kstar (f : α → β) (l : Language α) : map f l∗ = (map f l)∗ := by
rw [kstar_eq_iSup_pow, kstar_eq_iSup_pow]
simp_rw [← map_pow]
exact image_iUnion | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | map_kstar | null |
mul_self_kstar_comm (l : Language α) : l∗ * l = l * l∗ := by
simp only [kstar_eq_iSup_pow, mul_iSup, iSup_mul, ← pow_succ, ← pow_succ']
@[simp] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | mul_self_kstar_comm | null |
one_add_self_mul_kstar_eq_kstar (l : Language α) : 1 + l * l∗ = l∗ := by
simp only [kstar_eq_iSup_pow, mul_iSup, ← pow_succ', ← pow_zero l]
exact sup_iSup_nat_succ _
@[simp] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | one_add_self_mul_kstar_eq_kstar | null |
one_add_kstar_mul_self_eq_kstar (l : Language α) : 1 + l∗ * l = l∗ := by
rw [mul_self_kstar_comm, one_add_self_mul_kstar_eq_kstar] | theorem | Computability | [
"Mathlib.Algebra.Order.Kleene",
"Mathlib.Algebra.Ring.Hom.Defs",
"Mathlib.Data.Set.Lattice",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/Language.lean | one_add_kstar_mul_self_eq_kstar | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.