# External and internal Assumptions on PiecewiseExpand and Mod

After this question I'm intrigued about the different behaviors depending where and how the assumptions are given.

PiecewiseExpand[Mod[n, m]]    (* case #1 *)
(* Mod[n, m] *)

PiecewiseExpand[Mod[n, m], n == m, Integers]    (* case #2 *)
(* -m + n *)

Assuming[n == m,    (* case #3 *)
FullSimplify@PiecewiseExpand[Mod[n, m]]
]
(* 0 *)

Assuming[n == m,    (* case #4 *)
Simplify@PiecewiseExpand[Mod[n, m]]
]
(* Mod[0, n] *)

Assuming[n == m,    (* case #6 *)
FullSimplify@Mod[n, m]
]
(* 0 *)

Assuming[n == m,    (* case #7 *)
Simplify@Mod[n, m]
]
(* Mod[0, n] *)


Case #5 removed as it was an unrelated bug discussed in this question

How is that explained?

• Items 3 and 4 exhibit the same behavior without PiecewiseExpand[]; item 5 is manifestly a bug. – J. M. will be back soon Oct 9 '15 at 15:41
• \$Assumptions = m > 0 && Element[{n, m}, Integers]; PiecewiseExpand[Mod[n, m]] returns Mod[n, m] – Bob Hanlon Oct 9 '15 at 15:48
• @rhermans I suggest copying case 5 to a new question and tagging it with bugs instead of tagging THIS question :). Although we aren't a bugs repository it's nice to have a highlights catalog. – Dr. belisarius Oct 9 '15 at 15:55