Message Boards Message Boards

0
|
1944 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Test that two functions are equivalent

Hello everyone,

I have a parametric probability distribution that should reduce to exactly equivalent to a Uniform distribution when the second parameter is zero, but I can't get Mathematica to test the equivalence.

Comparison of PDF and CDF

The resulting equalities "eyeball" as tautologically equal, but I can't get Solve, Simplify, Reduce, etc. to give me a True. (SameQ does yield False, as it should.)

I can get close with ForAll, but it gets confused with the CDF at x=0.

Comparison of PDF and CDF with some subsitution

First, is this clunky ForAll construct really the only way to make this test? And second, is there any way to get ForAll (or the correct function) to see the CDFs as equivalent despite the ever-so-slight difference in definition?

POSTED BY: Frank MacCrory
5 Replies

Sorry for not including copiable code in the original message; it didn't seem to me to bear on the question of comparing two functions, and it didn't render quite as I expected. Should work, though.

(* Original, intended definition *)
MDistribution[f_, a_] = ProbabilityDistribution[a*Cos[f*2*\[Pi]*x] + 1, {x, 0, 1}];

(* The above behaves oddly at the endpoints, this was the suggested fix: *)
pdf2 = Piecewise[{{0, 1 < x < \[Infinity]}, {a*Cos[f*2*\[Pi]*x] + 1, 0 <= x <= 1}, {0, -\[Infinity] < x < 0}}]
MDistribution[f_, a_] = ProbabilityDistribution[pdf2, {x, -\[Infinity], \[Infinity]}];

FullSimplify[ForAll[n, PDF[MDistribution[f, 0]][n] == PDF[UniformDistribution[{0, 1}]][n]]]
FullSimplify[ForAll[n, CDF[MDistribution[f, 0]][n] == CDF[UniformDistribution[{0, 1}]][n]]]

Thank you for looking!

POSTED BY: Frank MacCrory

Thanks. With this we can proceed using quantifier elimination methods. I predefine the pdfs and cdfs as symbols just to make later code more concise.

pdf2 = Piecewise[{{0, 1 < x < \[Infinity]}, {a*Cos[f*2*\[Pi]*x] + 1, 
     0 <= x <= 1}, {0, -\[Infinity] < x < 0}}];
MDistribution[f_, a_] = 
  ProbabilityDistribution[pdf2, {x, -\[Infinity], \[Infinity]}];
pdfM0 = PDF[MDistribution[f, 0]];
pdfU0 = PDF[UniformDistribution[{0, 1}]];
cdfM0 = CDF[MDistribution[f, 0]];
cdfU0 = CDF[UniformDistribution[{0, 1}]];

Resolve is a useful tool for the ForAll approach (I do not know of a better one by the way).

In[492]:= Resolve[ForAll[n, pdfM0[n] == pdfU0[n]], n, Reals]

(* Out[492]= True *)

In[493]:= Resolve[ForAll[n, cdfM0[n] == cdfU0[n]], n, Reals]

(* Out[493]= True *)

Reduce could also be used for these. FullSimplify is a different beast. Also it seems they are not quite equivalent outside the reals (maybe they are undefined there).

POSTED BY: Daniel Lichtblau

Thank you!

Resolve[...,Reals] is precisely what I needed to ask my question in a way that Mathematica would understand it. The previous results were confusing without the Reals qualifier because I thought it assumed Reals whenever a variable gets used in an inequality.

Maybe an inequality in a Piecewise[] function doesn't count as getting used in an inequality.

POSTED BY: Frank MacCrory

I was wondering pretty much the same thing about inequalities.

POSTED BY: Daniel Lichtblau

Please add actual code for a minimal complete example that is copy-pastable. I don't want to retype just to test things.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract