Let's try a more complicated expression that states an inequality between two functions. We'll use plots to illustrate what's happening:
forget() expr = -20 * x - 30 <= 4 * x^3 - 7 * x print("Expression {0} is {1}".format(expr, bool(expr))) p1 = plot(expr.left(), (x, -5, 5), legend_label='lhs') p2 = plot(expr.right(),(x, -5, 5), color='red', legend_label='rhs') assume(x > 0) print("Now assume x > 0") print("Expression {0} is {1}".format(expr, bool(expr))) show(p1 + p2)
The output is shown in the following screenshot:
We started the example with a call to the forget
function, to clear any assumptions that we may have made in other cells. The first expression evaluated to False
, because the expression on the left-hand side is greater than the expression on the right-hand side over part of the domain. However, when we used the assume
statement to assert that x>0, the expression evaluated to True
....