If I write an expression like Sqrt[2 a], Mathematica apparently automatically transforms it into Sqrt[2]Sqrt. Is there a way to prevent this?
In: Sqrt[2 a] // InputForm
Out: Sqrt[2]*Sqrt
The context: I am trying to write a rule that will take the product of several square roots and turn it into the square root of the product. This works fine for symbols:
In: Sqrt Sqrt Sqrt //. Sqrt Sqrt → Sqrt // InputForm
Out: Sqrt[a*b*c]
However, it doesn’t work if there’s a number, e.g.
In: Sqrt[2] Sqrt Sqrt //. Sqrt Sqrt → Sqrt // InputForm
Out: Sqrt[2]*Sqrt*Sqrt
After much puzzlement, I realized that what is probably happening is:
Mathematica uses the first application of the rule to transform Sqrt[2] Sqrt → Sqrt[2 b]
Mathematica automatically splits this Sqrt[2 b] → Sqrt[2] Sqrt
Since the output expression is the same as the input expression, ReplaceRepeated terminates, never processing Sqrt Sqrt.
I can partially fix this particular example with a more complicated rule, but the Sqrt[2] still stays separate
Sorry folks. In my previous post, lots of quantities in square brackets disappeared, completely garbling the Mathematica code. I don’t know how to prevent this or even to preview what the post is going to look like. The short form of the question, replacing all the square brackets with parentheses is:
If I write an expression like Sqrt(2 a), Mathematica apparently automatically transforms it into Sqrt(2)Sqrt(a). Is there a way to prevent this?
And now I have another question. How do I put square brackets in a posting without risking them getting dropped? As an experiment, I’m going to try using the “Insert Special Character” tool. Test: Sqrt
Use the little <> button near the right end of the second row of buttons to create a box to paste code into.
That also has problems, but fewer of those are silently erasing some characters in your code.
I’m sorry, but I don’t “desktop publish” results, like trying to get that square root sign in there, because that only increases the difficulty and errors by a large scale factor.
Yes I used exactly that code box to try to prevent the forum software from mangling the code.