Re: What to return on symbolic evaluation of own heads ?
- To: mathgroup@smc.vnet.net
- Subject: [mg12613] Re: [mg12511] What to return on symbolic evaluation of own heads ?
- From: Bob Hanlon <BobHanlon@aol.com>
- Date: Mon, 25 May 1998 14:25:22 -0400
Is this what you want?
F[x_?NumericQ] := MyCharFunc[0, 1, x]
MyCharFunc[left_, right_, var_] :=
If[var < left || var > right, 0, 1]
{F[x], F[3], F[x] /. x -> 3, F[Pi/3], F[3/Pi]}
{F[x], 0, 0, 0, 1}
Bob Hanlon
In a message dated 5/24/98 2:25:03 AM, a.keese@tu-bs.de wrote:
>I'm trying to build my own Datatype - as an example, I'll try to
>construct a characteristic function. I define a characteristic function
>like this:
>
>F[x_] := MyCharFunc[0,1,x]
>(* this is the char func of the interval [0,1] *)
>
>And I try to define an evaluation-rule like this:
>
>MyCharFunc[left_, right_, var_]:=
> If[NumberQ[var],
> If[var < left || var > right,
> 0,
> 1], (* else - symbolic variable *)
> MyCharFunc[left, right, var]
> ]
>
>Of course, this doesn't work - while I can write F[0.5] and get a
>correct result, I can't write F[x] as this results in an infinite
>recursion --- but If I want to manipulate my data-object, I somehow
>need to return the original object. E.G. I want to be able to write
> F[x] /. x-> 3
>and have this evaluated as F[3]...
>
>What should I return in my evaluation-rule when the parameter is
>symbolic ?