Skip to content

LogicalExpand ​

expr rewritten as a disjunction of conjunctions (DNF), with Implies/Equivalent/Xor/Nand/Nor eliminated.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageLogicalExpand✓
LogicalExpand(expr)expr, boolean-connective-eliminated and distributed into an Or of Ands
Typed signatures
TypePackageApplies
(any) -> anycombinatoricsalways

Domain: Collections

Details
  • Structural, not type-inferring: And/Or/Not/Implies/Equivalent/Xor/Nand/Nor are walked by operator, so a bare symbol is a boolean variable here regardless of what compute-engine would otherwise infer its type to be.
  • Implies(a, b) becomes Or(Not(a), b); Xor and Equivalent are eliminated via their pairwise expansions before distribution; Nand/Nor become Not(And(...))/Not(Or(...)).
  • A term with both a literal and its negation (a contradiction) is dropped; an empty result (no satisfiable term) is False.
  • Every And/Or's operands are sorted and deduplicated by their serialized form for a deterministic result — the same input always prints the same way.
  • Anything not one of the eight connectives above (a plain symbol, a comparison, a predicate call) is an opaque literal.

Examples

Basic #
live ↗
InLogicalExpand(p  ⟹  b)\mathrm{LogicalExpand}(p\implies b)Outb∨¬p{{b}}∨¬{{p}}
live ↗
InLogicalExpand(p∧¬(q∨r))\mathrm{LogicalExpand}(p∧¬(q∨r))Outp∧¬q∧¬r{{p}}∧¬{{q}}∧¬r
Scope #
live ↗
InLogicalExpand(p∧(b∨r))\mathrm{LogicalExpand}(p∧(b∨r))Outb∧p∨p∧r{{b}}∧{{p}}∨{{p}}∧r
live ↗
InLogicalExpand(p⊻b)\mathrm{LogicalExpand}(p\veebar b)Outb∧¬p∨p∧¬b{{b}}∧¬{{p}}∨{{p}}∧¬{{b}}
live ↗
InLogicalExpand(p∧¬p)\mathrm{LogicalExpand}(p∧¬p)OutFalse\mathrm{False}

The law of excluded middle collapses to True

live ↗
InLogicalExpand(a∨¬a)\mathrm{LogicalExpand}(a∨¬a)OutTrue\mathrm{True}

A contradiction collapses to False

live ↗
InLogicalExpand(a∧¬a)\mathrm{LogicalExpand}(a∧¬a)OutFalse\mathrm{False}

Equations are kept as atoms; the absorbed term drops

live ↗
InLogicalExpand(x=a∧y=b∨x=a∨y=b)\mathrm{LogicalExpand}(x=a∧y=b∨x=a∨y=b)Outx=a∨y=bx=a∨y=b
live ↗
InLogicalExpand((a∨b)∧¬(c∨d∨k))\mathrm{LogicalExpand}((a∨b)∧¬(c∨d∨k))Outa∧¬c∧¬d∧¬k∨b∧¬c∧¬d∧¬k{{a}}∧¬{{c}}∧¬{{d}}∧¬{{k}}∨{{b}}∧¬{{c}}∧¬{{d}}∧¬{{k}}
live ↗
InLogicalExpand(p⊻q⊻r)\mathrm{LogicalExpand}(p\veebar q\veebar r)Outp∧q∧r∨p∧¬q∧¬r∨q∧¬p∧¬r∨r∧¬p∧¬q{{p}}∧{{q}}∧r∨{{p}}∧¬{{q}}∧¬r∨{{q}}∧¬{{p}}∧¬r∨r∧¬{{p}}∧¬{{q}}
Applications #

A symbol is already expanded

live ↗
InLogicalExpand(t)\mathrm{LogicalExpand}(t)Outtt
Properties #

De Morgan: the negation of an Or is the And of negations

live ↗
InLogicalExpand(¬(a∨b))\mathrm{LogicalExpand}(¬(a∨b))Out¬a∧¬b¬{{a}}∧¬{{b}}

De Morgan the other way: negated And becomes Or of negations

live ↗
InLogicalExpand(¬(a∧b))\mathrm{LogicalExpand}(¬(a∧b))Out¬a∨¬b¬{{a}}∨¬{{b}}
About
Examples13
Checked againstWolfram Language 13 agree
CrosswalkWolfram Language

See also: BooleanConvert