Opened 8 years ago
Closed 8 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 )
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)
Change History (13)
comment:1 Changed 8 years ago by
- Component changed from PLEASE CHANGE to symbolics
Changed 8 years ago by
comment:2 Changed 8 years ago by
comment:3 Changed 8 years ago by
- Status changed from new to needs_review
- Type changed from PLEASE CHANGE to enhancement
Changed 8 years ago by
comment:4 Changed 8 years ago by
- 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 8 years ago by
- Status changed from needs_review to positive_review
comment:6 follow-up: ↓ 7 Changed 8 years ago by
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: ↓ 8 Changed 8 years ago by
- 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 TrueThat'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 8 years ago by
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() FalseUnfortunately, 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 8 years ago by
- Milestone changed from sage-5.5 to sage-5.6
comment:10 Changed 8 years ago by
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 8 years ago by
- Merged in set to sage-5.6.beta1
- Resolution set to fixed
- Status changed from positive_review to closed
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