Langlib

Langlib.Classes.ContextFree.Decidability.UniformMembership

Uniform Membership Check for Encoded Context-Free Grammars #

Saturation Algorithm Definitions #

def matchRHS {T : Type} [DecidableEq T] (w : List T) (nc : ) (S : List ( × × )) (rhs : List ( T)) (startPos : ) :

Match a rule's RHS against a substring of word w, starting from position startPos. Returns all possible end positions after matching the full RHS.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def satStep {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) :

    One step of the saturation.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def satFixpoint {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (steps : ) :

      Iterate the saturation step.

      Equations
      Instances For

        Check membership of word w in the language of encoded CFG G.

        Equations
        Instances For

          Monotonicity #

          theorem satStep_mono {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (t : × × ) :
          t St satStep nc rules w S
          theorem satFixpoint_mono {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (n m : ) (h : n m) (t : × × ) :
          t satFixpoint nc rules w nt satFixpoint nc rules w m

          Soundness Lemmas #

          def TripleDerives {T : Type} (G : EncodedCFG T) (w : List T) (nt i j : ) :

          Property that a triple represents a valid derivation.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def AllSound {T : Type} (G : EncodedCFG T) (w : List T) (S : List ( × × )) :

            Property that all triples in a set represent valid derivations.

            Equations
            Instances For
              theorem matchRHS_sound {T : Type} [DecidableEq T] (G : EncodedCFG T) (w : List T) (S : List ( × × )) (hS : AllSound G w S) (rhs : List ( T)) (startPos endPos : ) (hstart : startPos w.length) (hmatch : endPos matchRHS w G.ntCount S rhs startPos) :
              startPos endPos endPos w.length CF_derives G.toCFGrammar (List.map G.toSymbol rhs) (List.map symbol.terminal (List.take (endPos - startPos) (List.drop startPos w)))
              theorem mem_satStep_iff {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (nt i j : ) :
              (nt, i, j) satStep nc rules w S(nt, i, j) S rulerules, startPosw.length, nt = rule.1 % nc i = startPos j matchRHS w nc S rule.2 startPos
              theorem satStep_sound {T : Type} [DecidableEq T] (G : EncodedCFG T) (w : List T) (S : List ( × × )) (hS : AllSound G w S) :
              theorem satFixpoint_sound {T : Type} [DecidableEq T] (G : EncodedCFG T) (w : List T) (steps : ) :

              matchRHS structural lemmas #

              def matchOneSym {T : Type} [DecidableEq T] (w : List T) (nc : ) (S : List ( × × )) (sym : T) (pos : ) :

              The single-symbol matching step.

              Equations
              Instances For
                theorem matchRHS_foldl_append {T : Type} [DecidableEq T] (w : List T) (nc : ) (S : List ( × × )) (rhs : List ( T)) (p1 p2 : List ) :
                List.foldl (fun (positions : List ) (sym : T) => List.flatMap (matchOneSym w nc S sym) positions) (p1 ++ p2) rhs = List.foldl (fun (positions : List ) (sym : T) => List.flatMap (matchOneSym w nc S sym) positions) p1 rhs ++ List.foldl (fun (positions : List ) (sym : T) => List.flatMap (matchOneSym w nc S sym) positions) p2 rhs
                theorem matchRHS_cons {T : Type} [DecidableEq T] (w : List T) (nc : ) (S : List ( × × )) (sym : T) (rest : List ( T)) (startPos : ) :
                matchRHS w nc S (sym :: rest) startPos = List.flatMap (matchRHS w nc S rest) (matchOneSym w nc S sym startPos)

                Completeness Lemmas #

                theorem mem_satStep_of_matchRHS {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (lhs : ) (rhs : List ( T)) (hrule : (lhs, rhs) rules) (startPos endPos : ) (hstart : startPos w.length) (hmatch : endPos matchRHS w nc S rhs startPos) :
                (lhs % nc, startPos, endPos) satStep nc rules w S

                Monotonicity of matchRHS in S #

                theorem matchRHS_mono {T : Type} [DecidableEq T] (w : List T) (nc : ) (S₁ S₂ : List ( × × )) (hS : tS₁, t S₂) (rhs : List ( T)) (startPos e : ) :
                e matchRHS w nc S₁ rhs startPose matchRHS w nc S₂ rhs startPos

                Additional splitting lemmas #

                theorem terminal_derives_in_self {T : Type} (g : CF_grammar T) (t : T) (n : ) (w : List T) (h : CF_derives_in g n [symbol.terminal t] (List.map symbol.terminal w)) :
                n = 0 w = [t]
                theorem transforms_single_nonterminal {T : Type} (g : CF_grammar T) (nt : g.nt) (mid : List (symbol T g.nt)) (h : CF_transforms g [symbol.nonterminal nt] mid) :
                ∃ (rhs : List (symbol T g.nt)), (nt, rhs) g.rules mid = rhs
                theorem rawRule_of_toCFGrammar_rule {T : Type} (G : EncodedCFG T) (nt : Fin G.ntCount) (rhs : List (symbol T (Fin G.ntCount))) (hrule : (nt, rhs) G.toCFGrammar.rules) :
                ∃ (lhs_raw : ) (rhs_raw : List ( T)), (lhs_raw, rhs_raw) G.rawRules G.toNT lhs_raw = nt rhs = List.map G.toSymbol rhs_raw
                theorem matchRHS_in_satFixpoint {T : Type} [DecidableEq T] (G : EncodedCFG T) (w : List T) (n : ) (ih_outer : m < n + 1, ∀ (nt : Fin G.ntCount) (i j : ), i jj w.lengthCF_derives_in G.toCFGrammar m [symbol.nonterminal nt] (List.map symbol.terminal (List.take (j - i) (List.drop i w)))∃ (bound : ), (nt, i, j) satFixpoint G.ntCount G.rawRules w bound) (rhs : List ( T)) (startPos endPos : ) (hstart : startPos endPos) (hend : endPos w.length) (nder : ) (hnder : nder n) (hder : CF_derives_in G.toCFGrammar nder (List.map G.toSymbol rhs) (List.map symbol.terminal (List.take (endPos - startPos) (List.drop startPos w)))) :
                ∃ (bound : ), endPos matchRHS w G.ntCount (satFixpoint G.ntCount G.rawRules w bound) rhs startPos
                theorem satFixpoint_complete {T : Type} [DecidableEq T] (G : EncodedCFG T) (w : List T) (nt : Fin G.ntCount) (i j : ) (hij : i j) (hj : j w.length) (hder : CF_derives G.toCFGrammar [symbol.nonterminal nt] (List.map symbol.terminal (List.take (j - i) (List.drop i w)))) :
                ∃ (bound : ), (nt, i, j) satFixpoint G.ntCount G.rawRules w bound

                Saturation Stabilization #

                theorem satStep_prefix {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) :
                S <+: satStep nc rules w S
                theorem satStep_fst_bound {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (nt i j : ) (hnc : 0 < nc) (hS : ∀ (nt' i' j' : ), (nt', i', j') Snt' < nc) (h : (nt, i, j) satStep nc rules w S) :
                nt < nc
                theorem matchRHS_endPos_bound {T : Type} [DecidableEq T] (w : List T) (nc : ) (S : List ( × × )) (hS : ∀ (nt i j : ), (nt, i, j) Sj w.length) (rhs : List ( T)) (startPos endPos : ) (hstart : startPos w.length) (hmatch : endPos matchRHS w nc S rhs startPos) :
                endPos w.length
                theorem satStep_pos_bound {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (hS : ∀ (nt i j : ), (nt, i, j) Si w.length j w.length) (nt i j : ) (h : (nt, i, j) satStep nc rules w S) :
                theorem satStep_nodup {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (S : List ( × × )) (hS : S.Nodup) :
                (satStep nc rules w S).Nodup
                theorem satFixpoint_nodup {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (n : ) :
                (satFixpoint nc rules w n).Nodup
                theorem satFixpoint_entries_bounded {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (hnc : 0 < nc) (n nt i j : ) (h : (nt, i, j) satFixpoint nc rules w n) :
                nt < nc i w.length j w.length
                theorem satFixpoint_length_bounded {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (hnc : 0 < nc) (n : ) :
                (satFixpoint nc rules w n).length nc * (w.length + 1) * (w.length + 1)
                theorem satFixpoint_stable_after {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (k : ) (hk : satFixpoint nc rules w k = satFixpoint nc rules w (k + 1)) (m : ) :
                m ksatFixpoint nc rules w m = satFixpoint nc rules w k
                theorem satFixpoint_converges {T : Type} [DecidableEq T] (nc : ) (rules : List ( × List ( T))) (w : List T) (hnc : 0 < nc) (t : × × ) :
                (∃ (n : ), t satFixpoint nc rules w n)t satFixpoint nc rules w (nc * (w.length + 1) * (w.length + 1) + 1)

                Main Correctness #