Documentation

LeanPool.PumpingCfg.ChomskyNormalForm.LengthRestriction

Length Restriction #

This file contains the algorithm to translate a ContextFreeGrammar.Wellformed grammar to a chomsky normal form grammar while preserving the language of the original grammar. A context-free grammar is wellformed if it has rules that rewrite either to a single terminal or multiple nonterminals.

Main definitions #

Main theorems #

References #

inductive ContextFreeRule.Wellformed {T : Type uT} {N : Type u_1} :

Wellformed r holds if the rule's output is not a single nonterminal (UnitRule), not empty, or if the output is more than one symbol, it is only nonterminals

Instances For
    theorem ContextFreeRule.only_nonterminals {T : Type uT} {N : Type u_1} {u : List (Symbol T N)} (hu : su, match s with | Symbol.nonterminal n => True | x => False) :
    theorem ContextFreeRule.Wellformed.mem_nonterminal {T : Type uT} {N : Type u_1} {r : ContextFreeRule T N} (hr : r.Wellformed) (i : Fin r.output.length) (h2 : 2 r.output.length) :
    ∃ (n : N), r.output[i] = Symbol.nonterminal n
    theorem ContextFreeRule.Wellformed.cases {T : Type uT} {N : Type u_1} {r : ContextFreeRule T N} (hr : r.Wellformed) :
    (∃ (t : T), r.output = [Symbol.terminal t]) ∃ (n₁ : N) (n₂ : N) (u : List N), r.output = Symbol.nonterminal n₁ :: Symbol.nonterminal n₂ :: List.map Symbol.nonterminal u

    Definition of ContextFreeGrammar.restrictLength, the algorithm to translate a wellformed context-free grammar to a chomsky normal form grammar

    @[reducible, inline]

    Shorthand for the new type of nonterminals.

    Equations
    Instances For
      @[irreducible]

      Computes a cascade of rules generating r.output if it only contains nonterminals. For a rule r : n -> n₁n₂n₃n₄, generates rules n -> n₁m₂, m₂ -> n₂m₃, and m₃ -> n₃n₄. The type of of NT', encodes the correspondence between rules and the new nonterminals.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        We assume all rules' output is either a pair of nonterminals, a single terminal or a string of at least 3 nonterminals. In the first two cases we can directly translate them, otherwise we generate new rules using compute_rules_rec.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Construct a ChomskyNormalGrammar corresponding to the original ContextFreeGrammar

          Equations
          Instances For

            A grammar is Wellformed if all rules are ContextFreeRule.Wellformed

            Equations
            Instances For

              Definitions of embeding into and projecting to the type of symbols of the new grammar

              Intuitive embedding of symbols of the original grammar into symbols of the new grammar's type

              Equations
              Instances For
                @[reducible, inline]

                Intuitive embedding of strings of the original grammar into strings of the new grammar's type

                Equations
                Instances For
                  @[reducible, inline]

                  Projection from strings of the new grammars type into strings of the original grammar

                  Equations
                  Instances For