﻿

# Question: Is Bayes theorem simpler in Mathematica?

February 26 2013 by
false
Maple

1

I came across this post http://www.stiglerdiet.com/2012/02/10/mathematica-a-love-story/

and in the commented section near the end someone mentions this can not be elegantly done in Maple.  I would like to disprove this comment.  He says "There’s NO WAY any numeric language like R or Maple can try to do this."

I don't believe it, and I welcome anyone to disprove his comment.  Or anyone to comment on the topic.

I have replicated his comment here:

quote...

I want to quickly touch up on symbolic language…. Someone mentioned Maple… try this in Maple…

First, I define Bayes’ Theorem and probabilistic logic through symbolic use (looks a lot prettier in Mathematica, where a lot of this text is special symbols):

Remove[P]
Unprotect@Intersection;
Intersection[A_Symbol, B_Symbol] := {A, B}
Intersection[A_Not, B_Symbol] := {A, B}
Intersection[A_Symbol, B_Not] := {A, B}
P[Int_List /; Length@Int == 2] :=
P[Int[[2]] [Conditioned] Int[[1]]] P[Int[[1]]]
P[B_, A_] :=
If[NumericQ@B, B,
P[B [Conditioned] A] P[A] + P[B [Conditioned] Not@A] P[Not@A]]
P[Not@B_, A_: 1] := If[NumericQ@A, 1 - P[B], 1 – P[B, A]]
P[A_ [Conditioned] B_] := P[A [Intersection] B]/P[B, A]
P[Not@A_ [Conditioned] B_] := 1 – P[A [Conditioned] B];

Then I use it, and query various probabilities:

P[Sunny] = .7;
P[Happy [Conditioned] Sunny] = .9;
P[Happy [Conditioned] [Not] Sunny] = .4;
P[Sunny [Conditioned] Happy]

P[Cancer] = .01;
P[Test [Conditioned] Cancer] = 0.9
P[Test [Conditioned] ! Cancer] = 0.2
P[Test, Cancer]
P[! Test, Cancer]

P[Cancer [Conditioned] Test]
P[! Cancer [Conditioned] Test]
P[Cancer [Conditioned] ! Test]
P[! Cancer [Conditioned] ! Test]