0

https://www.wolframalpha.com/input/?i=%28a+and+b+and+c%29+or+%28not+a+and+not+b+and+not+c%29+or+%28not+a+and+b+and+not+c%29+or+%28a+and+not+b+and+not+c%29

How do you plot Venn Diagramm shown in the VA Link with Mathematica for a given boolean formula?

mikado
  • 16,741
  • 2
  • 20
  • 54
booli100
  • 37
  • 1

1 Answers1

4

Construct a function using the input boolean expression:

ClearAll[a, b, c, boolfunc]

boolfunc = Function[{a, b, c}, 
  (a && b && c) || (! a && ! b && ! c) || (! a && b && ! c) || (a && ! b && ! c)];

Use boolfunc to create a boolean region using three disks as input:

a = Disk[{0, .5}];
b = Disk[{-0.5, -.5}];
c = Disk[{0.5, -.5}];

BoundaryDiscretizeRegion[BooleanRegion[boolfunc, {a, b, c}],
 MeshCellStyle -> {2 -> RGBColor[1, 0.932, 0.821]}, 
 Epilog -> {EdgeForm[{Thin, Gray}], FaceForm[], {a, b, c}, 
   MapThread[Text, 
     {Style[#, 16, Gray] & /@ {"a", "b", "c"},
     {{0, 1.25}, {-1.25, -.5}, {1.25, -.5}}}]}]

enter image description here

Compare with the picture WolframAlpha gives:

WolframAlpha["(a&&b&&c)||(!a&&!b&&!c)||(!a&&b&&!c)||(a&&!b&&!c)", 
  {"VennDiagram", 1}, "Content"}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896