Ask Your Question

Restricting a variable to a (real) range

asked 2019-05-17 16:18:03 +0200

Dox gravatar image

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.


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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-17 18:55:21 +0200

dsejas gravatar image

updated 2019-05-17 20:36:57 +0200

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


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!

edit flag offensive delete link 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!

Dox gravatar imageDox ( 2019-05-17 21:46:48 +0200 )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.

dsejas gravatar imagedsejas ( 2019-05-17 22:04:47 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-05-17 16:18:03 +0200

Seen: 790 times

Last updated: May 17 '19