Opened 7 years ago

Closed 7 years ago

#13708 closed enhancement (fixed)

Get assumptions by variables

Reported by: noud Owned by: Noud
Priority: minor Milestone: sage-5.6
Component: symbolics Keywords: symbolic, assumptions, variable
Cc: Merged in: sage-5.6.beta1
Authors: Noud Aldenhoven, Burcin Erocal Reviewers: Burcin Erocal, Noud Aldenhoven
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by burcin)

Hi everyone,

I'm very exited to create my first ticket and add my first patch. It would be nice if the assumption function could return the assumptions of a variable explicitly. For example:

sage: x, y, z = var('x y z')
sage: assume(x, 'integer')
sage: assume(y > 0)
sage: assume(y**2 + z**2 == 1)
sage: assume(x < 0)
sage: assumptions()
[x is integer, y > 0, y^2 + z^2 == 1, x < 0]
sage: assumptions(x)
['integer', x < 0]
sage: assumptions(x, y)
[x is integer, x < 0, y > 0, y^2 + z^2 == 1]
sage: assumptions(z)   
[y^2 + z^2 == 1]

I'll upload a solution for this suggestion shortly.

Apply: trac_13708_get_assumption_by_variables.patch, trac_13708-eliminate_strings.patch

Attachments (2)

trac_13708_get_assumption_by_variables.patch (2.2 KB) - added by noud 7 years ago.
trac_13708-eliminate_strings.patch (2.3 KB) - added by burcin 7 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by noud

  • Component changed from PLEASE CHANGE to symbolics

comment:2 Changed 7 years ago by noud

I added a patch which allows sage to do the things shown in the Description box. I hope this code makes sense. Please be easy on me, it's my first patch. ;)

Best, Noud

comment:3 Changed 7 years ago by burcin

  • Status changed from new to needs_review
  • Type changed from PLEASE CHANGE to enhancement

Changed 7 years ago by burcin

comment:4 Changed 7 years ago by burcin

  • Authors set to Noud Aldenhoven, Burcin Erocal
  • Description modified (diff)
  • Reviewers set to Burcin Erocal

Thanks for the patch. Your changes look good to me. I attached a referee patch to fix some minor issues:

  • do not use strings to check if an assumption contains a variable
  • minor documentation fix (code blocks should be preceeded by ::)

If you're OK with my changes, feel free to switch this ticket to positive_review.

comment:5 Changed 7 years ago by noud

  • Status changed from needs_review to positive_review

comment:6 follow-up: Changed 7 years ago by noud

Thank you, this seems very nice. I like it.

However I would still like to do something like this:

sage: x = var('x')
sage: assume(x, 'integer')
sage: 'integer' in assumptions(x) # or something in this fashion
True

That's why I added a 'integer' string in the assumption code, but I see that you removed this in the newer patch. I still do not know a nice solution for this (small) problem.

comment:7 in reply to: ↑ 6 ; follow-up: Changed 7 years ago by burcin

  • Reviewers changed from Burcin Erocal to Burcin Erocal, Noud Aldenhoven

Replying to noud:

Thank you, this seems very nice. I like it.

However I would still like to do something like this:

sage: x = var('x')
sage: assume(x, 'integer')
sage: 'integer' in assumptions(x) # or something in this fashion
True

That's why I added a 'integer' string in the assumption code, but I see that you removed this in the newer patch. I still do not know a nice solution for this (small) problem.

I removed that code because treating only the integer case specially is not a good long term solution.

The right way to handle this is via the is_integer() method of symbolic expressions:

sage: var('y', domain=ZZ)
y
sage: y.is_integer()
False
sage: var('a')
a
sage: a.is_integer()
False

Unfortunately, our wrappers around Maxima assumptions don't know anything about these and these don't know about Maxima assumptions. I can't even find a bug to make the two work together. Would you be interested in helping out?

In order to make assumptions set domains in Pynac, all we need to do is add a call to SR.symbol(variable_name, domain=new_domain) in the code for assume() and reset the domain to CC in forget().

This should all be done on a separate ticket of course.

comment:8 in reply to: ↑ 7 Changed 7 years ago by noud

Replying to burcin:

The right way to handle this is via the is_integer() method of symbolic expressions:

sage: var('y', domain=ZZ)
y
sage: y.is_integer()
False
sage: var('a')
a
sage: a.is_integer()
False

Unfortunately, our wrappers around Maxima assumptions don't know anything about these and these don't know about Maxima assumptions. I can't even find a bug to make the two work together. Would you be interested in helping out?

Certainly I would like to help! But I have no idea how to approach. To me it looks like if the function is_integer() should be modified. Could you explain to me a bit better how this works? I also don't get how this should work with SR.symbol.

comment:9 Changed 7 years ago by jdemeyer

  • Milestone changed from sage-5.5 to sage-5.6

comment:10 Changed 7 years ago by robert_dodier

You can ask Maxima to report what it assumptions it has recorded for a variable, via facts(x) where x is the variable of interest. Also, propvars(p) returns the variables for which property p has been declared, e.g. propvars('integer). I'm guessing that it might be preferable to get the report directly from Maxima since that's what actually affects results. Hope this helps.

comment:11 Changed 7 years ago by jdemeyer

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