0
|
3272 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# Can I prevent numbers from being pulled out of a product inside Sqrt?

Posted 10 years ago
 If I write an expression like Sqrt[2 a], Mathematica apparently automatically transforms it into SqrtSqrt.  Is there a way to prevent this?In: Sqrt[2 a] // InputFormOut: Sqrt*SqrtThe 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[x_] Sqrt[y_] -> Sqrt[x y] // InputFormOut: SqrtHowever, it doesn't work if there's a number, e.g. In: Sqrt Sqrt Sqrt //. Sqrt[x_] Sqrt[y_] -> Sqrt[x y] // InputFormOut: Sqrt*Sqrt*SqrtAfter much puzzlement, I realized that what is probably happening is: 1) Mathematica uses the first application of the rule to transform Sqrt Sqrt -> Sqrt[2 b]2) Mathematica automatically splits this Sqrt[2 b] -> Sqrt Sqrt3) 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 still stays separateIn: Sqrt Sqrt Sqrt //. Sqrt[x_] Sqrt[y_] Sqrt[z_] -> Sqrt[x y z] // InputFormOut: Sqrt*SqrtThanks,BillP.S. - All the expressions inside the square roots have values that are real and positive, so this is mathematically legitimate!
6 Replies
Sort By:
Posted 10 years ago
 Would it be acceptable for you to create a function that Mathematica doesn't know how to rewrite?In:= Sqrt Sqrt[a] Sqrt[b] //. {sqrt[a_] Sqrt[b_] -> sqrt[a b], Sqrt[a_] Sqrt[b_] -> sqrt[a b]}Out= sqrt[2 a b]In:= Sqrt[2 a] //. {sqrt[a_] Sqrt[b_] -> sqrt[a b], Sqrt[a_] Sqrt[b_] -> sqrt[a b]}Out= sqrt[2 a]If you later need to give that back to Mathematica then another rule to turn sqrt into Sqrt might be enough.
Posted 10 years ago
 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: SqrtBill
Posted 10 years ago
 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.
Posted 10 years ago
 Thanks for the suggestion.  Now I have two more questions!Is there a way that I can display your sqrt function with the usual square root sign?Did you use the code box (which I just noticed) to prevent the brackets from getting lost?In:= Sqrt[a]/sqrt[b]Out= Sqrt[a]/sqrt[b]
Posted 10 years ago
 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.
Posted 10 years ago
 Thanks for the help.  I'm learning.