-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Change default domain of SR.var() #36841
Conversation
This is a fix to the issue trac:`36833`. Variables whose domain is not defined should be considered in the complex plane by default as described in the documentation.
36ef7f7
to
7d10eb2
Compare
src/sage/symbolic/ring.pyx
Outdated
@@ -862,6 +862,16 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): | |||
Traceback (most recent call last): | |||
... | |||
ValueError: cannot specify n for multiple symbol names | |||
|
|||
Check that :trac:`36833` is fixed: Variables whose domain is not | |||
defined should be considered in complex plane as described in documentation:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you point out where in documentation you see this " considered in complex plane" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
we might see lots of doctest errors now, not sure. |
Then, I think it would be good if we change the factor function instead of doing this. I'll change it and will update. |
@dimpase Do you know any function that can return the domain of a symbolic variable? |
no, I don't. By the way, I just saw the place where it's claimed that |
Can't we implement a new class for variables of symbolic ring? By this method, we will be able to track domain of the variable and once we are able to access the domain of variable, I think it will be easier to handle these type of issues. |
I don't think it's a good idea to make sage: y = SR.var("y",domain="complex")
sage: f(y) = y * conjugate(y)
sage: f.diff(y)
y |--> y*diff(conjugate(y), y) + conjugate(y) doesn't make much sense, as in fact |
Hmm, got it. But when we declare a variable without declaring any domain, it is clear that it is not real from the following, sage: n = SR.var("n"); n
n
sage: n.is_real()
False So it simply implies that it is complex. So I am not getting the point that what is wrong here, if the variable is not real then it should not be simplified to y^2, anyhow. But factor function is doing so. I think the error is occurring with the maxima. Actually maxima is simplifying many functions which should not be simplified like 0^n is being converted to 0 (this is referenced from the issue #36838 ) , here y * conjugate(y) is being converted to y^2. |
On 12 December 2023 15:48:25 GMT, Ruchit Jagodara ***@***.***> wrote:
Hmm, got it. But when we declare a variable without declaring any domain, it is clear that it is not real from the following,
```python
sage: n = SR.var("n"); n
n
sage: n.is_real()
False
```
So it simply implies that it is complex.
it'd imply this if our docs were correct:-)
By default `domain=None`, and it could be that `is_real()` just checked that.
So I am not getting the point that what is wrong here, if the variable is not real then it should not be simplified to y^2, anyhow. But factor function is doing so. I think the error is occurring with the maxima. Actually maxima is simplifying many functions which should not be simplified like 0^n is being converted to 0 (this is referenced from the issue #36838 ) , here y * conjugate(y) is being converted to y^2.
maxima has no concept of a domain for a variable, it seems to me.
|
But it has to be, because when we do operation like below sage: n = var('n',domain="complex"); n
n
sage: f1 = n * conjugate(n); f1
n*conjugate(n)
sage: f1.factor()
n*conjugate(n) Here, we can clearly see that it is giving correct answer if we declare domain="complex", but it is not giving the same answer when we do it as below, which means it has something to do with the domain. sage: b = var("b")
sage: f2 = b * conjugate(b); f2
b*conjugate(b)
sage: f2.factor()
b^2 |
Sorry, indeed, you are right. Maxima has domain, which is a domain for computation to be done (although it's not to declare that a variable is real or complex) , and a similar thing called Better, it has declare - which seems to be exactly what is needed here. So one can do
|
Hmm... But in sage when we are doing this sage: y = SR.var("y","real"); y
y
sage: f = y * conjugate(y); f
y*conjugate(y)
sage: f
y*conjugate(y)
sage: f.simplify_full()
y^2 Here, you can see that for variable whose domain is real, it is not simplifying conjugate(y) and for that I have to use simplify_full() function but I think this should be done when we were multiplying y with conjuage(y) so the value of f should be y^2 not y*conjugate(y). |
Check whether the default domain=real working or not.
I found an issue where one had similar problem with maxima, discussion link |
Should I change the documentation instead, which may specify that the default domain of |
Yes, please, we are not going to make the default domain |
Changed the documentation of var function.
Sorry for the delay! Actually, I was checking if there is any other fix that can be applied, but I think we cannot do anything as the problem is with maxima only. So, I have changed the documentation. Can you please review my changes now ? |
Documentation preview for this PR (built with commit 053d50c; changes) is ready! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
This patch fixes sagemath#36833 by changing the default domain of SR.var() function to complex. By this way, every variable whose domain is not defined will be considered in complex plane, by default. The issue was with the default value only because whenever we were defining a variable without specifying any domain it was calling symbol() function with domain=None; Subsequently, it calls new_Expression_symbol() function with domain=None. In this code, I found that it was not giving any specific domain to the variable and so when we define a new variable using SR.var() function, it is passing the is_real() (Because it does not have any specific domain) test but giving the wrong answer on factor() function, if we assume that the variable is in complex plane by default which is correct according to the documentation. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36841 Reported by: Ruchit Jagodara Reviewer(s): Dima Pasechnik, Ruchit Jagodara
This patch fixes #36833 by changing the default domain of SR.var()
function to complex. By this way, every variable whose domain is not defined will be considered
in complex plane, by default.
The issue was with the default value only because whenever we were defining a variable without specifying any domain it was calling symbol() function with domain=None; Subsequently, it calls new_Expression_symbol() function with domain=None. In this code, I found that it was not giving any specific domain to the variable and so when we define a new variable using SR.var() function, it is passing the is_real() (Because it does not have any specific domain) test but giving the wrong answer on factor() function, if we assume that the variable is in complex plane by default which is correct according to the documentation.
📝 Checklist