Reputation: 75
I'm trying to create a associate xor chart on Haskell, which to my understanding, should come out true in every instance. Though, when i call my function I get: [True, True, True, False, True, False, True, True]. Can anyone see the mistake I made?
bools = [True, False]
xor_assoc = [ ((r || (p || q)) && not (r || (p && q)))
== ((p || (r || q)) && not (p || (r && q)))
| r <- bools,
p <- bools,
q <- bools]
Upvotes: 2
Views: 188
Reputation: 5406
Are you trying to implement r xor p xor q
? That should have 4 True and 4 False.
[r /= (p /= q) | let bools = [True, False], r <- bools, p <- bools, q <- bools]
Or if you are proving xor is associative, then:
[(r /= (p /= q)) == ((r /= p) /= q) |
let bools = [True, False], r <- bools, p <- bools, q <- bools]
This one does have all 8 True
Upvotes: 0
Reputation: 74334
Your principle is wrong: (r || (p && q)) /= (p || (r && q))
. Counter-example is (p, q, r) = (T, F, F)
where we have
(F || (T && F)) /= (T || (F && F))
(F || F ) /= (T || F )
F /= T
Notably, both (||)
and (&&)
are individually associative, but do not associate around one another.
Upvotes: 3
Reputation: 11208
I dont know what you are doing exactly. But the way you are doing list comprehension, it will generate all possible 2^3
cases. And your predicate returns False
in two of them.
When (p,q,r) = (False,False,True)
then (r || (p && q))
becomes True
hence lhs is False
, whereas (p || (r && q))
is False
and hence rhs is True
.
Similar is the case with (True,False,False)
in which lhs is True
and rhs is False
.
Upvotes: 0