Ordinary word equations
DefinitionSubstitution of words for variables in a word#✓fully proved
Substitute words for variables in a word over constants and variables.
Used by 13
DefinitionEmbedding of ordinary words into string terms#✓fully proved
Embed an ordinary word in the larger string-constraint term language.
def wordTerm : List (α ⊕ V) → Term α V
| [] => .const []
| Sum.inl a :: w => .append (.const [a]) (wordTerm w)
| Sum.inr i :: w => .append (.var i) (wordTerm w)
inductive Term (α : Type*) (V : Type*) where
| const : List α → Term α V
| var : V → Term α V
| append : Term α V → Term α V → Term α V
| hom : (α → List α) → Term α V → Term α V
CSLibExt/AutomatedReasoning/StringConstraints/Syntax.lean:74
Uses 1 · Used by 3
TheoremWord embedding preserves substitution semantics#✓fully proved
The embedding preserves substitution semantics.
@[simp] theorem eval_wordTerm (σ : V → List α) (w : List (α ⊕ V)) :
eval σ (wordTerm w) = evalWord σ w
def eval (σ : V → List α) : Term α V → List α
| .const w => w
| .var i => σ i
| .append t₁ t₂ => eval σ t₁ ++ eval σ t₂
| .hom f t => (eval σ t).flatMap f
CSLibExt/AutomatedReasoning/StringConstraints/Syntax.lean:81
def wordTerm : List (α ⊕ V) → Term α V
| [] => .const []
| Sum.inl a :: w => .append (.const [a]) (wordTerm w)
| Sum.inr i :: w => .append (.var i) (wordTerm w)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:45
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
StructureOrdinary word equation#✓fully proved
An ordinary word equation, with no morphisms or language-membership atoms.
Used by 21
DefinitionSolution of a word equation#✓fully proved
A substitution solves a word equation when the substituted sides agree.
def WordEq.Satisfies (σ : V → List α) (e : WordEq α V) : Prop :=
evalWord σ e.lhs = evalWord σ e.rhs
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
Uses 2 · Used by 12
DefinitionWord equation as a string-constraint formula#✓fully proved
View an ordinary word equation as a string-constraint formula.
def WordEq.toFormula (e : WordEq α V) : Formula α V :=
.atom (.eq (wordTerm e.lhs) (wordTerm e.rhs))
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
inductive Formula (α : Type*) (V : Type*) where
| atom : Atom α V → Formula α V
| and : Formula α V → Formula α V → Formula α V
| or : Formula α V → Formula α V → Formula α V
| true : Formula α V
| false : Formula α V
CSLibExt/AutomatedReasoning/StringConstraints/Syntax.lean:150
def wordTerm : List (α ⊕ V) → Term α V
| [] => .const []
| Sum.inl a :: w => .append (.const [a]) (wordTerm w)
| Sum.inr i :: w => .append (.var i) (wordTerm w)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:45
TheoremFormula embedding of word equations preserves satisfaction#✓fully proved
The formula embedding preserves satisfaction.
@[simp] theorem WordEq.sat_toFormula (σ : V → List α) (e : WordEq α V) :
Sat σ e.toFormula ↔ e.Satisfies σ
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
def Sat (σ : V → List α) : Formula α V → Prop
| .atom a => SatAtom σ a
| .and f g => Sat σ f ∧ Sat σ g
| .or f g => Sat σ f ∨ Sat σ g
| .true => True
| .false => False
CSLibExt/AutomatedReasoning/StringConstraints/Syntax.lean:183
Uses 12 · Used by 1
TheoremWord evaluation depends only on occurring variables#✓fully proved
Evaluation depends only on variables that occur in the word.
theorem evalWord_eq_of_agree_on_vars {σ τ : V → List α} {w : List (α ⊕ V)}
(h : ∀ i, Sum.inr i ∈ w → σ i = τ i) : evalWord σ w = evalWord τ w
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
Uses 1 · Used by 1
TheoremOccurring variable's image is no longer than the evaluated word#✓fully proved
Each occurring variable contributes a contiguous block, so its length cannot exceed the length of the evaluated word, even when substitutions may be empty.
theorem length_le_evalWord_of_mem (σ : V → List α) {w : List (α ⊕ V)} {i : V}
(hi : Sum.inr i ∈ w) : (σ i).length ≤ (evalWord σ w).length
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
Uses 1 · Used by 1
DefinitionWord substitution normalized by emptying unused images#✓fully proved
Retain the images of occurring variables and replace every unused image by
[]. Only equality of variables, not equality of alphabet symbols, is needed.
TheoremNormalization keeps images of occurring variables#✓fully proved
Normalization preserves the image of every occurring variable.
theorem normalizeWordSubst_of_mem [DecidableEq V] (σ : V → List α)
{w : List (α ⊕ V)} {i : V} (hi : Sum.inr i ∈ w) :
normalizeWordSubst σ w i = σ i
def normalizeWordSubst [DecidableEq V] (σ : V → List α) (w : List (α ⊕ V)) :
V → List α :=
fun i => if i ∈ w.filterMap (Sum.elim (fun _ => none) some) then σ i else []
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:93
Uses 1 · Used by 1
TheoremNormalization empties images of absent variables#✓fully proved
Every variable absent from the word has empty normalized image.
theorem normalizeWordSubst_of_not_mem [DecidableEq V] (σ : V → List α)
{w : List (α ⊕ V)} {i : V} (hi : Sum.inr i ∉ w) :
normalizeWordSubst σ w i = []
def normalizeWordSubst [DecidableEq V] (σ : V → List α) (w : List (α ⊕ V)) :
V → List α :=
fun i => if i ∈ w.filterMap (Sum.elim (fun _ => none) some) then σ i else []
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:93
Uses 1
TheoremNormalization does not change the evaluated word#✓fully proved
Removing unused images does not change the evaluated word.
@[simp] theorem evalWord_normalizeWordSubst [DecidableEq V] (σ : V → List α)
(w : List (α ⊕ V)) : evalWord (normalizeWordSubst σ w) w = evalWord σ w
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
def normalizeWordSubst [DecidableEq V] (σ : V → List α) (w : List (α ⊕ V)) :
V → List α :=
fun i => if i ∈ w.filterMap (Sum.elim (fun _ => none) some) then σ i else []
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:93
Uses 4 · Used by 1
TheoremNormalized images are bounded by the evaluation length#✓fully proved
After normalization, every variable image, including unused ones, is bounded by the length of the original evaluation.
theorem length_normalizeWordSubst_le [DecidableEq V] (σ : V → List α)
(w : List (α ⊕ V)) (i : V) :
(normalizeWordSubst σ w i).length ≤ (evalWord σ w).length
def normalizeWordSubst [DecidableEq V] (σ : V → List α) (w : List (α ⊕ V)) :
V → List α :=
fun i => if i ∈ w.filterMap (Sum.elim (fun _ => none) some) then σ i else []
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:93
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
TheoremBounding variable images by the target loses no pattern matches#✓fully proved
Matching a pattern against a fixed target loses no solutions by bounding
ALL variable images by the target length. Unused variables are normalized to
[]; an arbitrary unnormalized solution need not obey this bound.
theorem patternMatch_iff_bounded {n : ℕ} (w : List (α ⊕ Fin n)) (target : List α) :
(∃ σ : Fin n → List α, evalWord σ w = target) ↔
∃ σ : Fin n → List α, (∀ i, (σ i).length ≤ target.length) ∧
evalWord σ w = target
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
Uses 4 · Used by 1
DefinitionExecutable satisfaction test for ground word equations#✓fully proved
Executable satisfaction test for a ground equation. Since the variable
type is Empty, no substitution search is required.
def WordEq.groundSatB [DecidableEq α] (e : WordEq α Empty) : Bool :=
decide (evalWord Empty.elim e.lhs = evalWord Empty.elim e.rhs)
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
def evalWord (σ : V → List α) (w : List (α ⊕ V)) : List α :=
w.flatMap (Sum.elim (fun a => [a]) σ)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:41
Uses 2 · Used by 2
TheoremGround test agrees with satisfaction under any substitution#✓fully proved
The ground test agrees with satisfaction under any substitution.
theorem WordEq.groundSatB_eq_true_iff [DecidableEq α] (e : WordEq α Empty)
(σ : Empty → List α) : e.groundSatB = true ↔ e.Satisfies σ
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
Uses 4 · Used by 1
TheoremGround test decides solvability of ground word equations#✓fully proved
The executable ground test decides existence of a solution, not just satisfaction of one guessed substitution.
TheoremSolvability of word equation systems at a finite length bound#✓fully proved
A system over finitely many variables has a solution iff one substitution solves every equation at some finite global length bound. The witness bound is obtained from the solution; this supplies no terminating general UNSAT test.
theorem wordSystem_satisfiable_iff_exists_bound {n : ℕ} (es : List (WordEq α (Fin n))) :
(∃ σ : Fin n → List α, ∀ e ∈ es, e.Satisfies σ) ↔
∃ B : ℕ, ∃ σ : Fin n → List α, (∀ i, (σ i).length ≤ B) ∧
∀ e ∈ es, e.Satisfies σ
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
Uses 2 · Used by 2
TheoremSatisfiability of a single word equation at a finite length bound#✓fully proved
An equation over Fin n is satisfiable iff it is satisfiable at some
finite global length bound. There is no equation-computable bound claimed.
theorem WordEq.satisfiable_iff_exists_bound {n : ℕ} (e : WordEq α (Fin n)) :
(∃ σ : Fin n → List α, e.Satisfies σ) ↔
∃ B : ℕ, ∃ σ : Fin n → List α, (∀ i, (σ i).length ≤ B) ∧ e.Satisfies σ
structure WordEq (α V : Type*) where
lhs : List (α ⊕ V)
rhs : List (α ⊕ V)
CSLibExt/AutomatedReasoning/StringConstraints/WordEquations.lean:58
Uses 3
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.