## Mathematica not evaluating #1

Related searches

I defined 2 objects:

```f=x^2
g=x->#1
```

Why does this:

```f /. x -> #1 &
```

give me the expected result:

```25
```

But this:

```f /. g &
```

gives me:

```#1^2
```

`Function` (short form `&`) has attribute `HoldAll`:

```Attributes[Function]
```
```{HoldAll, Protected}
```

Therefore `g` remains unevaluated. You can force it with `Evaluate`:

```Evaluate[f /. g] &
```
```25
```

`Evaluate` will not work deeper in the expression; you cannot write `f /. Evaluate[g] &`

Variables Inside Functions Not Evaluating, Without going into too much detail, this is a result of the way pattern matching is carried out. When you write the rule f[y_]:={x,y} for instance,� Without going into too much detail, this is a result of the way pattern matching is carried out. When you write the rule f[y_]:={x,y} for instance, it tells the compiler that it should match anything and call it y, then replace any instance of y on the right side with the match.

You can make it work by keeping the pure function components together.

```f = x^2
g = x -> #1 &

f/. g
```

25

To run it over a list form the function before mapping.

```f = x^2
g = x -> #1
list = {1, 2, 3, 4, 5};
b = Block[{a}, Function[f /. a] /. a -> g]
Map[b, list]
```

{1, 4, 9, 16, 25}

And for the specific problem in the comments...

```vars = {x, y};
f = x + y;
g = Table[vars[[i]] -> Slot[i], {i, 1, Length[vars]}];
b = Block[{a}, Function[f /. a] /. a -> g];
list = {{1, 2}, {3, 4}, {5, 6}};
Map[b[Sequence @@ #] &, list]
```

{3, 7, 11}

With Mr. Wizard's answer this can become:

```vars = {x, y};
f = x + y;
g = Table[vars[[i]] -> Slot[i], {i, 1, Length[vars]}];
list = {{1, 2}, {3, 4}, {5, 6}};
Map[Evaluate[f /. g] &[Sequence @@ #] &, list]
```

{3, 7, 11}

Evaluation Control—Wolfram Language Documentation, The Wolfram Language normally takes any expression it is given, and evaluates it as far as possible. But built into the Wolfram Language is a collection of� \$\begingroup\$ From the MoreInformation section of MatrixForm in the docs: MatrixForm acts as a "wrapper", which affects printing, but not evaluation. \$\endgroup\$ – kglr Mar 16 '12 at 19:54 1 \$\begingroup\$ @kguler and not all functions actually respect it, such as MatrixExp . \$\endgroup\$ – rcollyer Mar 16 '12 at 19:57

Replace `g=x->#1` with `g=x->#1 &` and `f /. g &` with `f/. g`

Wolfram Mathematica does not evaluate at all, Wolfram Community forum discussion about Wolfram Mathematica does not evaluate at all. Stay on top of important topics and build connections by joining� Integrate can evaluate integrals of rational functions. It can also evaluate integrals that involve exponential, logarithmic, trigonometric, and inverse trigonometric functions, so long as the result comes out in terms of the same set of functions. Integrate can give results in terms of many special functions.

Evaluation of Expressions—Wolfram Language Documentation, Some functions that use non‐standard evaluation procedures. When you give a definition such as a=1, the Wolfram Language does not evaluate the a that� All expressions that do not explicitly depend on the variables given are taken to have zero partial derivative. The setting NonConstants {u 1, …} specifies that u i depends on all variables x, y, etc. and does not have zero partial derivative. »

Evaluate—Wolfram Language Documentation, Evaluate[expr] causes expr to be evaluated even if it appears as the argument of a function Basic Examples (1)Summary of the most common use cases. How come? This isn't an issue of not considering the negative root. The expressions are identical. As demonstrated by Simplify[a > m, a < m], replacing m with more complex expressions aside from having the Sqrt function. In fact, if I use Surd, no matter the nth root, even or odd, or square root, Simplify will evaluate completely into False. Why?

Another common syntax mistake is the naming of built-in Mathematica functions. Mathematica functions are always capitalized. Forgetting to capitalize a Sin[x] or an Exp[y-1] will cause errors because Mathematica will not recognize them. Defining Functions: Defining a new function in Mathematica is also slightly tricky, syntax-wise.