4
$\begingroup$

Given

t1 = {1/7 (4 + Sqrt[37]), 1/15 (3 + 2 Sqrt[7]), 1/2 (5 + 3 Sqrt[2])}

I do not want to simplify the square roots. I want to get

t2 = {1/7 (4 + Sqrt[37]), 1/15 (3 + Sqrt[28]), 1/2 (5 + Sqrt[18])}

I can cheat my way round by code:

t2 = t1[[All, 2, -1]]
t3 = t2^2
Defer[Sqrt[#]] & /@ t3

to get

{Sqrt[37], Sqrt[28], Sqrt[18]}

and fiddle it in again. What is an elegant way to obtain t2? How could I use Cases inserting two optional patterns? I tried with If inside Cases but that didn't do the job properly.

$\endgroup$
5
  • 3
    $\begingroup$ The problem is that Mathematica automatically likes to write Sqrt[28] as 2 Sqrt[7]. So you will fighting against the front end all the time trying to prevent it from doing this. But why exactly you want it displayed Sqrt[28] vs 2 Sqrt[7]? Is it just for display purposes? computationally there is no difference. $\endgroup$
    – Nasser
    Commented Oct 19, 2021 at 7:51
  • $\begingroup$ I kinda remember now this was asked before on this forum...may be if you search you might find it. $\endgroup$
    – Nasser
    Commented Oct 19, 2021 at 7:56
  • $\begingroup$ The roots show up in a sequence i am interested in. I found similar questions about this problem but structures where a bit easier. $\endgroup$
    – user57467
    Commented Oct 19, 2021 at 8:15
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/101618/… $\endgroup$
    – Michael E2
    Commented Oct 20, 2021 at 4:12
  • $\begingroup$ I am reliably certain that it is not the Mathematica front end that converts Sqrt[28] to 2*Sqrt[7]. $\endgroup$ Commented Mar 20, 2022 at 14:56

3 Answers 3

2
$\begingroup$

maybe replace Sqrt first?

{1/7 (4 + Sqrt[37]), 1/15 (3 + 2 Sqrt[7]), 1/2 (5 + 3 Sqrt[2])} //
#/. Sqrt[x_] :> f[x]& //
#/. a_ f[b_] :> f[a^2 b]& //
#/. f[x_] :> Defer[Sqrt[x]] &
$\endgroup$
1
$\begingroup$

Is this helpful? It may be too fragile for your use-case but the desired output is obtained.

expr=Inactivate[{1/7 (4 + Sqrt[37]), 1/15 (3 + 2 Sqrt[7]), 1/2 (5 + 3 Sqrt[2])}, Sqrt] 

expr//.Times[a_, Inactive[Sqrt][b_]] -> Inactive[Sqrt][a^2*b]
$\endgroup$
2
  • 1
    $\begingroup$ Thank you, but the thing is, that I already get t1 in the simplified square root form with the square root sign (which I cannot copy here because it comes out as Sqrt). $\endgroup$
    – user57467
    Commented Oct 20, 2021 at 11:53
  • $\begingroup$ Oh, I think I understand you. When I define t1 and then try to inactivate stuff in it in later lines the method does not work. I did some looking in the documentation and it suggests that there is a variable $InactivateExclusions whose value determines that Inactivate should ignore certain heads. Probably those heads include stuff that is displayed in special ways by the front end like $$\sqrt{}$$ $\endgroup$
    – Diffycue
    Commented Oct 20, 2021 at 16:51
1
$\begingroup$

I think I found a reasonable solution:

t1 = {1/7 (4 + Sqrt[37]), 1/15 (3 + 2 Sqrt[7]), 1/2 (5 + 3 Sqrt[2])};
Replace[#, a_*(b_ + c_*Sqrt[d_]) :> a*(b + Hold[Sqrt[c^2*d]])] & /@ t1;
% /. Hold[e_] :> Defer[e]

Which gives

{1/7 (4 + Sqrt[37]), 1/15 (3 + Sqrt[2^2 7]), 1/2 (5 + Sqrt[3^2 2])}

How would I evaluate just the number under the root and keep the rest?

$\endgroup$
2
  • 1
    $\begingroup$ replace Sqrt with f, eval the num, replace f[num] with defer[sqrt[num]] $\endgroup$ Commented Mar 20, 2022 at 4:07
  • $\begingroup$ Thanks, I think that this is equivalent to my "cheating" method $\endgroup$
    – user57467
    Commented Mar 21, 2022 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.