2
$\begingroup$

I'm using Mathematica to compare some constants. Before playing around with those constants, I would like to check that I didn't make any mistake in typing them. So my question is the following: "What is the command that return the expression I typed?"

Just to be clear. The expression

4*Sum[Log[Gamma[k]], {k, 3, IntegerPart[n] + 2*(n - IntegerPart[n])}]

returns:

enter image description here

And that is what I want. On the other hand, the expression

Sum[(2*n - 2*m - 1)*Log[n*(m + 1)], {m, 0, IntegerPart[n] - 1}]

returns:

enter image description here

and that is what I want to avoid!

$\endgroup$
5
  • 1
    $\begingroup$ You can use Hold and its variants. $\endgroup$ Mar 25, 2013 at 10:58
  • 1
    $\begingroup$ And it's best to post code, so people can copy/paste and try for themselves. $\endgroup$ Mar 25, 2013 at 10:59
  • $\begingroup$ Thank you for the fast reply! I'm sorry for non-posting code. I'll keep it in mind for next questions. $\endgroup$ Mar 25, 2013 at 11:02
  • $\begingroup$ Just edit the question and paste in the actual code. This makes for a better question and a better site. $\endgroup$
    – Jagra
    Mar 25, 2013 at 11:58
  • $\begingroup$ @Jagra You're definitely right! I edited my question, is it fine now? :) $\endgroup$ Mar 25, 2013 at 13:38

2 Answers 2

5
$\begingroup$

What you want is probably HoldForm but I don't understand why you cannot just check what you typed and why you need it to be printed again:

HoldForm[Sum[(2 n - 2 m - 1)*Log[n (m + 1)], {m, 0, IntegerPart[n] - 1}]]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Yes, this is exactly what I was looking for! At the beginning I was trying to do that because it's just simpler to check long expression in the form I'm used to do that. After I while I was just refusing to believe that there wasn't a proper command on Mathematica (I could't find it googling around)! $\endgroup$ Mar 25, 2013 at 13:32
  • 1
    $\begingroup$ Welcome to the 20K club. Congratulations! :-) $\endgroup$
    – Mr.Wizard
    Mar 25, 2013 at 19:11
6
$\begingroup$

What you could do is

SetOptions[Sum, Method -> None]

Then

Sum[(2 n - 2 m - 1)*Log[n (m + 1)], {m, 0, IntegerPart[n] - 1}]

does not evaluate, similar to like @halirutans solution. The advantage is that you can control this globally and do not have to put HoldForm everywhere.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer! In this specific case I'm fine with the "local" solution, but it's good to have another tool at disposal if needed. $\endgroup$ Mar 25, 2013 at 15:43

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.