MathGroup Archive 2009

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

Search the Archive

Re: If and ReplaceAll

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102837] Re: [mg102851] If and ReplaceAll
  • From: "Scot T. Martin" <smartin at seas.harvard.edu>
  • Date: Sun, 30 Aug 2009 06:04:43 -0400 (EDT)
  • References: <200908291033.GAA00437@smc.vnet.net>

I'm not really sure why you want to do this, but nevertheless the probelm 
is that If[] has the attribute of HoldRest. Here's one way to get the 
result you want:

a = 2 c;
f[z_] := If[z > 0, a, 0];
Evaluate /@ (Evaluate /@ (f[z]) /. c -> 1)

However, generally, without knowing exactly what problem you want to 
solve, I think there is undoubtedly a better approach than what you're 
trying right now.

On Sat, 29 Aug 2009, wiso wrote:

> a = 2c;
> ff[z_] := a;
> ff[z] /. c -> 1
>
>
> and I got 2. Ok, now:
>
> a = 2 c;
> f[z_] := If[z > 0, a, 0]
> f[z] /. c -> 1
>
> and I got:  If[z > 0, a, 0]
> but I want: If[z > 0, 2, 0]
>
> I tried to use Evaluate, FullSimplify... but nothing
>
>
>


  • Prev by Date: avi and QuickTime
  • Next by Date: Re: If and ReplaceAll
  • Previous by thread: If and ReplaceAll
  • Next by thread: Re: If and ReplaceAll