Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Function defined with If

  • To: mathgroup at
  • Subject: [mg71384] Re: [mg71338] Function defined with If
  • From: Julian Aguirre <julian.aguirre at>
  • Date: Thu, 16 Nov 2006 00:53:31 -0500 (EST)
  • References: <>


El 15/11/2006, a las 18:18, David Park escribió:

> I'm not quite certain what you want to do. Suppose that a and b are
> complicated expressions of x and y. Do you want f to be a function  
> of x and
> y, or of a and b? I am going to assume a function of x and y.

That is exactly what I intended.

> Then note the Attributes of If.
> Attributes[If]
> {HoldRest, Protected}
> So in the f definition we have to evaluate the second and third  
> arguments of
> If.
> a = x; b = y;
> f[x_, y_] = If[a < b, Evaluate@a, Evaluate@b]
> If[x < y, x, y]

Thank you very much for this solution. It is exactly what I need. I  
have tried it in my much more complicated original problem, and it  


> From: Julian Aguirre [mailto:julian.aguirre at]
> Dear group,
> I am trying to define a function of the variables x, y through other
> quantities depending on x and y and the function If. A minimal example
> is
> In[1]:a = x;
> b = y;
> f[ x_, y_ ] = If[ a < b, a, b ]
> Out[3]If[ x < y, a, b ]
> How can I force Mathematica to return If[ x < y, x, y ], as I thought
> it would?
> Thaks in advance,
> Julián Aguirre

  • Prev by Date: Re: Binomial Distribution
  • Next by Date: Re: Define a matrix function with size as argument
  • Previous by thread: Re: Function defined with If
  • Next by thread: coercion into series