Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunctionUsing Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

(3 + Sin[t])/2

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

(3 + Sin[t])/2

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

(3 + Sin[t])/2

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

added 22 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"] 

(3 + Sin[t])/2

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"] 

(3 + Sin[t])/2

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

added 335 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

There are multiple internal forms of x / 2 apparently. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] * expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

There are multiple internal forms of x / 2 apparently. I ran into the same problem here:
Using Hold correctly with Simplify and ComplexityFunction

This appears to work:

MakeBoxes[expr_ / 2 | Rational[1, 2] * expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

Mathematica graphics

There are multiple internal forms of x / 2. I ran into the same problem here (with 1/4):
Using Hold correctly with Simplify and ComplexityFunction

This appears to work in all cases:

MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := 
  FractionBox[MakeBoxes[expr, fmt], "2"]

Mathematica graphics

You can better see what is going on with FullForm:

HoldForm @ FullForm[expr_/2]
HoldForm @ FullForm[Rational[1, 2]*expr_]
Times[Pattern[expr,Blank[]],Power[2,-1]]
Times[Rational[1,2],Pattern[expr,Blank[]]]

You need to cover both the Power[2,-1] and Rational[1, 2] cases with your pattern.

Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading