# Tag Info

7

I can see the source of your confusion: If you use Head[f[x]] and Head[5] you get f and Integer respectively. Then, you read the documentation Apply[f,expr] or f@@expr replaces the head of expr by f. and you expect Cos@@5 to replace the Integer head by Cos. The way I explain it to myself is by saying Mathematica has two (types of) heads ;-) One type is ...

7

They return different answers because they're actually different expressions that have the same value, but of course that equality isn't going to be preserved when working with inexact numbers like 4.3. In particular, the first four expressions are all interpreted by Mathematica as Sqrt[(-4.3)^2] while the last expression is interpreted as Sqrt[-4.3]^2 ...

6

I like to think about @@ as a Frankstein decapitation operator. It take out the Head of the old expression and replace by the new one. And @@@ as a mass Frankstein decapitation operator. It get inside each list element and apply @@ to each element inside the list. To understand what Head means, use FullForm. For example, in the list l={1,2,3} if you apply ...

4

This sort of programming is not my strength and I don't know Python. Reading the comments, perhaps this won't quite be perfect, but it might be good enough. It seems good enough for many purposes, at least in the way I interpret the question. It localizes all Symbols in the code that are in the "Global`" context and don't have Ownvalues or DownValues. If ...

3

With $a = -4.3$, the results of $\sqrt{a^2}$ and $(\sqrt a)^2$ are not "slightly different". $\sqrt{a^2}$ is a positive number. $(\sqrt a)^2$ is a negative number close to $a$. For any $b$, $(\sqrt b)^2$ is always equal to $b$, because $\sqrt b$ is defined to be a number whose square is $b$. Multiple roots, branch cuts, and the like don't make a ...

2

How did your rules come to be in a text file? I'd recommend storing them in one of two ways: rules = {x^3 y^2 -> 4, x y^2 -> 2}; rules >> rules.dat then e.g x y^2 /. Get["rules.dat"] To me this is an intuitive Mathematica way of storing your rules. Unfortunately you cannot do this with CDF, not even when using Player Pro, because Put fails ...

1

You may think of it as follows: @ applies a single-parameter function to a single argument, and @@ applies a multi-parameter function to a list of arguments (effectively, replacing its head List with the function). And, as a bonus, @@ works not only on lists with the List head, it can replace any head of a structured expression (but not heads of atomic ...

Only top voted, non community-wiki answers of a minimum length are eligible