12
$\begingroup$

I'm using value-defined function as set of parameter, i.e.

f[1] ===> first parameter
f[2] ===> second parameter
f[3] ===> third parameter

etc. I would like to tell Mathematica that all these parameters are positive. I tried something like

FullSimplify[Abs[f[1]],Assumptions-> {f[x_]>0}]

and I get

Abs[f[1]]

instead of the desired

f[1]

Of course here I posted just an example, the function I have to simplify in my case is much more complicated. How can I do?

$\endgroup$
  • $\begingroup$ Have you tried creating a list of assumptions like Thread[Table[f[i], {i, fmin, fmax}] > 0]? $\endgroup$ – Feyre Aug 14 '16 at 11:41
  • $\begingroup$ Interestingly using f[1] > 0 in Assumptions does work. Doesn't pattern matching work here, and if so, why? $\endgroup$ – kirma Aug 14 '16 at 11:45
  • $\begingroup$ Of course this is a solution but in my program I don't know the range of the parameters. I want to tell Mathematica that every value of the function is positive. $\endgroup$ – MaPo Aug 14 '16 at 11:47
  • 1
    $\begingroup$ @MaPo A way I see (not sure whether it fits your need in your more general case) would be to define an UpValue for f, either with f /: Abs[fun : f[_]] := fun or with Abs[fun : f[_]] ^:= fun. This will evaluate Abs[f[1]] to f[1], for instance, without the need of using Assumptions and FullSimplify. $\endgroup$ – user31159 Aug 14 '16 at 14:44
  • 2
    $\begingroup$ Related: (6182), (42607), (58271), (67343), (79301), (79756), (94983) $\endgroup$ – Mr.Wizard Aug 15 '16 at 1:05
10
$\begingroup$

EDIT: Simplified per suggestion from @BobHanlon.

This constructs assumptions by finding all occurrences of pattern f[_] in the expression being simplified:

FullSimplify[#, Cases[#, v : f[_] :> v > 0, Infinity]] &[
 Abs[f[f[1]]] + Abs[f[x]]]

(* f[x] + f[f[1]] *)
$\endgroup$
  • 2
    $\begingroup$ +1 Or more succinctly: Simplify[#, Cases[#, v : f[_] :> v > 0, Infinity]] &[ Abs[f[f[1]]] + Abs[f[x]]] $\endgroup$ – Bob Hanlon Aug 14 '16 at 14:57
  • 2
    $\begingroup$ I find it somewhat surprising that Mathematica doesn't have support for a more concise way of expressing this. $\endgroup$ – mikado Aug 14 '16 at 20:32
  • $\begingroup$ @mikado I wouldn't be surprised if I there would actually be a way, but I wouldn't be aware of it. Thankfully the above form is not that long, just slightly inelegant. $\endgroup$ – kirma Aug 15 '16 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.