Files
z3/examples/python/socrates.py

35 lines
793 B
Python
Raw Permalink Normal View History

############################################
# Copyright (c) Microsoft Corporation. All Rights Reserved.
#
# all humans are mortal
# Socrates is a human
# so Socrates mortal
############################################
from z3 import *
Object = DeclareSort('Object')
Human = Function('Human', Object, BoolSort())
Mortal = Function('Mortal', Object, BoolSort())
# a well known philosopher
socrates = Const('socrates', Object)
# free variables used in forall must be declared Const in python
x = Const('x', Object)
axioms = [ForAll([x], Implies(Human(x), Mortal(x))),
2016-09-14 21:36:39 +02:00
Human(socrates)]
s = Solver()
s.add(axioms)
2016-09-14 21:36:39 +02:00
2019-08-15 11:39:44 +07:00
print(s.check()) # prints sat so axioms are coherent
2016-09-14 21:36:39 +02:00
# classical refutation
2016-09-14 21:36:39 +02:00
s.add(Not(Mortal(socrates)))
print(s.check()) # prints unsat so socrates is Mortal