本文整理汇总了Python中z3.And方法的典型用法代码示例。如果您正苦于以下问题:Python z3.And方法的具体用法?Python z3.And怎么用?Python z3.And使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类z3
的用法示例。
在下文中一共展示了z3.And方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _seq_as_one
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _seq_as_one(self, sequence):
""" use z3 solver to determine if the gates in the sequence are either
all executed or none of them are executed, based on control qubits
(consider sequences of length 2 for now)
Args:
sequence (list(DAGNode)): gate sequence to inspect
Returns:
bool: if gate sequence is only executed completely or not at all
"""
assert len(sequence) == 2
ctrlvar1 = self._seperate_ctrl_trgt(sequence[0])[1]
ctrlvar2 = self._seperate_ctrl_trgt(sequence[1])[1]
self.solver.push()
self.solver.add(
Or(
And(And(*ctrlvar1), Not(And(*ctrlvar2))),
And(Not(And(*ctrlvar1)), And(*ctrlvar2))
)
)
res = self.solver.check() == unsat
self.solver.pop()
return res
示例2: construct_axioms
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def construct_axioms(variables): # List[StatVar]
_axioms = []
for var in variables:
# A variable must be continuous or categorical, but not both.
_axioms.append(z3.And(z3.Or(continuous(var).__z3__, categorical(var).__z3__),
z3.Not(z3.And(continuous(var).__z3__, categorical(var).__z3__))))
# If a variable is an explanatory variable and all explanatory variables are categorical,
# then the variable must be categorical.
# It isn't clear how to reason about whether a variable is an explanatory or explained variable.
# _axioms.append(z3.Implies(all_x_variables_categorical(var).__z3__, categorical(var).__z3__))
# Not sure how to reason about test properties like one_x_variable and one_y_variable.
# _axioms.append(z3.Not(z3.And(one_x_variable(var).__z3__, one_y_variable(var).__z3__)))
# If a variable is normal, then it cannot be categorical.
_axioms.append(z3.Implies(normal(var).__z3__, z3.Not(categorical(var).__z3__)))
# If a variable is continuous or ordinal, it must be continuous.
_axioms.append(z3.Implies(continuous_or_ordinal(var).__z3__, continuous(var).__z3__))
# If a variable has two categories, then it must be categorical.
# _axioms.append(z3.Implies(two_x_variable_categories(var).__z3__, categorical(var).__z3__))
return _axioms
示例3: find_name_for_bit_at_index
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def find_name_for_bit_at_index(index, bit):
solver = z3.Solver()
NAME_LENGTH = 12 # arbitrary
name = [z3.BitVec("c%d" % i, 32) for i in range(NAME_LENGTH)]
for i in range(len(name)):
solver.add(z3.And(name[i] > 0, name[i] <= 0xff))
h1 = hash1(name)
solver.add(h1 == index)
h2 = hash2(name)
solver.add(h2 == bit)
h3 = hash3(name)
solver.add(z3.Extract(15, 0, h3) == h2) # for simplicity
if solver.check() == z3.sat:
return "".join(chr(solver.model()[c].as_long()) for c in name).encode("latin-1")
示例4: _convert_to_while_loop
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _convert_to_while_loop(
self, node: MediumLevelILAstLoopNode, while_condition
):
log_debug(f"{node} is a while loop")
node.loop_type = "while"
node.condition = reduce(
And, Tactic("ctx-solver-simplify")(Not(while_condition))[0]
)
break_cond = node.body.nodes[0]
if break_cond[False] is not None:
node.body._nodes[0] = break_cond[False]
# Flatten condition nodes that have the same condition
# as the loop condition
for idx, child in enumerate(node.body.nodes):
if (
isinstance(child, MediumLevelILAstCondNode)
and is_true(simplify(child.condition == node.condition))
and child[False] is None
):
node.body._nodes[idx] = child[True]
示例5: all
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def all(self, *conds): return self.bfold(conds, z3.And, True, False)
示例6: _test_gate
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _test_gate(self, gate, ctrl_ones, trgtvar):
""" use z3 sat solver to determine triviality of gate
Args:
gate (Gate): gate to inspect
ctrl_ones (BoolRef): z3 condition asserting all control qubits to 1
trgtvar (list(BoolRef)): z3 variables corresponding to latest state
of target qubits
Returns:
bool: if gate is trivial
"""
trivial = False
self.solver.push()
try:
triv_cond = gate._trivial_if(*trgtvar)
except AttributeError:
self.solver.add(ctrl_ones)
trivial = self.solver.check() == unsat
else:
if isinstance(triv_cond, bool):
if triv_cond and len(trgtvar) == 1:
self.solver.add(And(ctrl_ones, Not(trgtvar[0])))
sol1 = self.solver.check() == unsat
self.solver.pop()
self.solver.push()
self.solver.add(And(ctrl_ones, trgtvar[0]))
sol2 = self.solver.check() == unsat
trivial = sol1 or sol2
else:
self.solver.add(And(ctrl_ones, Not(triv_cond)))
trivial = self.solver.check() == unsat
self.solver.pop()
return trivial
示例7: _traverse_dag
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _traverse_dag(self, dag):
""" traverse DAG in topological order
for each gate check: if any control is 0, or
if triviality conditions are satisfied
if yes remove gate from dag
apply postconditions of gate
Args:
dag (DAGCircuit): input DAG to optimize in place
"""
for node in dag.topological_op_nodes():
gate = node.op
_, ctrlvar, trgtqb, trgtvar = self._seperate_ctrl_trgt(node)
ctrl_ones = And(*ctrlvar)
trivial = self._test_gate(gate, ctrl_ones, trgtvar)
if trivial:
dag.remove_op_node(node)
elif self.size > 1:
for qbt in node.qargs:
self.gatecache[qbt.index].append(node)
self.varnum[qbt.index][node] = self.gatenum[qbt.index]-1
for qbt in node.qargs:
if len(self.gatecache[qbt.index]) >= self.size:
self._multigate_opt(dag, qbt.index)
self._add_postconditions(gate, ctrl_ones, trgtqb, trgtvar)
示例8: scheduling_constraints
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def scheduling_constraints(self):
"""
DAG scheduling constraints optimization
Sets overlap indicator variables
"""
for gate in self.gate_start_time:
for dep_gate in self.dag.successors(gate):
if not dep_gate.type == 'op':
continue
if isinstance(dep_gate.op, Measure):
continue
if isinstance(dep_gate.op, Barrier):
continue
fin_g = self.gate_start_time[gate] + self.gate_duration[gate]
self.opt.add(self.gate_start_time[dep_gate] > fin_g)
for g_1 in self.xtalk_overlap_set:
for g_2 in self.xtalk_overlap_set[g_1]:
if len(g_2.qargs) == 2 and self.gate_id[g_1] > self.gate_id[g_2]:
# Symmetry breaking: create only overlap variable for a pair
# of gates
continue
s_1 = self.gate_start_time[g_1]
f_1 = s_1 + self.gate_duration[g_1]
s_2 = self.gate_start_time[g_2]
f_2 = s_2 + self.gate_duration[g_2]
# This constraint enforces full or zero overlap between two gates
before = (f_1 < s_2)
after = (f_2 < s_1)
overlap1 = And(s_2 <= s_1, f_1 <= f_2)
overlap2 = And(s_1 <= s_2, f_2 <= f_1)
self.opt.add(Or(before, after, overlap1, overlap2))
intervals_overlap = And(s_2 <= f_1, s_1 <= f_2)
self.opt.add(self.overlap_indicator[g_1][g_2] == intervals_overlap)
示例9: _gen_path_constraints
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _gen_path_constraints(self, translator, expr, expected):
"""Generate path constraint from @expr. Handle special case with
generated loc_keys
"""
out = []
expected = canonize_to_exprloc(self._ircfg.loc_db, expected)
expected_is_loc_key = expected.is_loc()
for consval in possible_values(expr):
value = canonize_to_exprloc(self._ircfg.loc_db, consval.value)
if expected_is_loc_key and value != expected:
continue
if not expected_is_loc_key and value.is_loc_key():
continue
conds = z3.And(*[translator.from_expr(cond.to_constraint())
for cond in consval.constraints])
if expected != value:
conds = z3.And(
conds,
translator.from_expr(
ExprAssign(value,
expected))
)
out.append(conds)
if out:
conds = z3.Or(*out)
else:
# Ex: expr: lblgen1, expected: 0x1234
# -> Avoid inconsistent solution lblgen1 = 0x1234
conds = translator.from_expr(self.unsat_expr)
return conds
示例10: get_wstate_z3vars
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def get_wstate_z3vars(wstate):
r = get_z3vars(z3.simplify(z3.And(wstate.constraints)))
for address, gstate in wstate.address_to_account.items():
r.update(get_z3vars(z3.simplify(gstate.storage.storage)))
return r
示例11: _ascii_printable
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _ascii_printable(x):
return z3.And(0x21 <= x, x <= 0x7e) # enforces that byte is printable ascii
示例12: _generate_ascii_printable_string
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def _generate_ascii_printable_string(base_name, size, solver):
# establishes z3 variable names for bytes of the input string
bytes = [z3.BitVec('%s%d' % (base_name, i), 8) for i in range(size)]
# adds the constraint that the bytes are printable ascii
solver.add(z3.And([_ascii_printable(byte) for byte in bytes]))
return bytes
示例13: __and__
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def __and__(l, r):
return And(l, fexpr_cast(r))
示例14: __rand__
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def __rand__(r, l):
return And(fexpr_cast(l), r)
# The | operator
示例15: z3Node
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import And [as 别名]
def z3Node(self):
return z3.And(self.left.z3Node(), self.right.z3Node())