# Tricky FindRoot/NExpectation problem

What's the best way to solve the following with $$x\sim \text{Normal}(0,1)$$?

$$E_x[\log(1-2 a x^2 + a^2 x^4)]=0$$

Idea 1: FindRoot

a0 = 2.42;
term[a_] :=
TransformedDistribution[Log[1 - 2 a x^2 + a^2 x^4],
x \[Distributed] NormalDistribution[]];
FindRoot[NExpectation[t, t \[Distributed] term[a]], {a, a0}]
(* NIntegrate failed to converge to prescribed accuracy *)


Idea 2: increase MaxRecursion, AccuracyGoal

a0 = 2.42;
method = {"NIntegrate", {MinRecursion -> 12, MaxRecursion -> 30,
WorkingPrecision -> 30, AccuracyGoal -> 12}};
term[a_] :=
TransformedDistribution[Log[1 - 2 a x^2 + a^2 x^4],
x \[Distributed] NormalDistribution[]];
FindRoot[
NExpectation[t, t \[Distributed] term[a], Method -> method], {a, a0}]
(* {a -> 2.42125 - 2.16855*10^-9 I} *)


Idea 3: look at density to find tricks

a0 = 2.42;
func = With[{a = a0},
PDF[TransformedDistribution[Log[1 - 2 a x^2 + a^2 x^4],
x \[Distributed] NormalDistribution[]]]];
Plot[func[x], {x, -3, 3}]


Now it seems an integral splitting technique would work, but I can't get PDF for symbolic $$a$$, any ideas?

Background: this gives largest $$a$$ such that $$w=w-a w x^2$$ converges almost surely for any starting $$w$$

Part 1. Using $$1-2ax^2+a^2x^4 = |1-ax^2|^2$$ and the law of the unconscious statistician:

pdfN01=1/Sqrt[2*Pi]*Exp[-x^2/2];
expectationAux:=Integrate[2*Log[Abs[1-a*x^2]]*pdfN01,{x,-Infinity,Infinity}]//FullSimplify;
expectation=Piecewise[{
{Assuming[a>0,expectationAux],a>0},
{Assuming[a<0,expectationAux],a<0}},0];
(*
Piecewise[{
{2*(-EulerGamma + HypergeometricPFQ[{1, 1}, {3/2, 2}, -1/2*1/a]/a + Log[a/2]), a > 0},
{2*(-EulerGamma + Pi*Erfi[1/(Sqrt[2]*Sqrt[-a])] + HypergeometricPFQ[{1, 1}, {3/2, 2}, -1/2*1/a]/a + Log[-1/2*a]), a < 0}},
0]
*)


Plot of the result:

Plot[expectation,{a,-3,8},WorkingPrecision->100,AxesLabel->{"a","Expectation"}]


Part 2. Determine the $$a\approx 2.5$$ where the expectation vanishes:

FindRoot[expectation,{a,25/10},WorkingPrecision->100]
(* a->2.421249521036836042992780131428225933128842834067867847377838424345397835692066559296652232682365322 *)

• Neat trick with Piecewise, learning something new every day! Commented Aug 21, 2022 at 20:14