# Restricting a variable to a (real) range

Hi. I'm solving a differential equation which depends on two parameters $c1$ and $c2$. They are both positive

assume(c1 > 0)
assume(c2 > 0)


but in order to solve the equation, maxima ask me whether c2-3 is positive, negative or zero. With the condition

assume(c2 - 3 > 0)

the equation is solved; But imposing c2 - 3 < 0 triggers and inconsistency... I believe that it is due to the initial assumption.

Question

Is it possible to set a condition like assume(0 < c2 < 3)?

edit retag close merge delete

Sort by » oldest newest most voted

Hello, @Dox. I am not completely sure what the inconsistency you mention is, but maybe it is due to the fact of using two assumes that clash with each other. You said you used

assume(c2 - 3 > 0)


and then you used

assume(c2 - 3 < 0)


So you are effectively telling Sage that $c_2>3$ AND $c_2<3$ at the same time, which represents an inconsistency. You can check this by calling

assumptions()


If both assumptions are there, you made a mistake.

The way to proceed is, once you have finished solving your problem with assume(c2 - 3 > 0) and you have your answer, you should use

forget(c2 - 3 > 0)


and then you can call assume(c2 - 3 < 0) without triggering an inconsistency. (You can check the effect of forget by calling assumptions again.)

Another way to proceed is the following: you should forget the previous assumptions that you made about c2, and then you can call

assume(0 < c2)
assume(c2 < 3)


These will effectively restrict c2 to the range $(0,3)$. (Once again, you can check this, by calling assumptions().)

I hope this helps!

more

Thank you @dsejas Yes, your comment was incredible useful! It drove me to a nice solution. Since I had a lot of assumptions, I was trying to find a way to drop the last assumption (still don't know it possible), and looking for that I found the with assuming(condition): code statement, which execute the code assuming the condition without registering in the assumptions() list! Thank you very much!

( 2019-05-17 14:46:48 -0600 )edit

Hello, @Dox. I'm glad that my answer could help. Actually, I didn't know the syntax

with assuming(condition):    code


Really nice!. However, when you say you were "trying to find a way to drop the last assumption (still don't know if possible)", doesn't the forget(<last_assumption_you_made>) syntax solve your problem? Maybe I can help with that too.

( 2019-05-17 15:04:47 -0600 )edit