Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg4149] Problem with condition in function definition !
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Allan Hayes

Posts: 1,508
Registered: 12/6/04
Re: [mg4149] Problem with condition in function definition !
Posted: Jun 16, 1996 2:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

a_kowald@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@haystack.demon.co.uk







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.