Simplifying boolean algebra without using certain operations
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
when I use Simplify
or FullSimplify
in Mathematica it often simplifies it using all the existing boolean operations. For example, consider the following:
FullSimplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Simplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Both the code segment above are going to output the following:
! (x ⊻ z ⊻ (x && y) ⊻ (z && y) ⊻ (z && x && y))
I do not want the Xor
gates in the solution. Is there a way we can give restrictions to the two functions, such that it gives the simplest possible formula but without using other gates except Or
, Not
, and And
.
I've tried BooleanMinimize
with "CNF" and "DNF", but these two things do not mean that the formula is the simplest (in terms of numbers of operation). I simply want a "Simplify" that does not use other operators except Not
, And
, and Or
. Thanks!
functions simplifying-expressions
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
6
down vote
favorite
when I use Simplify
or FullSimplify
in Mathematica it often simplifies it using all the existing boolean operations. For example, consider the following:
FullSimplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Simplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Both the code segment above are going to output the following:
! (x ⊻ z ⊻ (x && y) ⊻ (z && y) ⊻ (z && x && y))
I do not want the Xor
gates in the solution. Is there a way we can give restrictions to the two functions, such that it gives the simplest possible formula but without using other gates except Or
, Not
, and And
.
I've tried BooleanMinimize
with "CNF" and "DNF", but these two things do not mean that the formula is the simplest (in terms of numbers of operation). I simply want a "Simplify" that does not use other operators except Not
, And
, and Or
. Thanks!
functions simplifying-expressions
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You may not be aware of an optional argument toSimplify
calledExcludedForms
. That can let you tellSimplify
thatXor
cannot be considered as part of the solution.Simplify
usesLeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without usingXor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?
– Bill
Sep 8 at 17:28
The expression may not be necessarily simpler than usingXor
. However what I want here is that the "simplest possible form" withoutXor
. Which can be solved usingExcludedForms
argument. Thank you for your reply.
– Naufal Fikri
Sep 9 at 8:31
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
when I use Simplify
or FullSimplify
in Mathematica it often simplifies it using all the existing boolean operations. For example, consider the following:
FullSimplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Simplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Both the code segment above are going to output the following:
! (x ⊻ z ⊻ (x && y) ⊻ (z && y) ⊻ (z && x && y))
I do not want the Xor
gates in the solution. Is there a way we can give restrictions to the two functions, such that it gives the simplest possible formula but without using other gates except Or
, Not
, and And
.
I've tried BooleanMinimize
with "CNF" and "DNF", but these two things do not mean that the formula is the simplest (in terms of numbers of operation). I simply want a "Simplify" that does not use other operators except Not
, And
, and Or
. Thanks!
functions simplifying-expressions
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
when I use Simplify
or FullSimplify
in Mathematica it often simplifies it using all the existing boolean operations. For example, consider the following:
FullSimplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Simplify[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
Both the code segment above are going to output the following:
! (x ⊻ z ⊻ (x && y) ⊻ (z && y) ⊻ (z && x && y))
I do not want the Xor
gates in the solution. Is there a way we can give restrictions to the two functions, such that it gives the simplest possible formula but without using other gates except Or
, Not
, and And
.
I've tried BooleanMinimize
with "CNF" and "DNF", but these two things do not mean that the formula is the simplest (in terms of numbers of operation). I simply want a "Simplify" that does not use other operators except Not
, And
, and Or
. Thanks!
functions simplifying-expressions
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Sep 8 at 16:18
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Sep 8 at 13:54


Naufal Fikri
1334
1334
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Naufal Fikri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You may not be aware of an optional argument toSimplify
calledExcludedForms
. That can let you tellSimplify
thatXor
cannot be considered as part of the solution.Simplify
usesLeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without usingXor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?
– Bill
Sep 8 at 17:28
The expression may not be necessarily simpler than usingXor
. However what I want here is that the "simplest possible form" withoutXor
. Which can be solved usingExcludedForms
argument. Thank you for your reply.
– Naufal Fikri
Sep 9 at 8:31
add a comment |Â
You may not be aware of an optional argument toSimplify
calledExcludedForms
. That can let you tellSimplify
thatXor
cannot be considered as part of the solution.Simplify
usesLeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without usingXor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?
– Bill
Sep 8 at 17:28
The expression may not be necessarily simpler than usingXor
. However what I want here is that the "simplest possible form" withoutXor
. Which can be solved usingExcludedForms
argument. Thank you for your reply.
– Naufal Fikri
Sep 9 at 8:31
You may not be aware of an optional argument to
Simplify
called ExcludedForms
. That can let you tell Simplify
that Xor
cannot be considered as part of the solution. Simplify
uses LeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without using Xor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?– Bill
Sep 8 at 17:28
You may not be aware of an optional argument to
Simplify
called ExcludedForms
. That can let you tell Simplify
that Xor
cannot be considered as part of the solution. Simplify
uses LeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without using Xor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?– Bill
Sep 8 at 17:28
The expression may not be necessarily simpler than using
Xor
. However what I want here is that the "simplest possible form" without Xor
. Which can be solved using ExcludedForms
argument. Thank you for your reply.– Naufal Fikri
Sep 9 at 8:31
The expression may not be necessarily simpler than using
Xor
. However what I want here is that the "simplest possible form" without Xor
. Which can be solved using ExcludedForms
argument. Thank you for your reply.– Naufal Fikri
Sep 9 at 8:31
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
You could try giving Simplify
a ComplexityFunction
option that discourages Xor
:
Simplify[
!(x&&y&&z)&&!(x&&!y&&!z)&&!(!x&&!y&&z),
ComplexityFunction->(LeafCount[#]+10000Count[#, _Xor,0,Infinity]&)
]
(x && ! y && z) || (! x && (y || ! z)) || (y && ! z)
Addendum
(The OP asked about another expression)
I don't know which boolean transformations are built in to Simplify
/FullSimplify
, but you can add more with the option TransformationFunctions
. So:
FullSimplify[
!u && !v && !w && !x,
ComplexityFunction -> (LeafCount[#]+10000Count[#, _Xor,0,Infinity]&),
TransformationFunctions -> Automatic, BooleanConvert[#,"OR"]&
]
(* !(u || v || w || x) *)
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps(!u && !v && !w && !x)
while in fact it can be simplified to!(u || v || w || x)
, assuming thatLeafCount[!u] = 2
(due to the terms!u
andu
)... Is my understandingofLeafCount
wrong?
– Naufal Fikri
2 days ago
add a comment |Â
up vote
2
down vote
perhaps BooleanMinimize
?
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
(x && ! y && z) || (! x && y) || (! x && ! z) || (y && ! z)
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z), "CNF"]
(! x || ! y || ! z) && (! x || y || z) && (x || y || ! z)
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize(x || (y && t)) && z
then usingBooleanMinimize
gives(t || x) && (x || y) && z
and(t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.
– Naufal Fikri
Sep 8 at 16:17
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
You could try giving Simplify
a ComplexityFunction
option that discourages Xor
:
Simplify[
!(x&&y&&z)&&!(x&&!y&&!z)&&!(!x&&!y&&z),
ComplexityFunction->(LeafCount[#]+10000Count[#, _Xor,0,Infinity]&)
]
(x && ! y && z) || (! x && (y || ! z)) || (y && ! z)
Addendum
(The OP asked about another expression)
I don't know which boolean transformations are built in to Simplify
/FullSimplify
, but you can add more with the option TransformationFunctions
. So:
FullSimplify[
!u && !v && !w && !x,
ComplexityFunction -> (LeafCount[#]+10000Count[#, _Xor,0,Infinity]&),
TransformationFunctions -> Automatic, BooleanConvert[#,"OR"]&
]
(* !(u || v || w || x) *)
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps(!u && !v && !w && !x)
while in fact it can be simplified to!(u || v || w || x)
, assuming thatLeafCount[!u] = 2
(due to the terms!u
andu
)... Is my understandingofLeafCount
wrong?
– Naufal Fikri
2 days ago
add a comment |Â
up vote
5
down vote
accepted
You could try giving Simplify
a ComplexityFunction
option that discourages Xor
:
Simplify[
!(x&&y&&z)&&!(x&&!y&&!z)&&!(!x&&!y&&z),
ComplexityFunction->(LeafCount[#]+10000Count[#, _Xor,0,Infinity]&)
]
(x && ! y && z) || (! x && (y || ! z)) || (y && ! z)
Addendum
(The OP asked about another expression)
I don't know which boolean transformations are built in to Simplify
/FullSimplify
, but you can add more with the option TransformationFunctions
. So:
FullSimplify[
!u && !v && !w && !x,
ComplexityFunction -> (LeafCount[#]+10000Count[#, _Xor,0,Infinity]&),
TransformationFunctions -> Automatic, BooleanConvert[#,"OR"]&
]
(* !(u || v || w || x) *)
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps(!u && !v && !w && !x)
while in fact it can be simplified to!(u || v || w || x)
, assuming thatLeafCount[!u] = 2
(due to the terms!u
andu
)... Is my understandingofLeafCount
wrong?
– Naufal Fikri
2 days ago
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
You could try giving Simplify
a ComplexityFunction
option that discourages Xor
:
Simplify[
!(x&&y&&z)&&!(x&&!y&&!z)&&!(!x&&!y&&z),
ComplexityFunction->(LeafCount[#]+10000Count[#, _Xor,0,Infinity]&)
]
(x && ! y && z) || (! x && (y || ! z)) || (y && ! z)
Addendum
(The OP asked about another expression)
I don't know which boolean transformations are built in to Simplify
/FullSimplify
, but you can add more with the option TransformationFunctions
. So:
FullSimplify[
!u && !v && !w && !x,
ComplexityFunction -> (LeafCount[#]+10000Count[#, _Xor,0,Infinity]&),
TransformationFunctions -> Automatic, BooleanConvert[#,"OR"]&
]
(* !(u || v || w || x) *)
You could try giving Simplify
a ComplexityFunction
option that discourages Xor
:
Simplify[
!(x&&y&&z)&&!(x&&!y&&!z)&&!(!x&&!y&&z),
ComplexityFunction->(LeafCount[#]+10000Count[#, _Xor,0,Infinity]&)
]
(x && ! y && z) || (! x && (y || ! z)) || (y && ! z)
Addendum
(The OP asked about another expression)
I don't know which boolean transformations are built in to Simplify
/FullSimplify
, but you can add more with the option TransformationFunctions
. So:
FullSimplify[
!u && !v && !w && !x,
ComplexityFunction -> (LeafCount[#]+10000Count[#, _Xor,0,Infinity]&),
TransformationFunctions -> Automatic, BooleanConvert[#,"OR"]&
]
(* !(u || v || w || x) *)
edited yesterday
answered Sep 8 at 17:24


Carl Woll
56.3k272147
56.3k272147
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps(!u && !v && !w && !x)
while in fact it can be simplified to!(u || v || w || x)
, assuming thatLeafCount[!u] = 2
(due to the terms!u
andu
)... Is my understandingofLeafCount
wrong?
– Naufal Fikri
2 days ago
add a comment |Â
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps(!u && !v && !w && !x)
while in fact it can be simplified to!(u || v || w || x)
, assuming thatLeafCount[!u] = 2
(due to the terms!u
andu
)... Is my understandingofLeafCount
wrong?
– Naufal Fikri
2 days ago
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps
(!u && !v && !w && !x)
while in fact it can be simplified to !(u || v || w || x)
, assuming that LeafCount[!u] = 2
(due to the terms !u
and u
)... Is my understandingof LeafCount
wrong?– Naufal Fikri
2 days ago
This did the trick and does exactly what I want it to do! Thank you. Although for some reason it does not always give out the "simplest". Most notably there are a lot of cases where this does not "simplify" using De Morgan's laws, it keeps
(!u && !v && !w && !x)
while in fact it can be simplified to !(u || v || w || x)
, assuming that LeafCount[!u] = 2
(due to the terms !u
and u
)... Is my understandingof LeafCount
wrong?– Naufal Fikri
2 days ago
add a comment |Â
up vote
2
down vote
perhaps BooleanMinimize
?
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
(x && ! y && z) || (! x && y) || (! x && ! z) || (y && ! z)
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z), "CNF"]
(! x || ! y || ! z) && (! x || y || z) && (x || y || ! z)
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize(x || (y && t)) && z
then usingBooleanMinimize
gives(t || x) && (x || y) && z
and(t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.
– Naufal Fikri
Sep 8 at 16:17
add a comment |Â
up vote
2
down vote
perhaps BooleanMinimize
?
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
(x && ! y && z) || (! x && y) || (! x && ! z) || (y && ! z)
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z), "CNF"]
(! x || ! y || ! z) && (! x || y || z) && (x || y || ! z)
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize(x || (y && t)) && z
then usingBooleanMinimize
gives(t || x) && (x || y) && z
and(t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.
– Naufal Fikri
Sep 8 at 16:17
add a comment |Â
up vote
2
down vote
up vote
2
down vote
perhaps BooleanMinimize
?
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
(x && ! y && z) || (! x && y) || (! x && ! z) || (y && ! z)
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z), "CNF"]
(! x || ! y || ! z) && (! x || y || z) && (x || y || ! z)
perhaps BooleanMinimize
?
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z)]
(x && ! y && z) || (! x && y) || (! x && ! z) || (y && ! z)
BooleanMinimize[! (x && y && z) && ! (x && ! y && ! z) && ! (! x && ! y && z), "CNF"]
(! x || ! y || ! z) && (! x || y || z) && (x || y || ! z)
edited Sep 8 at 14:39
answered Sep 8 at 14:07
kglr
159k8184384
159k8184384
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize(x || (y && t)) && z
then usingBooleanMinimize
gives(t || x) && (x || y) && z
and(t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.
– Naufal Fikri
Sep 8 at 16:17
add a comment |Â
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize(x || (y && t)) && z
then usingBooleanMinimize
gives(t || x) && (x || y) && z
and(t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.
– Naufal Fikri
Sep 8 at 16:17
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize
(x || (y && t)) && z
then using BooleanMinimize
gives (t || x) && (x || y) && z
and (t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.– Naufal Fikri
Sep 8 at 16:17
Thanks for the answer, however this just converts them into CNF and DNF instead of simplifying the formula as minimal as possible. Consider If I try to minimize
(x || (y && t)) && z
then using BooleanMinimize
gives (t || x) && (x || y) && z
and (t && y && z) || (x && z)
for "CNF" and "DNF" respectively. Which is more complex (has more repeated terms) than the original formula.– Naufal Fikri
Sep 8 at 16:17
add a comment |Â
Naufal Fikri is a new contributor. Be nice, and check out our Code of Conduct.
Naufal Fikri is a new contributor. Be nice, and check out our Code of Conduct.
Naufal Fikri is a new contributor. Be nice, and check out our Code of Conduct.
Naufal Fikri is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181494%2fsimplifying-boolean-algebra-without-using-certain-operations%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You may not be aware of an optional argument to
Simplify
calledExcludedForms
. That can let you tellSimplify
thatXor
cannot be considered as part of the solution.Simplify
usesLeafCount
, which is roughly a count of the number of symbols needed to write an expression, to determine what is simplest. Without usingXor
I'm not sure I see any expression with fewer symbols that is equivalent to your problem. Can you show the simplest result with fewer symbols?– Bill
Sep 8 at 17:28
The expression may not be necessarily simpler than using
Xor
. However what I want here is that the "simplest possible form" withoutXor
. Which can be solved usingExcludedForms
argument. Thank you for your reply.– Naufal Fikri
Sep 9 at 8:31