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.

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.

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?

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

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!

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).

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.

I was wondering pretty much the same thing about inequalities.