SyGuS grammars, typed #
A grammar restricts the shape of a term the solver may produce, for synthFun, getInterpolant or
getAbduct. smt.grammar! writes one as a block, its first non-terminal being the start symbol:
smt.grammar! s (x y : Int) where
start : Int := x | y | 0 | if c then start else start
c : Bool := start ≤ start
A rule must have its non-terminal's sort, or it does not compile. A Grammar σ carries the
parameters it was built over, and σ is their sorts arrowed onto the start symbol's
(Int → Int → Int above), so synthFun needs nothing else. Any solver of the scope accepts a
grammar, but a grammar freezes once used: after synthFun, cvc5 rejects further rules.
Non-terminal symbols #
A grammar's non-terminal symbol, at the sort its index describes.
A bound variable, but not interchangeable with one: mkGrammar takes the parameters and the
non-terminals separately, and only the type keeps them apart.
- ofUntyped :: (
- untyped : Cvc.Untyped.NT
- )
Instances For
Non-terminal symbols of assorted sorts.
Equations
- Cvc.Typed.NTs = List ((α : Type) × Cvc.Typed.NT α)
Instances For
A non-terminal symbol of the sort α describes.
Equations
- Cvc.Typed.NT.mk' α name = do let __do_lift ← Cvc.Srt.of α let __do_lift ← Cvc.Untyped.NT.mk __do_lift name pure { untyped := __do_lift }
Instances For
A non-terminal symbol of the sort α describes.
Equations
- Cvc.Typed.NT.mk name = Cvc.Typed.NT.mk' α name
Instances For
Turns itself into a bound variable.
Explicit on purpose: there is no coercion, because a non-terminal is not a parameter.
Equations
- nt.toBVar = (Cvc.Typed.NT.untyped✝ nt).toBVar
Instances For
Turns itself into a term, which is how a non-terminal appears inside its own rules.
Equations
- nt.toTerm = (Cvc.Typed.NT.untyped✝ nt).toTerm
Instances For
Equations
The sort-erased non-terminal it wraps, for free.
Equations
- nt.toUntyped = Cvc.Typed.NT.untyped✝ nt
Instances For
The sort-erased non-terminal it wraps, for free.
Equations
Instances For
Types a sort-erased non-terminal at α, checking its sort against α's.
The non-terminal counterpart of Untyped.Term.toTypedAs, so that the non-terminals a sort-erased
grammar was built with can be given rules through the typed Grammar.addRule. toTyped infers
α from the expected type; typeCheckAs and typeCheck are the same two functions under the
names that say what they do.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Types a sort-erased non-terminal at α, checking its sort against α's.
The non-terminal counterpart of Untyped.Term.toTypedAs, so that the non-terminals a sort-erased
grammar was built with can be given rules through the typed Grammar.addRule. toTyped infers
α from the expected type; typeCheckAs and typeCheck are the same two functions under the
names that say what they do.
Equations
- nt.toTyped = Cvc.Untyped.NT.toTypedAs α nt
Instances For
Types a sort-erased non-terminal at α, checking its sort against α's.
The non-terminal counterpart of Untyped.Term.toTypedAs, so that the non-terminals a sort-erased
grammar was built with can be given rules through the typed Grammar.addRule. toTyped infers
α from the expected type; typeCheckAs and typeCheck are the same two functions under the
names that say what they do.
Equations
Instances For
Types a sort-erased non-terminal at α, checking its sort against α's.
The non-terminal counterpart of Untyped.Term.toTypedAs, so that the non-terminals a sort-erased
grammar was built with can be given rules through the typed Grammar.addRule. toTyped infers
α from the expected type; typeCheckAs and typeCheck are the same two functions under the
names that say what they do.
Equations
Instances For
The sort-erased non-terminals, in the same order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The sort-erased non-terminals, in the same order.
Equations
Instances For
Grammars #
A grammar over the given parameters, starting at start.
boundVars are the parameters of the function the grammar will constrain, and the index is their
sorts arrowed onto start's. others are the other non-terminals the rules may mention.
Equations
Instances For
Types a sort-erased grammar at signature σ, checking it against what the grammar generates.
σ is compared with the grammar's parameters' sorts arrowed onto its start symbol's. toTyped
infers σ from the expected type; typeCheckAs and typeCheck are the same two functions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Types a sort-erased grammar at signature σ, checking it against what the grammar generates.
σ is compared with the grammar's parameters' sorts arrowed onto its start symbol's. toTyped
infers σ from the expected type; typeCheckAs and typeCheck are the same two functions.
Equations
Instances For
Types a sort-erased grammar at signature σ, checking it against what the grammar generates.
σ is compared with the grammar's parameters' sorts arrowed onto its start symbol's. toTyped
infers σ from the expected type; typeCheckAs and typeCheck are the same two functions.
Instances For
Types a sort-erased grammar at signature σ, checking it against what the grammar generates.
σ is compared with the grammar's parameters' sorts arrowed onto its start symbol's. toTyped
infers σ from the expected type; typeCheckAs and typeCheck are the same two functions.
Instances For
Adds a production rule.
The rule's index is the non-terminal's, so a sort mismatch does not typecheck. That the non-terminal belongs to this grammar is a property of a value rather than a type, so it is checked when the rule is added.
Equations
Instances For
Adds a production rule.
The rule's index is the non-terminal's, so a sort mismatch does not typecheck. That the non-terminal belongs to this grammar is a property of a value rather than a type, so it is checked when the rule is added.
Equations
- g.addRules nt rules = do let __do_lift ← (Cvc.Typed.Grammar.untyped✝ g).addRules nt.erase (Array.map Cvc.Typed.Term.erase rules) pure { untyped := __do_lift }
Instances For
Allows any constant of the non-terminal's sort.
Equations
- g.addAnyConstant nt = do let __do_lift ← (Cvc.Typed.Grammar.untyped✝ g).addAnyConstant nt.erase pure { untyped := __do_lift }
Instances For
Allows any of the grammar's parameters that has the non-terminal's sort.
Equations
- g.addAnyVariable nt = do let __do_lift ← (Cvc.Typed.Grammar.untyped✝ g).addAnyVariable nt.erase pure { untyped := __do_lift }
Instances For
smt.grammar! #
Available under open Cvc.Typed. A parameter's or a non-terminal's sort is written as a Lean type.
To add rules afterwards, smt.mkGrammar! and smt.letGrammar! also hand back the parameters, as
BVar α, and the non-terminals, as NT α; there, a non-terminal may be declared with no
alternatives (n : Int).
A grammar written as a block: smt.grammar! s (x : Int) where start : Int := x | ?const.
After the solver building it and the parameters, one line per non-terminal, the first being the
start symbol, with |-separated smt! alternatives. ?const and ?var allow any constant and
any parameter of the non-terminal's sort.
Equations
- One or more equations did not get rendered due to their size.
Instances For
smt.grammar!, also answering the parameters and non-terminals it made.
The result is (g, nt₁, …), or ((g, p₁, …), nt₁, …) when there are parameters p₁, ….
Equations
- One or more equations did not get rendered due to their size.
Instances For
smt.grammar! as a do element, binding the grammar, its parameters and its non-terminals.
smt.letGrammar! g ← s (x : Int) where … binds g, and each parameter and non-terminal under its
own name.
Equations
- One or more equations did not get rendered due to their size.