mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 13:29:11 +00:00 
			
		
		
		
	Create socrates.py
Classical syllogism in Z3. Many samples talks about integer, reals. Not much sample available on non integer things.
This commit is contained in:
		
							parent
							
								
									9f77759cd6
								
							
						
					
					
						commit
						a7e3a9df5a
					
				
					 1 changed files with 33 additions and 0 deletions
				
			
		
							
								
								
									
										33
									
								
								examples/python/socrates.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								examples/python/socrates.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
############################################
 | 
			
		||||
# Copyright (c) Microsoft Corporation. All Rights Reserved.
 | 
			
		||||
# 
 | 
			
		||||
# all humans are mortal
 | 
			
		||||
# Socrates is a human
 | 
			
		||||
# so Socrates mortal 
 | 
			
		||||
############################################
 | 
			
		||||
 | 
			
		||||
from z3 import *
 | 
			
		||||
 | 
			
		||||
set_param(proof=True)
 | 
			
		||||
 | 
			
		||||
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))), 
 | 
			
		||||
          Human(socrates) == True]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
s = Solver()
 | 
			
		||||
s.add(axioms)
 | 
			
		||||
# classical refutation
 | 
			
		||||
s.add(Mortal(socrates) == False)
 | 
			
		||||
 | 
			
		||||
print(s.check()) # prints unsat so socrates is Mortal
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue