2
$\begingroup$

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 /;?

$\endgroup$
3
  • 4
    $\begingroup$ Piecewise lets you define such functions. Also it probably should be Reduce[test[x] && 0<x<5, x]. $\endgroup$ Commented Jul 1, 2020 at 8:42
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Jul 1, 2020 at 8:52
  • 3
    $\begingroup$ 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] $\endgroup$ Commented Jul 1, 2020 at 9:10

1 Answer 1

3
$\begingroup$

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 *) 
$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$ Commented Jul 1, 2020 at 19:54
  • $\begingroup$ 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] $\endgroup$ Commented Jul 2, 2020 at 0:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.