# How do I use /. to replace a custom function?

**URL:** <https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351>\
**Category:** Questions\
**Created:** [January 5, 2023, 11:59am UTC](https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351 "2023-01-05T11:59:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastianneumann1](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@sebastianneumann1](https://community.wolfram.com/u/sebastianneumann1)\
**Post date:** [January 5, 2023, 11:59am UTC](https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351/1 "2023-01-05T11:59:06Z")

</div>

Hi everyone,

I already assume that there’s a really trivial solution to this, but I just can’t figure it out and also couldn’t find anybody else writing about this - why is

```
In[1]:= Sin[x]/.Sin->Cos
Out[1]:= Cos[x]

```

but

```
In[1]:= A[x_]:=2x
         B[x_]:=3x
         A[x]/.A->B
Out[1]:= 2x

```

What’s different with this replacement rule, and how to I get the desired result `3x`?

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [January 5, 2023, 1:46pm UTC](https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351/2 "2023-01-05T13:46:00Z")

</div>

The first argument of `ReplaceAll` is evaluated before the replacement rule acts. The difference between the two cases is that evaluating `Sin[x]` just returns `Sin[x]`, unchanged. So `Sin` is still visible to the replacement rule. But evaluating `A[x]` returns 2 x, so `A` is no longer visible to the rule.

A workaround:

```
A[x] /. A[x] -> B[x]

```

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [January 5, 2023, 4:36pm UTC](https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351/3 "2023-01-05T16:36:18Z")

</div>

Another workaround

```
Unevaluated@A[x] /. A -> B

```

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [January 5, 2023, 6:59pm UTC](https://community.wolfram.com/t/how-do-i-use-to-replace-a-custom-function/21351/4 "2023-01-05T18:59:39Z")

</div>

An alternative:

```
Hold@A[x] /. A -> B // ReleaseHold

```
