Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get assumptions by variables #13708

Closed
sagetrac-noud mannequin opened this issue Nov 13, 2012 · 12 comments
Closed

Get assumptions by variables #13708

sagetrac-noud mannequin opened this issue Nov 13, 2012 · 12 comments

Comments

@sagetrac-noud
Copy link
Mannequin

sagetrac-noud mannequin commented Nov 13, 2012

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: attachment: trac_13708_get_assumption_by_variables.patch, attachment: trac_13708-eliminate_strings.patch

Component: symbolics

Keywords: symbolic, assumptions, variable

Author: Noud Aldenhoven, Burcin Erocal

Reviewer: Burcin Erocal, Noud Aldenhoven

Merged: sage-5.6.beta1

Issue created by migration from https://trac.sagemath.org/ticket/13708

@sagetrac-noud sagetrac-noud mannequin added this to the sage-5.5 milestone Nov 13, 2012
@sagetrac-noud sagetrac-noud mannequin added the p: minor / 4 label Nov 13, 2012
@sagetrac-noud sagetrac-noud mannequin self-assigned this Nov 13, 2012
@sagetrac-noud sagetrac-noud mannequin added the c: symbolics label Nov 13, 2012
@sagetrac-noud
Copy link
Mannequin Author

sagetrac-noud mannequin commented Nov 13, 2012

@sagetrac-noud
Copy link
Mannequin Author

sagetrac-noud mannequin commented Nov 13, 2012

comment:2

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

@burcin
Copy link

burcin commented Nov 19, 2012

Author: Noud Aldenhoven, Burcin Erocal

@burcin
Copy link

burcin commented Nov 19, 2012

Reviewer: Burcin Erocal

@burcin

This comment has been minimized.

@burcin
Copy link

burcin commented Nov 19, 2012

comment:4

Attachment: trac_13708-eliminate_strings.patch.gz

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.

@sagetrac-noud
Copy link
Mannequin Author

sagetrac-noud mannequin commented Nov 20, 2012

comment:6

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.

@burcin
Copy link

burcin commented Nov 21, 2012

comment:7

Replying to @sagetrac-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.

@burcin
Copy link

burcin commented Nov 21, 2012

Changed reviewer from Burcin Erocal to Burcin Erocal, Noud Aldenhoven

@sagetrac-noud
Copy link
Mannequin Author

sagetrac-noud mannequin commented Nov 26, 2012

comment:8

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.

@jdemeyer jdemeyer modified the milestones: sage-5.5, sage-5.6 Nov 27, 2012
@sagetrac-robert-dodier
Copy link
Mannequin

sagetrac-robert-dodier mannequin commented Nov 29, 2012

comment:10

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.

@jdemeyer
Copy link

Merged: sage-5.6.beta1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants