本文整理匯總了Python中z3.Not方法的典型用法代碼示例。如果您正苦於以下問題:Python z3.Not方法的具體用法?Python z3.Not怎麽用?Python z3.Not使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類z3
的用法示例。
在下文中一共展示了z3.Not方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _seq_as_one
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [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: generate_contract_objects
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def generate_contract_objects(contract_to_build_data, hash_to_func_name):
contract_name_to_contract = {}
lib_name_to_address = {}
# filename = combined_json_data['sourceList'][0]
# assert len(combined_json_data['sourceList']) == 1, 'Not a flat file!'
utils.get_next_lib_address()
for contract_name, contract_json_data in contract_to_build_data.items():
src_code = contract_json_data['source']
runtime_bytecode = contract_json_data['deployedBytecode']
bytecode = contract_json_data['bytecode']
for lib_name in find_library_names(bytecode) | find_library_names(runtime_bytecode):
lib_name_to_address.setdefault(lib_name, utils.get_next_lib_address())
# runtime_bytecode = link_libraries(filename, lib_name_to_address, runtime_bytecode)
# bytecode = link_libraries(filename, lib_name_to_address, bytecode)
abi = contract_json_data['abi']
runtime_src_map = contract_json_data['deployedSourceMap']
src_map = contract_json_data['sourceMap']
contract = SolidityContract(contract_name, abi, bytecode,
runtime_bytecode, src_map,
runtime_src_map, src_code, hash_to_func_name)
contract_name_to_contract[contract_name] = contract
return contract_name_to_contract, lib_name_to_address
示例3: construct_axioms
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [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
示例4: try_make_simple_if_else
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def try_make_simple_if_else(
self, node1, node2, nodes_to_check, nodes_to_remove
):
log_debug("try_make_simple_if_else")
cond1 = node1.condition
cond2 = node2.condition
if is_true(simplify(cond1 == Not(cond2))):
log_debug(f"found a simple if/else match")
if cond1.decl().name() == "not":
node2[False] = node1[True]
nodes_to_check.remove(node2)
nodes_to_remove.append(node1)
else:
node1[False] = node2[True]
nodes_to_remove.append(node2)
return True
return False
示例5: _convert_to_while_loop
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [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]
示例6: neg
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def neg(self, cond):
b = to_bool(cond)
if b is True: return self.false
if b is False: return self.true
return z3.Not(cond, self.ctx)
示例7: _initialize
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def _initialize(self, dag):
""" create boolean variables for each qubit and apply qb == 0 condition
Args:
dag (DAGCircuit): input DAG to get qubits from
"""
for qbt in dag.qubits:
self.gatenum[qbt.index] = 0
self.variables[qbt.index] = []
self.gatecache[qbt.index] = []
self.varnum[qbt.index] = dict()
x = self._gen_variable(qbt.index)
self.solver.add(Not(x))
示例8: _add_postconditions
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def _add_postconditions(self, gate, ctrl_ones, trgtqb, trgtvar):
""" create boolean variables for each qubit the gate is applied to
and apply the relevant post conditions.
a gate rotating out of the z-basis will not have any valid
post-conditions, in which case the qubit state is unknown
Args:
gate (Gate): gate to inspect
ctrl_ones (BoolRef): z3 condition asserting all control qubits to 1
trgtqb (list((QuantumRegister, int))): list of target qubits
trgtvar (list(BoolRef)): z3 variables corresponding to latest state
of target qubits
"""
new_vars = []
for qbt in trgtqb:
new_vars.append(self._gen_variable(qbt.index))
try:
self.solver.add(
Implies(ctrl_ones, gate._postconditions(*(trgtvar + new_vars)))
)
except AttributeError:
pass
for i, tvar in enumerate(trgtvar):
self.solver.add(
Implies(Not(ctrl_ones), new_vars[i] == tvar)
)
示例9: _test_gate
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [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
示例10: equiv
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def equiv(z3_expr1, z3_expr2):
s = z3.Solver()
s.add(z3.Not(z3_expr1 == z3_expr2))
return s.check() == z3.unsat
示例11: get_library_names
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def get_library_names(combined_json_data):
lib_names = []
filename = combined_json_data['sourceList'][0]
assert len(combined_json_data['sourceList']) == 1, 'Not a flat file!'
pattern = re.compile('(' + filename + ':)([a-zA-Z0-9]+)(_+)')
hash_pattern = re.compile('__\$([a-f0-9]{34})\$__')
hash_to_contract_name = { ethereum.utils.sha3(c).hex()[:34]: c for c in combined_json_data['contracts'].keys() }
for contract_name, contract_data in combined_json_data['contracts'].items():
lib_names.extend([lib_name for (_, lib_name, _) in re.findall(pattern, contract_data['bin-runtime'])])
hash_matches = re.findall(hash_pattern, contract_data['bin-runtime'])
for hash_match in hash_matches:
lib_full_name = hash_to_contract_name[hash_match]
lib_names.append(lib_full_name.split(':')[-1])
return set(lib_names)
示例12: is_true
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def is_true(cond):
# NOTE: This differs from `not is_false(cond)`, which corresponds to "may be true"
return is_false(z3.Not(cond))
示例13: compute_reaching_states
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def compute_reaching_states(bv, mlil, from_bb, to_bb, states):
visitor = ConditionVisitor(bv)
path = next(dfs_paths_backward(from_bb, to_bb))
reaching_conditions = []
cond = None
for edge in path:
terminator = edge.source[-1]
# assert terminator.operation == MediumLevelILOperation.MLIL_IF
if terminator.operation == MediumLevelILOperation.MLIL_IF:
cond = terminator.condition
if cond.operation == MediumLevelILOperation.MLIL_VAR:
cond = mlil.get_var_definitions(cond.src)[0].src
condition = visitor.visit(cond)
if edge.type == BranchType.TrueBranch:
reaching_conditions.append(condition)
else:
reaching_conditions.append(z3.Not(condition))
solver = z3.Solver()
for condition in reaching_conditions:
solver.add(condition)
reaching_states = set()
if cond.operation == MediumLevelILOperation.MLIL_VAR:
cond = mlil.get_var_definitions(cond.src)[0].src
symbolic_state = make_variable(cond.left.src)
for state in states:
solver.push()
solver.add(symbolic_state == state)
if solver.check() == z3.sat:
reaching_states.add(state)
solver.pop()
return list(reaching_states)
示例14: __ne__
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def __ne__(l, r):
return Not(Eq(l, fexpr_cast(r)))
# The & operator
示例15: remapLabels
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import Not [as 別名]
def remapLabels(self, policy, writer):
return Mod(
self.left.remapLabels(policy, writer)
, self.right.remapLabels(policy, writer))
# Not sure if bitwise operations are supported by Z3?