I'm trying to force a Mathematica function to make an assumption about its input variables. In my case, I'm trying to define a function to return the pdf of a Gaussian. But let's use a simple toy case:
n[x_]:= x^(1/2);
Thus, n[x] returns
Sqrt[x]
However, n[x^2] returns
Sqrt[x^2]
While this is correct and fine in principle, in my case some of the variables (like variance) will always be positive and will always be real, thus the simplification
n[x^2] = x
is appropriate. I've tried many things like:
n[x_/; x > 0 && Element[x,Reals]]:=x^(1/2);
n[x_]:=Assuming[x > 0 && Element[x,Reals],FullSimplify[x^(1/2)]];
etc. The best I can get it to do is
n[x^2] = Abs[x];
When I want
n[x^2] = x;
Anyone have any advice on how to do this?
Comments
Post a Comment