Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want every output expression in a notebook to use //PowerExpand and also to format numbers as scientific. Is there a way to do this without explicitly calling ScientificForm[] and //PowerExpand on every input?

i.e. I want to be able to enter

In: 4.3*^-5*Sqrt[M]*(L*n^2)^{3/4}
Out: {0.000043 \Sqrt[M] (L n^2)^(3/4)}

and instead get,

Out: 4.3e-5 M^(1/2} L^(3/4} n^(3/2)

Aside: is there a way to make mathematica never use radical symbols, and to use exponents instead?

share|improve this question
1  
I suggest re-posting your final line as a separate question. It seems both interesting and potentially difficult. –  Mr.Wizard May 31 at 20:12
    
Great idea, I've posted a new question here –  zhermes May 31 at 23:17

2 Answers 2

up vote 4 down vote accepted

With

$PrePrint = ScientificForm@PowerExpand@# &

You would get the desired output. To return to normal just type:

$PrePrint =.
share|improve this answer
    
Thanks! This is working on a new notebook, but when I put it into my existing notebook, and re-run my cells - they keep the same format. Any ideas? –  zhermes May 30 at 19:43

It seems you are using a variation of my comments-in-output code from Notebook formatting - easier descriptions for equations and results? The variation you are using does not actually produce any formal output; it merely prints the evaluated form as a side-effect. Despite its name $PrePrint does not affect the lines produced by Print, as these are not considered output.

You can either add ScientificForm and PowerExpand to your modified $PreRead function:

$PreRead = Replace[#, 
    RowBox[{body__, ";", note_String?(StringMatchQ[#, "\"*\""] &)}] :> 
     Print[ScientificForm @ PowerExpand @ ToExpression@RowBox@{body}, Spacer[50], 
      Style[ToExpression@note, Italic, Red]]] &;

Or as I would prefer you can add it to my original code:

$note = Null;

$PreRead =
      Replace[#,
        RowBox[{body__, ";", note_String?(StringMatchQ[#, "\"*\""] &)}] :>
         ($note = Style[ToExpression@note, Italic, Red]; RowBox[{body}])
  ] &;

$PrePrint = 
      If[$note =!= Null,
    # &[Row[{Pane@#, Spacer[50], $note}], $note = Null],
    #
  ] & @ ScientificForm @ PowerExpand @ # &;
share|improve this answer
    
Thanks so much! This made everything work perfectly. I'm giving the 'accepted' answer to eldo as he did most appropriately answer the question I (naively) asked. –  zhermes May 31 at 19:54
    
@zhermes You're welcome, and no problem. –  Mr.Wizard May 31 at 20:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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