9
$\begingroup$

The extension field $\mathbb{Q}(\sqrt {2} + \sqrt {3})$ can be represented by a $4$ - dimensional vector space over $\mathbb{Q}$ with basis $\{1, \sqrt {2}, \sqrt {3}, \sqrt {6}\} $.

I made a matrix model of such a field where presenting the numbers is done as shown in the following example:

{1,2,3,4}.{1, Sqrt[2], Sqrt[3], Sqrt[6]}

$1 + 2\sqrt {2} + 3\sqrt {3} + 4\sqrt {6} $

The number {1,0,0,1/2} should be represented as:

$1 + \frac{1}{2}\sqrt {6} $

but is in fact represented as

$1 + \sqrt{\frac{3}{2}}$

Is there a way to workaround this such that $ \{a,b,c,d \}$ is always represented as

$a + b\sqrt {2} + c\sqrt {3} + d\sqrt {6} $

I suppose the title of the question should then be 'How to display numbers as multiples of a square root' ?

$\endgroup$
8
  • $\begingroup$ Try {1, 0, 0, 1/2}.{1, Sqrt[2], Sqrt[3], Sqrt[6]} // ContinuedFraction // FromContinuedFraction $\endgroup$
    – eldo
    Commented Jun 17, 2017 at 11:41
  • $\begingroup$ Gives 1/2(2+sqrt(6)) . That is not what I was looking for, sadly. $\endgroup$ Commented Jun 17, 2017 at 11:50
  • $\begingroup$ Also think of cases where sqrt(2), sqrt(3) and sqrt(6) are present. $\endgroup$ Commented Jun 17, 2017 at 11:51
  • 1
    $\begingroup$ If you always want them in symbolic form, consider using {1,a,b,c} as the basis. Then {1, 0, 0, 1/2}.{1,a,b,c} becomes 1+c/2. $\endgroup$
    – bill s
    Commented Jun 17, 2017 at 12:39
  • $\begingroup$ But that would spoil the presentation. $\endgroup$ Commented Jun 17, 2017 at 12:44

2 Answers 2

8
$\begingroup$

Maybe you can use a wrapper + MakeBoxes. Here is the basis using the wrapper q:

QBasis = {1, q[Sqrt[2]], q[Sqrt[3]], q[Sqrt[6]]}

Now, we tell Mathematica how to format the q:

q /: MakeBoxes[q[x_], StandardForm] := MakeBoxes[x, StandardForm]
MakeBoxes[n_ q[x_], StandardForm] := RowBox[{
    Parenthesize[n, StandardForm, Times, Left],
    MakeBoxes[x]}
]

A couple examples:

{1, 0, 0, -1/2} . QBasis
{1, -I, 2.2, -2+I} . QBasis
{1, 0, 1, 1} . QBasis

1 - 1/2 Sqrt[6]

1 - I Sqrt[2] + 2.2 Sqrt[3] - (2 - I) Sqrt[6]

1 + Sqrt[3] + 1/2 Sqrt[6]

$\endgroup$
3
  • $\begingroup$ Do you know if it is possible to let Mathematica print the cube root of four ' as such' instead of 2 to the power of 2/3? Or should that be another question? $\endgroup$ Commented Jun 24, 2017 at 9:51
  • $\begingroup$ Probably another question. Do you want a radical box, or a power form? $\endgroup$
    – Carl Woll
    Commented Jun 24, 2017 at 14:53
  • $\begingroup$ A radical box, but I'll make another question about this. $\endgroup$ Commented Jun 25, 2017 at 12:10
5
$\begingroup$
A = {1, 2, 3, 1/2} /. {Rational[x_, y_] :>  If[x > 0, HoldForm[x/y], 
-HoldForm@Evaluate[-x/y]]};
B = MapAt[HoldForm, {1, Sqrt[2], Sqrt[3], Sqrt[6]}, 2 ;;]
A.B

1+2 Sqrt[2]+3 Sqrt[3]+1/2 Sqrt[6]

$\endgroup$
3
  • $\begingroup$ @niloderoock Check the update. $\endgroup$ Commented Jun 17, 2017 at 13:44
  • $\begingroup$ Answer is incorrect for (-1/2,-1/2,-1/2,-1/2): -1/2 is shown as + - 1/2. $\endgroup$ Commented Jun 17, 2017 at 14:10
  • $\begingroup$ @niloderoock Check the update now. $\endgroup$ Commented Jun 17, 2017 at 14:31

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.