Z3
Loading...
Searching...
No Matches
Probe Class Reference

Public Member Functions

 __init__ (self, probe, ctx=None)
 __deepcopy__ (self, memo={})
 __del__ (self)
 __lt__ (self, other)
 __gt__ (self, other)
 __le__ (self, other)
 __ge__ (self, other)
 __eq__ (self, other)
 __ne__ (self, other)
 __call__ (self, goal)

Data Fields

 ctx = _get_ctx(ctx)
 probe = None

Detailed Description

Probes are used to inspect a goal (aka problem) and collect information that may be used
to decide which solver and/or preprocessing step will be used.

Definition at line 9290 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 9295 of file z3py.py.

9295 def __init__(self, probe, ctx=None):
9296 self.ctx = _get_ctx(ctx)
9297 self.probe = None
9298 if isinstance(probe, ProbeObj):
9299 self.probe = probe
9300 elif isinstance(probe, float):
9301 self.probe = Z3_probe_const(self.ctx.ref(), probe)
9302 elif _is_int(probe):
9303 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
9304 elif isinstance(probe, bool):
9305 if probe:
9306 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
9307 else:
9308 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
9309 else:
9310 if z3_debug():
9311 _z3_assert(isinstance(probe, str), "probe name expected")
9312 try:
9313 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
9314 except Z3Exception:
9315 raise Z3Exception("unknown probe '%s'" % probe)
9316 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
9317
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.

◆ __del__()

__del__ ( self)

Definition at line 9321 of file z3py.py.

9321 def __del__(self):
9322 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
9323 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
9324
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.

Member Function Documentation

◆ __call__()

__call__ ( self,
goal )
Evaluate the probe `self` in the given goal.

>>> p = Probe('size')
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
2.0
>>> g.add(x < 20)
>>> p(g)
3.0
>>> p = Probe('num-consts')
>>> p(g)
1.0
>>> p = Probe('is-propositional')
>>> p(g)
0.0
>>> p = Probe('is-qflia')
>>> p(g)
1.0

Definition at line 9410 of file z3py.py.

9410 def __call__(self, goal):
9411 """Evaluate the probe `self` in the given goal.
9412
9413 >>> p = Probe('size')
9414 >>> x = Int('x')
9415 >>> g = Goal()
9416 >>> g.add(x > 0)
9417 >>> g.add(x < 10)
9418 >>> p(g)
9419 2.0
9420 >>> g.add(x < 20)
9421 >>> p(g)
9422 3.0
9423 >>> p = Probe('num-consts')
9424 >>> p(g)
9425 1.0
9426 >>> p = Probe('is-propositional')
9427 >>> p(g)
9428 0.0
9429 >>> p = Probe('is-qflia')
9430 >>> p(g)
9431 1.0
9432 """
9433 if z3_debug():
9434 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expression expected")
9435 goal = _to_goal(goal)
9436 return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
9437
9438
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 9318 of file z3py.py.

9318 def __deepcopy__(self, memo={}):
9319 return Probe(self.probe, self.ctx)
9320

◆ __eq__()

__eq__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is equal to the value returned by `other`.

>>> p = Probe('size') == 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 9381 of file z3py.py.

9381 def __eq__(self, other):
9382 """Return a probe that evaluates to "true" when the value returned by `self`
9383 is equal to the value returned by `other`.
9384
9385 >>> p = Probe('size') == 2
9386 >>> x = Int('x')
9387 >>> g = Goal()
9388 >>> g.add(x > 0)
9389 >>> g.add(x < 10)
9390 >>> p(g)
9391 1.0
9392 """
9393 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9394
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...

◆ __ge__()

__ge__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is greater than or equal to the value returned by `other`.

>>> p = Probe('size') >= 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 9367 of file z3py.py.

9367 def __ge__(self, other):
9368 """Return a probe that evaluates to "true" when the value returned by `self`
9369 is greater than or equal to the value returned by `other`.
9370
9371 >>> p = Probe('size') >= 2
9372 >>> x = Int('x')
9373 >>> g = Goal()
9374 >>> g.add(x > 0)
9375 >>> g.add(x < 10)
9376 >>> p(g)
9377 1.0
9378 """
9379 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9380
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...

◆ __gt__()

__gt__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is greater than the value returned by `other`.

>>> p = Probe('size') > 10
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
0.0

Definition at line 9339 of file z3py.py.

9339 def __gt__(self, other):
9340 """Return a probe that evaluates to "true" when the value returned by `self`
9341 is greater than the value returned by `other`.
9342
9343 >>> p = Probe('size') > 10
9344 >>> x = Int('x')
9345 >>> g = Goal()
9346 >>> g.add(x > 0)
9347 >>> g.add(x < 10)
9348 >>> p(g)
9349 0.0
9350 """
9351 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9352
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...

◆ __le__()

__le__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is less than or equal to the value returned by `other`.

>>> p = Probe('size') <= 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 9353 of file z3py.py.

9353 def __le__(self, other):
9354 """Return a probe that evaluates to "true" when the value returned by `self`
9355 is less than or equal to the value returned by `other`.
9356
9357 >>> p = Probe('size') <= 2
9358 >>> x = Int('x')
9359 >>> g = Goal()
9360 >>> g.add(x > 0)
9361 >>> g.add(x < 10)
9362 >>> p(g)
9363 1.0
9364 """
9365 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9366
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...

◆ __lt__()

__lt__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is less than the value returned by `other`.

>>> p = Probe('size') < 10
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 9325 of file z3py.py.

9325 def __lt__(self, other):
9326 """Return a probe that evaluates to "true" when the value returned by `self`
9327 is less than the value returned by `other`.
9328
9329 >>> p = Probe('size') < 10
9330 >>> x = Int('x')
9331 >>> g = Goal()
9332 >>> g.add(x > 0)
9333 >>> g.add(x < 10)
9334 >>> p(g)
9335 1.0
9336 """
9337 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9338
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...

◆ __ne__()

__ne__ ( self,
other )
Return a probe that evaluates to "true" when the value returned by `self`
is not equal to the value returned by `other`.

>>> p = Probe('size') != 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
0.0

Definition at line 9395 of file z3py.py.

9395 def __ne__(self, other):
9396 """Return a probe that evaluates to "true" when the value returned by `self`
9397 is not equal to the value returned by `other`.
9398
9399 >>> p = Probe('size') != 2
9400 >>> x = Int('x')
9401 >>> g = Goal()
9402 >>> g.add(x > 0)
9403 >>> g.add(x < 10)
9404 >>> p(g)
9405 0.0
9406 """
9407 p = self.__eq__(other)
9408 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
9409
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.

Field Documentation

◆ ctx

ctx = _get_ctx(ctx)

Definition at line 9296 of file z3py.py.

◆ probe

probe = None

Definition at line 9297 of file z3py.py.