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

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach showsWReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector patternInjector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[+x]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[+x]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[+x]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
deleted 5 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[Plus[x]]HoldForm[+x]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[Plus[x]]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[+x]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
added 264 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[Plus[x]]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[Plus[x]]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#1

Trott-Strzebonski in-place evaluation:

hf = HoldForm[1 - 1^2/2 + 1^3/3 - 1^4/4 + 1^5/5 - 1^6/6]

hf /. x_Times :> With[{eval = x}, eval /; True]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
Replace[hf, x_ :> With[{eval = x}, eval /; True], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

One may simplify this method using the undocumented function RuleCondition as WReach shows:

Replace[hf, x_ :> RuleCondition[x], {2}]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6

#2

Injector pattern:

{1, -(1/2), 1/3, -(1/4), 1/5, -(1/6)} /. {x__} :> HoldForm[Plus[x]]
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6
added 109 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading