Opened 13 years ago

Closed 12 years ago

#6515 closed defect (fixed)

assume doesn't interact well with solve

Reported by: robertwb Owned by: burcin
Priority: major Milestone: sage-4.3.3
Component: calculus Keywords:
Cc: Merged in: sage-4.3.3.alpha0
Authors: Robert Bradshaw Reviewers: Burcin Erocal
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


This has been brought up several times on the mailing lists. As a specific example

sage: assume(x>0)
sage: solve([x^2-1],x)
[x == -1, x == 1]

At the very least, we could probably filter out the "solutions" that violate the assumptions.

sage: [all(a.subs(s) for a in assumptions()) for s in solve(x^2-1==0, x)]
[False, True]

Attachments (2)

6515-solve-assume.patch (9.1 KB) - added by robertwb 12 years ago.
trac_6515-referee.patch (1.3 KB) - added by burcin 12 years ago.
minor documentation fixes

Download all attachments as: .zip

Change History (11)

comment:1 Changed 12 years ago by kcrisman

It sounds like Maxima (intentionally?) doesn't use assumptions in solve, see for instance and other similar threads. The above solution seems reasonable.

comment:2 Changed 12 years ago by kcrisman

Update: the solution above works well for single equations in one variable, but is tricky to implement for multiple equations (you can't subs x+y==3, for instance). Also, one has to keep in mind how to check assumptions like 'x is Integer', which can't be subs'ed in.

Changed 12 years ago by robertwb

comment:3 Changed 12 years ago by robertwb

  • Report Upstream set to N/A
  • Status changed from new to needs_review

comment:4 Changed 12 years ago by robertwb

It doesn't catch everything, but is better than what we have now.

Changed 12 years ago by burcin

minor documentation fixes

comment:5 Changed 12 years ago by burcin

  • Authors set to Robert Bradshaw
  • Reviewers set to Burcin Erocal

The patch looks good and doctests pass. There is one minor problem, the line

sage: GenericDeclaration(x, 'rational').contradicts(y==pi)

is repeated several times in the doctest for sage.symbolic.assumptions.GenericDeclaration.contradicts().

I attached a patch to change these lines and add an INPUT field to the docstring. Can you look over my patch and change the status to positive_review if you agree with the changes?

comment:6 Changed 12 years ago by robertwb

  • Status changed from needs_review to positive_review

Thanks for looking at this. Nice catches, I approve of your changes.

comment:7 Changed 12 years ago by mpatel

For the record: Applying the patch to 4.3.2 + a long queue gives

applying 6515-solve-assume.patch
patching file sage/symbolic/expression.pyx
Hunk #2 succeeded at 5952 with fuzz 2 (offset 40 lines).
Hunk #3 succeeded at 6037 with fuzz 1 (offset 83 lines).

Please let us know (via sage-devel) about the best order in which to apply the symbolics and calculus patches.

comment:8 Changed 12 years ago by mpatel

The first patch is missing a Mercurial header and the ticket number. I've applied a refreshed patch to 4.3.3.alpha0.

comment:9 Changed 12 years ago by mpatel

  • Merged in set to sage-4.3.3.alpha0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.