2016-09-14 19:10:49 +02:00
|
|
|
############################################
|
|
|
|
|
# Copyright (c) Microsoft Corporation. All Rights Reserved.
|
2016-09-14 10:32:17 -07:00
|
|
|
#
|
|
|
|
|
# all humans are mortal
|
|
|
|
|
# Socrates is a human
|
|
|
|
|
# so Socrates mortal
|
2016-09-14 19:10:49 +02:00
|
|
|
############################################
|
|
|
|
|
|
|
|
|
|
from z3 import *
|
|
|
|
|
|
|
|
|
|
Object = DeclareSort('Object')
|
|
|
|
|
|
|
|
|
|
Human = Function('Human', Object, BoolSort())
|
|
|
|
|
Mortal = Function('Mortal', Object, BoolSort())
|
|
|
|
|
|
2016-09-14 10:32:17 -07:00
|
|
|
# a well known philosopher
|
2016-09-14 19:10:49 +02:00
|
|
|
socrates = Const('socrates', Object)
|
|
|
|
|
|
2016-09-14 10:32:17 -07:00
|
|
|
# free variables used in forall must be declared Const in python
|
2016-09-14 19:10:49 +02:00
|
|
|
x = Const('x', Object)
|
|
|
|
|
|
|
|
|
|
axioms = [ForAll([x], Implies(Human(x), Mortal(x))),
|
2016-09-14 21:36:39 +02:00
|
|
|
Human(socrates)]
|
2016-09-14 19:10:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-14 10:32:17 -07:00
|
|
|
# classical refutation
|
2016-09-14 21:36:39 +02:00
|
|
|
s.add(Not(Mortal(socrates)))
|
2016-09-14 19:10:49 +02:00
|
|
|
|
2016-09-14 10:32:17 -07:00
|
|
|
print(s.check()) # prints unsat so socrates is Mortal
|