4
$\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$
1
  • 5
    $\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, 2016 at 15:57

1 Answer 1

4
$\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$
1
  • $\begingroup$ @MattGrimes You're welcome! $\endgroup$
    – Michael E2
    Oct 13, 2016 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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