# understanding a mathematica equation

I have found the equation below written with Mathematica, I looked at the Mathematica online guide but it is still difficult to understand the equation. Can someone write this (or part of it) in simple math using latex, please.

n[r_] := Sum[ 1 + 2 Floor[Sqrt[r^2 - 3 x^2]],
{x, -Floor[r/Sqrt[3]], Floor[r/Sqrt[3]]}
] + Sum[2 Floor[ Sqrt[r^2 - 3 x^2] + 1/2],
{x, -Floor[(r/Sqrt[3]) + 1/2] + 1/2, Floor[(r/Sqrt[3]) + 1/2] - 1/2}
]


## migrated from math.stackexchange.comMay 25 '15 at 11:51

This question came from our site for people studying math at any level and professionals in related fields.

In Mathematica you can use $\it{\text{expression // TeXForm}}$ to get the TeX code for any mathematical expression you have written down (also works nicely for arrays and matrices). For your problem

   Sum[ 1 + 2 Floor[Sqrt[r^2 - 3 x^2]], {x, -Floor[r/Sqrt[3]],
Floor[r/Sqrt[3]]}] + Sum[2 Floor[ Sqrt[r^2 - 3 x^2] + 1/2],
{x, -Floor[(r/Sqrt[3]) + 1/2] + 1/2, Floor[(r/Sqrt[3]) + 1/2]
- 1/2}] // TeXForm


gives us:

$$\sum _{x=-\left\lfloor \frac{r}{\sqrt{3}}\right\rfloor }^{\left\lfloor \frac{r}{\sqrt{3}}\right\rfloor } \left(2 \left\lfloor \sqrt{r^2-3 x^2}\right\rfloor +1\right)+\sum _{x=\frac{1}{2}-\left\lfloor \frac{r}{\sqrt{3}}+\frac{1}{2}\right\rfloor }^{\left\lfloor \frac{r}{\sqrt{3}}+\frac{1}{2}\right\rfloor -\frac{1}{2}} 2 \left\lfloor \sqrt{r^2-3 x^2}+\frac{1}{2}\right\rfloor$$

• Thanks a lot. If you add n[r_] := at the beginning, what does it give? – Ben Bost May 24 '15 at 17:25
• @BenBost With $:=$ it does not work. With $n[r\_] = \ldots$ it gives us exactly the same. – Winther May 24 '15 at 17:28
• @BenBost btw the expression looks like it is approximating the area of a circle. We have $n(r) \sim \frac{2\pi r^2}{\sqrt{3}}$. – Winther May 24 '15 at 17:50
• yes! it gives the number of hexagonal lattice points in a circle. – Ben Bost May 24 '15 at 18:08
• actually you mean $n(r) = \frac{2\pi r^2}{\sqrt{3}}$ when $r$ goes to $\infty$. – Ben Bost May 24 '15 at 18:13

Using TeXForm as Winther suggests is one option, but you need then to process the LaTeX output. A more direct approach to show expression in traditional form is TraditionalForm[expression] or, equivalently, expression // TraditionalForm. Note that you cannot append this by n[r_]:= because you do not want to assign a graphical output to n[r].