module Z3
Constants
- Re
-
A regular expression over some sequence sort - âRe(
String)` for regexes over Strings, `Re(Seq(Int))` for regexes over sequences of Ints.These are deliberately not Ruby Regexps, and nothing here converts between the two in either direction. Rubyâs regexes match unanchored, backtrack, and have backreferences and lookaround; Z3âs denote regular languages, match the whole sequence, and are closed under intersection and complement. Compiling one into the other would quietly change what a pattern means, so a
Z3regex is built out of the combinators here - or out of aStringor a Seq, which âseq.to_re` turns into the regex matching exactly that one value and nothing else.That last conversion is what makes âZ3::Re.Union(âcatâ, âdogâ)` work: anywhere a regex is expected, a Ruby
String, a Ruby Array, aStringExpror aSeqExprmeans âthe regex matching exactly thisâ. The one place it deliberately doesnât happen is matches?, because thatâs where Rubyâs reading and Z3âs differ.â==` comes from
Exprand needs no help here, but itâs worth knowing what it means:Z3decides it as *language equivalence*, not as sameness of terms, so âsolver.prove! (a + b).star + a == a + (b + a).star` comes back proven. Thatâs the thing a backtracking regex engine canât do at all.
Public Instance Methods
Source
# File lib/z3/interface.rb, line 126 def AtLeast(args, k) BoolExpr.AtLeast(args, k) end
Source
# File lib/z3/interface.rb, line 122 def AtMost(args, k) BoolExpr.AtMost(args, k) end
Source
# File lib/z3/interface.rb, line 17 def Bitvec(v, n) BitvecSort.new(n).var(v) end
Source
# File lib/z3/interface.rb, line 36 def Const(v) Expr.sort_for_const(v).from_const(v) end
Source
# File lib/z3/interface.rb, line 86 def Distinct(*args) Expr.Distinct(*args) end
Source
# File lib/z3/interface.rb, line 130 def Exactly(args, k) BoolExpr.Exactly(args, k) end
Source
# File lib/z3/interface.rb, line 74 def Exists(bound, body) Expr.Exists(bound, body) end
Source
# File lib/z3/interface.rb, line 70 def ForAll(bound, body) Expr.ForAll(bound, body) end
âbound` is the variable, or variables, the quantifier binds - the very same ones the body was built out of, which Z3 rebinds inside it. Everywhere else they go on meaning what they always did.
Z3.ForAll(x, f[x] > 0) Z3.Exists([x, y], f[x] == y)
A quantified problem is a different kind of problem: âSolver#check` can return `:unknown`, and on some inputs it doesnât return at all - set âtimeout` or `rlimit` on the solver if that matters.
Source
# File lib/z3/interface.rb, line 52 def FreshFunction(prefix, *sorts) FuncDecl.declare_fresh(prefix, *sorts) end
Same, but Z3 picks a name nothing has used yet by appending a number to âprefix` - for helper functions which shouldnât collide with whatever the caller has named. The number comes from a counter shared by the whole context, so donât count on getting any particular one.
Source
# File lib/z3/interface.rb, line 44 def Function(name, *sorts) FuncDecl.declare(name, *sorts) end
Source
# File lib/z3/interface.rb, line 118 def IfThenElse(a,b,c) BoolExpr.IfThenElse(a,b,c) end
Source
# File lib/z3/interface.rb, line 114 def Implies(a,b) BoolExpr.Implies(a,b) end
Source
# File lib/z3/interface.rb, line 79 def Lambda(bound, body) Expr.Lambda(bound, body) end
An anonymous function, which comes back as an Array - âZ3.Lambda(x, x * 2)` is 6
Source
# File lib/z3/interface.rb, line 145 def set_param(k,v) LowLevel.global_param_set(k,v) end
Source
# File lib/z3/interface.rb, line 137 def version LowLevel.get_version.join(".") end
Source
# File lib/z3/interface.rb, line 141 def version_at_least?(a, b=0, c=0, d=0) (LowLevel.get_version <=> [a, b, c, d]) >= 0 end