# Reduce doesn't work with user defined function with /;

I want to use Reduce to my own function, but it generates the error message: This system cannot be solved with the methods available to Reduce. Here is a simplified example.

test[x_] := x^2 - 3 /; 0<x<10;
test[x_] := -1 /; 10<x

Reduce[test[x]<1, 0<x<5]


I think /; makes the problem. However, how can I define the domain of my own function without using /;?

• Piecewise lets you define such functions. Also it probably should be Reduce[test[x] && 0<x<5, x]. Jul 1, 2020 at 8:42
• @Natas gave the answer, I just wanted to add that /; is a programming construct. It is not meant to represent mathematical ideas. It is meant to implement algorithms. Jul 1, 2020 at 8:52
• I think I remember people saying that Boole had been incorporated into many functions in Mathematica. test[x_]:=((x^2-3)*Boole[0<x<10])+(-1*Boole[10<x]); Reduce[test[x]<1&&0<x<5,x]
– Bill
Jul 1, 2020 at 9:10

To summarize insightful comments, Piecewise is the appropriate construct to express the mathematical idea of a piecewise function, as Natas suggested. Condition (i.e. /;) is a programming construct. As Szabolcs mentioned, "it is not meant to represent mathematical ideas; it is meant to implement algorithms". In the following, note also the corrected syntax for Reduce.

Clear[test]
test[x_] := Piecewise[{{x^2 - 3, 0 < x < 10}, {-1, x > 10}}]
Reduce[test[x] < 1 && 0 < x < 5, x]

(* Out: 0 < x < 2 *)


As an alternative approach, Bill proposed using Boole:

Clear[test]
test[x_] := ((x^2 - 3)*Boole[0 < x < 10]) + (-1*Boole[10 < x]);
Reduce[test[x] < 1 && 0 < x < 5, x]

(* Out: 0 < x < 2 *)

• Thank you so much! Piecewise works very well. However, when I try to compare with the other user-defined function, it takes forever.... For example, Reduce[{test[x]>test2[x],0<x<2}] never returns the output... If I take the expressions out from the user-defined functions, then it works well. For example, Reduce[{x^2 - 3 > x + 2, 0<x<2}] works well. How can I make user-defined functions practically callable inside of Reduce? Jul 1, 2020 at 19:54
• What are the definitions of test and test2? Does it make a difference if you add the variable to be solved for explicitly, as we have been suggesting? Reduce[{test[x] > test2[x], 0 < x < 2}, x] Jul 2, 2020 at 0:05