3
$\begingroup$

I want Mathematica to display negative exponents always as fractions. I already tried:

Needs["Notation`"]
(* Notation[1/a_^b_ <==> a_^-b_] *)
Notation[
  ParsedBoxWrapper[RowBox[{"1", "/", RowBox[{"a_", "^", "b_"}]}]]
  ⟺ 
  ParsedBoxWrapper[RowBox[{"a_", "^", RowBox[{"-", "b_"}]}]]]

While I do have

x^-z
1/x^z 

the following doesn't work:

x^-(2z)
x^-2z

Some hints ? Thank you very much !

$\endgroup$
  • $\begingroup$ Thank you @Sektor for reformatting ! $\endgroup$ – Mark May 11 '14 at 11:41
  • $\begingroup$ You are welcome ! If you are still experiencing troubles in the future, please, refer to the help centre for code formatting practices :) $\endgroup$ – Sektor May 11 '14 at 11:54
0
$\begingroup$

I found a working solution for my case. It still uses the Notation Package and makes use of PatternWrappers:

Here is the Code:

Needs["Notation`"]
(*Notation[1/Simplify[a_^(-b_ c_)] <==> a_^TemplateBox[b_?Negative] c_]*)
(*Notation[(a_^d_)/Simplify[a_^(-b_ c_)] <==> a_^TemplateBox[b_?Negative] c_+d_]*)
ClearNotations[]
Notation[ParsedBoxWrapper[
FractionBox["1", 
SuperscriptBox["", 
TemplateBox[{
RowBox[{"Simplify", "[", 
SuperscriptBox["a_", 
RowBox[{
RowBox[{"-", "b_"}], " ", "c_"}]], "]"}]}, 
  "NotationPatternTag"]]]] \[DoubleLongLeftArrow] ParsedBoxWrapper[
SuperscriptBox["a_", 
RowBox[{
TemplateBox[{
RowBox[{"b_", "?", "Negative"}]}, "NotationPatternTag"], " ", "c_"}]]]]
Notation[ParsedBoxWrapper[
FractionBox[
SuperscriptBox["a_", "d_"], 
TemplateBox[{
RowBox[{"Simplify", "[", 
SuperscriptBox["a_", 
RowBox[{
RowBox[{"-", "b_"}], " ", "c_"}]], "]"}]}, 
  "NotationPatternTag"]]] \[DoubleLongLeftArrow] ParsedBoxWrapper[

SuperscriptBox["a_", 
RowBox[{
RowBox[{
TemplateBox[{
RowBox[{"b_", "?", "Negative"}]}, "NotationPatternTag"], " ", "c_"}], 
   "+", "d_"}]]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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