       Re: Using substitution rules to define a function

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Using substitution rules to define a function
• From: "Dr A. Hayes" <hay at leicester.ac.uk>
• Date: Fri, 1 Apr 1994 10:47:25 +0100 (BST)

```Jean:
Here is a simplified version of your problem and a solution to it.

PROBLEM
In:=
sol = {{x->w},{x->-w}}
Out=
{{x -> w}, {x -> -w}}
In:=
f[w_] := sol[[1,1,2]];
In:=
f[t]
Out=
w

SOLUTION
In:=
f[w_] = sol[[1,1,2]];
In:=
f[x]
Out=
x

EXPLANATION
With
In:=
f[w_] := sol[[1,1,2]];
the rule stored is
In:=
?f
Global`f
f[w_] := sol[[1,1,2]]
(unevaluated right side)
so when f[x] there is no w for the slot w_
to relate to as a place to substitute x for w.
In:=
TracePrint[f[x]]
f[x]
f
x
sol[[1,1,2]]
Part
sol
{{x -> w}, {x -> -w}}
1
1
2
{{x -> w}, {x -> -w}}[[1,1,2]]
w
Out=
w

But with
In:=
f[w_] = sol[[1,1,2]];
the rule stored is
In:=
?f
Global`f
f[w_] = w
and the evaluation process is
In:=
TracePrint[f[x]]
f[x]
f
x
x
Out=
x

Allan Hayes
hay at le.ac.uk

```

• Prev by Date: 3D Plotting in Mathematica of Data from an External File
• Next by Date: ListContourPlot3D ?
• Previous by thread: 3D Plotting in Mathematica of Data from an External File
• Next by thread: ListContourPlot3D ?