code for unevaluated Boolean and conditional expressions
Subject: code for unevaluated Boolean and conditional expressions
From: BIOMATES at telefonica.net
Date: Fri, 5 May 2006 18:20:51 +0200 (MEST)
El mi??, 03-05-2006 a las 20:47 -0600, Robert Dodier escribi??:
> Hello,
>
> I have written some code to handle unevaluated Boolean and
> conditional expressions. Please help me by testing the code
> and/or giving constructive criticism.
Just a story (from http://www.iep.utm.edu/p/prop-log.htm ):
Either cat fur or dog fur was found at the scene of the crime. If dog
fur was found at the scene of the crime, officer Thompson had an
allergy
attack. If cat fur was found at the scene of the crime, then Macavity
is
responsibile for the crime. But officer Thompson didn't have an
allergy
attack, and so therefore Macavity must be responsible for the crime.
Now, let's define some variables:
p: cat fur was found at the scene of the crime,
q: dog fur was found at the scene of the crime,
r: officer Thompson had an allergy attack,
s: Macavity is responsible for the crime
Premise #1: p or q
Premise #2: q => r
Premise #3: p => s
Premise #4: not r
Question: is Macavity responsible for the crime?
/********** begin Maxima session ********/
(%i1) load("~/Desktop/boolsimp.lisp")$
(%i2) /* I define the conditional operator */
"=>"(r,s):= not r or s $ infix("=>") $
(%i4) /* Checks for the validity of */
/* ante => conse by means of */
/* the truth table. */
implies(ante, conse, listvar):=
block([expr,npos,maxn,combis:[],bits,quot,div],
npos: length(listvar),
maxn: 2^npos - 1,
expr: not ante or conse,
for i:0 thru maxn do(
bits:[],
quot:i,
for j:1 thru npos do(
div: divide(quot, 2),
quot: div[1],
bits: cons(listvar[j]=div[2],bits) ),
combis: cons( subst([1=true,0=false],bits), combis)),
apply("and", makelist(subst(k,expr),k,combis)) )$
(%i5) /* Let's know who's the criminal */
implies((p or q) and (q => r) and (p => s) and not r,s,
[p,q,r,s]);
(%o5) true
/********** end Maxima session ********/
Lawyers will find your 'boolsimp' package very useful !
Best wishes.
--
Mario Rodriguez Riotorto
www.biomates.net