Edit: I am looking for a way to apply assumptions to all expressions contained in a compound expression. For example,
f[x_] := CompoundExpression[Clear[n], If[x > 0, n = 1, n = 2],
Array[#1 &, n]];
Output of this function is supposed to be an array of length either 1 or 2, and that is exactly what happens, when a numeric value is passed to the function.
Now I want to do the same, but without assigning a numeric value to x. I would use assumption, that x>0, and try to execute the function. I get output:
Array[#1 &, n]
instead of array {1}, that I would expect. I have tried the following:
Refine[f[x],{x>0}]
Assuming[x>0,Refine[f[x]]]
and even
$Assumptions=x>0
Refine[f[x]]
But with no success.
Original text: I am trying to write a function, which performs several calculations, say:
f[a_, b_] := Module[{x},
(*some irrelevant code omitted*)
Print[If[a > b, "a", "b"]];
(*more code omitted*)
If[a>b,a,b]];
And everything runs smoothly if the two variables (a,b) are assigned a numerical value:
f[1,2]
gives output
b
2
Now I want to use this function in a symbolic calculation. And this is where my problem appears. I am trying to apply assumptions to help comparing the two values:
Clear[a, b];
Refine[f[a, b], {a > b}]
And I would expect to get output:
a
a
, but what I get instead is:
If[a>b,a,b]
a
My question is: how do I apply the assumptions to that function properly?
Refineis applied to the return value off[a,b]. ThePrintstatement has already happened at that point. Do you want a function that will go through the statements in the definition offand refine each one? And then execute the refined code? Or ignore all the code except thePrintstatement and the return value? – Michael E2 Jan 02 '15 at 23:24