12

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
MaPo
  • 909
  • 4
  • 14
  • Have you tried creating a list of assumptions like Thread[Table[f[i], {i, fmin, fmax}] > 0]? – Feyre Aug 14 '16 at 11:41
  • Interestingly using f[1] > 0 in Assumptions does work. Doesn't pattern matching work here, and if so, why? – kirma Aug 14 '16 at 11:45
  • 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. – MaPo Aug 14 '16 at 11:47
  • Do you have to define the functions in f[n_]? when such things matter I try to define them in $x_m,..,x_0,..x_n$ instead. – Feyre Aug 14 '16 at 11:56
  • Of course it's possible, but in this casa how can I tell Mathematica $x_i>0$ forall $i$? Can you give me an example? – MaPo Aug 14 '16 at 12:01
  • @MaPo Well I don't know your full code, normally I'd define all $x_i$ in one variable, otherwise you might be able to pattern match. – Feyre Aug 14 '16 at 12:06
  • 1
    @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. –  Aug 14 '16 at 14:44
  • 2

1 Answers1

10

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]] *)
kirma
  • 19,056
  • 1
  • 51
  • 93
  • 2
    +1 Or more succinctly: Simplify[#, Cases[#, v : f[_] :> v > 0, Infinity]] &[ Abs[f[f[1]]] + Abs[f[x]]] – Bob Hanlon Aug 14 '16 at 14:57
  • 2
    I find it somewhat surprising that Mathematica doesn't have support for a more concise way of expressing this. – mikado Aug 14 '16 at 20:32
  • @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. – kirma Aug 15 '16 at 03:36