# function evaluation

**URL:** <https://community.wolfram.com/t/function-evaluation/6260>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [July 24, 2015, 7:51pm UTC](https://community.wolfram.com/t/function-evaluation/6260 "2015-07-24T19:51:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayh](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kayh/32/31501_2.png) [@kayh](https://community.wolfram.com/u/kayh)\
**Post date:** [July 24, 2015, 7:51pm UTC](https://community.wolfram.com/t/function-evaluation/6260/1 "2015-07-24T19:51:26Z")

</div>

In[18]:= y = Integrate[z, z]

```
Out[18]= z^2/2

In[19]:= fu[u_] := y /. z -> u

In[20]:= fs[3]

Out[20]= 9/2

In[21]:= fz[z_] := y

In[22]:= fz[3]

Out[22]= z^2/2

```

why doesn’t fz[3] evaluate and how can I force it?

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [July 24, 2015, 8:10pm UTC](https://community.wolfram.com/t/function-evaluation/6260/2 "2015-07-24T20:10:47Z")

</div>

Hi,

sorry, I do not get the question. Why do you say that fz[3] does not evaluate? Doesn’t Mathematica do exactly what you would expect it to do?

By definition fz does not depend on z. So I would expect it to evaluate to y. But input 18 defines y as \frac{z^2}{2}. So after fz evaluates to y this is substituted by \frac{z^2}{2}. So Mathematica’s result is as expected. I understand that this is not the result you expect. Would you have expected something like this?

```
ClearAll["Global`*"]
y[z_] := Evaluate[Integrate[z, z]]
fz[z_] := y[z]
fz[3]

```

This evaluates to \frac{9}{2}. By using the delayed evaluations I have changed to order of evaluations.

Cheers,

Marco

---

<div class="post-metadata">

**Author:** ![kayh](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kayh/32/31501_2.png) [@kayh](https://community.wolfram.com/u/kayh)\
**Post date:** [July 24, 2015, 10:21pm UTC](https://community.wolfram.com/t/function-evaluation/6260/3 "2015-07-24T22:21:06Z")

</div>

Thanks, my beef is that I have y=z^2/2 the equal sign should sybstitute z^2/2 whenever y is encountered right?  
However when I use y in the function fz definition it seems to substitute for y after evaluating the function.  
I guess Evaluate forces it:

```
In[13]:= y = Integrate[z, z]

Out[13]= z^2/2

In[14]:= fz[z_] := Evaluate[y]

In[15]:= fz[3]

Out[15]= 9/2

```

maybe I’m just foggy about rules here - why do I need evaluate here?

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 25, 2015, 12:54pm UTC](https://community.wolfram.com/t/function-evaluation/6260/4 "2015-07-25T12:54:07Z")

</div>

When you do

```
y = z^2/2;
fz[z_] := y;
fz[3]

```

the delayed evaluation `f[z_]:=y` means that the right-hand side is memorized verbatim. You can check with `?fz`

When you then call `f[3]`, the replacement `z->3` is done in the frozen `y`, resulting in no replacement at all, since the verbatim `y` does not contain `z`.

After this useless replacement `y/.z->3` is done, the result is unfrozen, and the outside rule `y=z^2/2` gets finally applied.
