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 9305 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 9310 of file z3py.py.

9310 def __init__(self, probe, ctx=None):
9311 self.ctx = _get_ctx(ctx)
9312 self.probe = None
9313 if isinstance(probe, ProbeObj):
9314 self.probe = probe
9315 elif isinstance(probe, float):
9316 self.probe = Z3_probe_const(self.ctx.ref(), probe)
9317 elif _is_int(probe):
9318 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
9319 elif isinstance(probe, bool):
9320 if probe:
9321 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
9322 else:
9323 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
9324 else:
9325 if z3_debug():
9326 _z3_assert(isinstance(probe, str), "probe name expected")
9327 try:
9328 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
9329 except Z3Exception:
9330 raise Z3Exception("unknown probe '%s'" % probe)
9331 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
9332
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 9336 of file z3py.py.

9336 def __del__(self):
9337 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
9338 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
9339
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 9425 of file z3py.py.

9425 def __call__(self, goal):
9426 """Evaluate the probe `self` in the given goal.
9427
9428 >>> p = Probe('size')
9429 >>> x = Int('x')
9430 >>> g = Goal()
9431 >>> g.add(x > 0)
9432 >>> g.add(x < 10)
9433 >>> p(g)
9434 2.0
9435 >>> g.add(x < 20)
9436 >>> p(g)
9437 3.0
9438 >>> p = Probe('num-consts')
9439 >>> p(g)
9440 1.0
9441 >>> p = Probe('is-propositional')
9442 >>> p(g)
9443 0.0
9444 >>> p = Probe('is-qflia')
9445 >>> p(g)
9446 1.0
9447 """
9448 if z3_debug():
9449 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expression expected")
9450 goal = _to_goal(goal)
9451 return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
9452
9453
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 9333 of file z3py.py.

9333 def __deepcopy__(self, memo={}):
9334 return Probe(self.probe, self.ctx)
9335

◆ __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 9396 of file z3py.py.

9396 def __eq__(self, other):
9397 """Return a probe that evaluates to "true" when the value returned by `self`
9398 is equal to the value returned by `other`.
9399
9400 >>> p = Probe('size') == 2
9401 >>> x = Int('x')
9402 >>> g = Goal()
9403 >>> g.add(x > 0)
9404 >>> g.add(x < 10)
9405 >>> p(g)
9406 1.0
9407 """
9408 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9409
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 9382 of file z3py.py.

9382 def __ge__(self, other):
9383 """Return a probe that evaluates to "true" when the value returned by `self`
9384 is greater than or equal to the value returned by `other`.
9385
9386 >>> p = Probe('size') >= 2
9387 >>> x = Int('x')
9388 >>> g = Goal()
9389 >>> g.add(x > 0)
9390 >>> g.add(x < 10)
9391 >>> p(g)
9392 1.0
9393 """
9394 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9395
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 9354 of file z3py.py.

9354 def __gt__(self, other):
9355 """Return a probe that evaluates to "true" when the value returned by `self`
9356 is greater than the value returned by `other`.
9357
9358 >>> p = Probe('size') > 10
9359 >>> x = Int('x')
9360 >>> g = Goal()
9361 >>> g.add(x > 0)
9362 >>> g.add(x < 10)
9363 >>> p(g)
9364 0.0
9365 """
9366 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9367
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 9368 of file z3py.py.

9368 def __le__(self, other):
9369 """Return a probe that evaluates to "true" when the value returned by `self`
9370 is less than or equal to the value returned by `other`.
9371
9372 >>> p = Probe('size') <= 2
9373 >>> x = Int('x')
9374 >>> g = Goal()
9375 >>> g.add(x > 0)
9376 >>> g.add(x < 10)
9377 >>> p(g)
9378 1.0
9379 """
9380 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9381
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 9340 of file z3py.py.

9340 def __lt__(self, other):
9341 """Return a probe that evaluates to "true" when the value returned by `self`
9342 is less than the value returned by `other`.
9343
9344 >>> p = Probe('size') < 10
9345 >>> x = Int('x')
9346 >>> g = Goal()
9347 >>> g.add(x > 0)
9348 >>> g.add(x < 10)
9349 >>> p(g)
9350 1.0
9351 """
9352 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
9353
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 9410 of file z3py.py.

9410 def __ne__(self, other):
9411 """Return a probe that evaluates to "true" when the value returned by `self`
9412 is not equal to the value returned by `other`.
9413
9414 >>> p = Probe('size') != 2
9415 >>> x = Int('x')
9416 >>> g = Goal()
9417 >>> g.add(x > 0)
9418 >>> g.add(x < 10)
9419 >>> p(g)
9420 0.0
9421 """
9422 p = self.__eq__(other)
9423 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
9424
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 9311 of file z3py.py.

◆ probe

probe = None

Definition at line 9312 of file z3py.py.