# How do I introduce an assumption when defining a piecewise function?

Define m as an integer. I want to specify a Piecewise function f[x,n] that takes value n^3 x^2 except when x divides m(n+1). At these values, I want f[x,n]=1.

I can't figure out how to do this because I can't work out how to include the assumption that m is an integer. I have

f[x_, n_] :=
Piecewise[{
{1, x ∈ Divisors[m (n + 1)]},
{x^2  n^(1/2), x ∉ Divisors[m (n + 1)]}
},
Assumptions -> m ∈ Integers];
table =Table[f[x, n], {x, 1, 5}, {n, 0, 5}]


This doesn't work. How do I do it?

• It's not clear what you're trying to do with m and the assumptions. Is m symbolic or numerical? If numerical, this is very simple: f[x_, n_] := Piecewise[{{n^3 *x^2, Mod[x, m (m + 1)] != 0}, {1, Mod[x, m (m + 1)] == 0}}] - but if m is symbolic, then this doesn't make any sense. – flinty Jul 13 '20 at 16:22
• Hi @flinty. The Mod trick works if I eliminate the use of m entirely - it was just a dummy variable to stand for "integer multiples of n+1". Thank you. If you could tweak and post it as an answer, I'll tick it. – Richard Burke-Ward Jul 13 '20 at 18:08
• Maybe ConditionalExpression is what you need? – Sjoerd Smit Jul 13 '20 at 18:43

## 1 Answer

As m is just an integer multiple of n+1, you can do this with Mod:

f[x_, n_] := Piecewise[{{1, Mod[x, n+1] == 0}}, n^3 *x^2]

f[4, 3] (* returns 1 *)
f[5, 3] (* returns 675 == 3^3 * 5^2 *)

table = Table[f[x, n], {x, 1, 5}, {n, 0, 5}]
(* returns: {{1, 1, 8, 27, 64, 125}, {1, 1, 32, 108, 256, 500}, {1, 9, 1, 243,
576, 1125}, {1, 1, 128, 1, 1024, 2000}, {1, 25, 200, 675, 1, 3125}} *)