# How to solve Piecewise function in Reduce？

Here I have a Piecewise Function:

f[x_]:=Piecewise[{{53, 0 <= x < 100}, {4, 100 <= x < 102}, {71,
102 <= x < 140}, {29, 140 <= x < 184}, {12, 184 <= x < 190}, {8,
190 <= x < 191}, {28, 191 <= x < 252}, {72, 252 <= x < 293}, {80,
293 <= x < 313}, {15, 313 <= x < 323}, {23, 323 <= x < 355}, {7,
355 <= x < 359}, {10, 359 <= x < 364}, {86, 364 <= x < 373}, {38,
373 <= x < 459}}]


And I have a Reduce:

Reduce[(f[k] >= 53) && (0 <= k < 1807), k, Integers] // ToString


f[k] is the Piecewise Function above, How to write the code? Thanks~

• Square brackets are used for function arguments in Mathematica. You were missing a curly bracket in the Piecewise function definition, and also you were not assigning your Piecewise function to any variable. I edited your post to fix this. Could you provide a bit more information please? What do you expect your code to do? I can run it just fine and I get an output from the Reduce[], but I do not know if this is correct or what your problem is.
– a20
Sep 28 at 9:11

Somewhat improving your code, this can be done as follows.

f[x_] := Piecewise[{{53, 0 <= x < 100}, {4, 100 <= x < 102}, {71,
102 <= x < 140}, {29, 140 <= x < 184}, {12, 184 <= x < 190}, {8,
190 <= x < 191}, {28, 191 <= x < 252}, {72, 252 <= x < 293}, {80,
293 <= x < 313}, {15, 313 <= x < 323}, {23, 323 <= x < 355}, {7,
355 <= x < 359}, {10, 359 <= x < 364}, {86, 364 <= x < 373}, {38,
373 <= x < 459}}]
FullSimplify[Reduce[(f[k] >= 53) && (0 <= k < 1807), k, Integers],
Assumptions -> k \[Element] Integers] // ToString


"0 <= k <= 99 || 101 < k < 140 || 251 < k < 313 || 363 < k < 373"

• Thanks! It really helps me. Sep 30 at 11:37
• But if I want to solve the Reduce which involves two or more variables.How can I write the code? Such as:  f[x_]=..... g[x_]=... FullSimplify[Reduce[(f[a]=g[b]) && (0< a < 100) && (0<b<200) , a , b, Integer.......]]  How can I write this? Could you tell me how to learn writing the code? Sep 30 at 11:40