Re: Problem with condition in function definition !
- To: mathgroup at smc.vnet.net
- Subject: [mg4221] Re: [mg4149] Problem with condition in function definition !
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Tue, 18 Jun 1996 03:26:51 -0400
- Sender: owner-wri-mathgroup at wolfram.com
a_kowald at chemie.fu-berlin.de (Axel Kowald)
[mg4149] Problem with condition in function definition !
Writes
>I'd like to define a function with condition in the following way:
>
>b=1
>bla[t_]/;(t<b) := {a,b,c}
>
>bla[0] gives {a,b,c}, fine. But now I want to clear b, Clear[b],
and >still get the same result. So really I want to type 1 instead
of b, >but for some reason can't do it.
Axel:
I'm not sure why you can't type 1 instead of b; it works for me.
Clear[bla]
After entering
b=1;
bla[t_]/;(t<b) := {a,b,c}
The infomation stored on bla and on b is
?bla
Global`bla
bla[t_] /; t < b := {a, b, c}
b is not evaluated because.
?b
Global`b
b = 1
When we evaluate bla[0] the condition t<b becomes first 0<b, then
0<1, then True; so we get {a,1,c}
bla[0]
{a, 1, c}
The change of b to 1 was because of the information stored on b.
Now clear b
Clear[b]
No rule is stored under b
?b
Global`b
So now, when bla[a] is evaluated the condition becomed 0<b and
stays at this values - this is not True so the condition fails and
no rule is applied
bla[0]
bla[0]
You have the flexibility to define b to be whatever you want:
b = 3;
bla[2]
{a, 3, c}
If you don't want this flexiblity then you can use
bla[t_]/;(t<1) := {a,b,c}
or
bla[t_]/;(t<1) := {a,1,c}
Allan Hayes
hay at haystack.demon.co.uk
==== [MESSAGE SEPARATOR] ====