Re: Boolean algebra?
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Boolean algebra?
- From: Jack K. Cohen <jkc at keller.mines.colorado.edu>
- Date: Tue, 29 Sep 92 13:50:49 -0600
Blush. How about my article in the Mathematica Journal, V2, #1.
Although actually, 2.0 broke my code by changing the functionality
of PolynomialMod. To avoid answering 1/2 dozen requests, the
updated modules are below
... STOP READING HERE, IF YOU DON'T CARE ABOUT THIS TOPIC ...
--------
(*
Author: Jack K. Cohen, Colorado School of Mines, 1992.
*)
BeginPackage["Logic`"];
(* Declaration of public function names in logic package *)
not::usage = "not[x]"
and::usage = "x ~and~ y"
xor::usage = "x ~xor~ y (exclusive or)"
or::usage = "x ~or~ y"
implies::usage = "x ~implies~ y"
iff::usage = "x ~iff~ y "
reduce::usage = "reduce[x] (simplifies expressions)"
Begin["`private`"];
Unprotect[Power]
Power[a_, n_Integer] := a /; n > 1
Protect[Power]
reduce[x_] := FixedPoint[PolynomialMod[#, 2]&, x]
not[x_] := 1 + x
and[x_, y_] := x y
xor[x_, y_] := x + y
or[x_, y_] := x + y + x y
implies[x_, y_] := 1 + x + x y
iff[x_, y_] := 1 + x + y
End[];
Endpackage[];
--------
(*
Author: Jack K. Cohen, Colorado School of Mines, 1992.
*)
BeginPackage["Set`"];
(* Declaration of public function names in set theory package *)
c::usage = "c[x] (complement of x)"
i::usage = "x ~i~ y (intersection of x and y)"
s::usage = "x ~s~ y (symmetric difference of x and y: (x-y) U
(y-x))"
u::usage = "x ~u~ y (union of x and y)"
d::usage = "x ~d~ y (difference of x and y: (x - y))"
ss::usage = "x ~ss~ y (x is a subset of y)"
eq::usage = "x ~eq~ y (x equals y)"
intersection::usage = "intersection[a, n] (a[1] ~i~ a[2] ~i~ ...
~i~ a[n])"
union::usage = "union[a, n] (a[1] ~u~ a[2] ~u~ ... ~u~ a[n])"
reduce::usage = "reduce[x] (simplifies expressions)"
Begin["`private`"];
Unprotect[Power]
Power[a_, n_Integer] := a /; n > 1
Protect[Power]
reduce[x_] := Expand[Simplify[Mod[x, 2]]]
c[x_] := 1 + x
i[x_, y_] := x y
s[x_, y_] := x + y
u[x_, y_] := x + y + x y
d[x_, y_] := x + x y
ss[x_, y_] := 1 + x + x y
eq[x_, y_] := 1 + x + y
intersection[a_ + b_Integer:0, n_] := reduce[Product[a[i] + b, {i,
n}]]
union[a_ + b_Integer:0, n_] :=
Block[{sum = 0, k},
Do [
sum = sum ~u~ (a[k] + b),
{k, n}];
Return[reduce[sum]]
]
End[];
Endpackage[];