3
$\begingroup$

I'm trying to get Mathematica to simplify a piecewise function, but as you can see below it's making some strange errors:

Simplify piecewise functions

  • I'm telling it i and g are integers, so it ought to know that 2g>4+i is extraneous;
  • In the cases where equality is assigned, it doesn't make the obvious substitutions: if 2g=5+i can I make it output an expression involving g instead?
  • Also, can I get it to output the cases "solved for i?" That is, instead of saying 2g>5+i say i<2g-5?

Thanks for any insight!

Edit: Here's a minimal working example:

c = 1;
cPlane = 1;
f[i_] := Piecewise[{{1 + i, 0 <= i < 2*g - 4}, {1 - i, i >= 2*g - 4}}]
w[i_, j_] := Piecewise[{{f[i + 1] - f[j], 0 <= j <= i}, {0, j > i}}]
sigma[i_] := f[i] - c*Sum[w[i, j], {j, 0, i}]

fPlane[i_] := Sum[w[i, j], {j, 0, 2 g - 5}] 
sigmaPlane[i_] := fPlane[i] - cPlane*Sum[w[i, j], {j, 0, i}] 

Refine[FullSimplify[-sigmaPlane[i]/sigma[i], 0 < i && i <= n - 2 && Element[i | g, Integers] && g >= 3]]
$\endgroup$
  • 4
    $\begingroup$ Please enter your code in copy-and-pastable Mathematica code, properly formatted in code blocks. (Use either four-spaces or back-tick marks: see the help for how to do this.) It helps potential answerers here if they can just copy and paste into their own copies of Mathematica. (So: also include your definitions of sigmaPlane and sigma.) $\endgroup$ – march Oct 13 '16 at 15:57
3
$\begingroup$

Perhaps PiecewiseExpand can help:

pwf = FullSimplify[-sigmaPlane[i]/sigma[i], 
   0 < i && i <= n - 2 && Element[i | g, Integers] && g >= 3];

Assuming[0 < i && i <= n - 2 && Element[i | g, Integers] && g >= 3,
 FullSimplify@PiecewiseExpand[-sigmaPlane[i]/sigma[i],
   Method -> {"ConditionSimplifier" -> Simplify, "OrderlessConditions" -> True}]
 ]

Mathematica graphics

$\endgroup$
  • $\begingroup$ @MattGrimes You're welcome! $\endgroup$ – Michael E2 Oct 13 '16 at 18:47

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.