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

factor ignores complex conjugate #36833

Closed
2 tasks done
jlportner opened this issue Dec 7, 2023 · 6 comments · Fixed by #36841
Closed
2 tasks done

factor ignores complex conjugate #36833

jlportner opened this issue Dec 7, 2023 · 6 comments · Fixed by #36841
Labels
Milestone

Comments

@jlportner
Copy link

Steps To Reproduce

  1. I run SageMath version 10.2, Release Date: 2023-12-03.
  2. When I enter the following commands:
y = SR.var("y") # or y = var("y")
f = y * conjugate(y)
f.factor()
  1. This returns y^2 which is clearly not true for y being complex.

Expected Behavior

The expected result for this would be to just return y * conjugate(y) as by documentation when declaring y as a variable of SR it is assumed that y is in the complex plain.

Actual Behavior

The factor function treats y as a real variable and thus returns the wrong result of y^2.

Additional Information

No response

Environment

- **OS**: Arch Linux
- **Kernel**: Linux 6.6.4-arch1-1
- **Sage Version**: 10.2
- **Python Version**: 3.11.6

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@jlportner
Copy link
Author

From my understanding the problem comes from the declaration of the var function in the SymbolicRing class.

def var(self, name, latex_name=None, n=None, domain=None):

Since no domain is assumed here in the default case this is passed on downwards and therefore complex is never assumed.
So either domain=None should be replaced with domain =CC or the documentation should be changed to reflect that by default the variables are actually not in the complex plane.

@RuchitJagodara
Copy link
Contributor

@jlportner,
Can you tell me the file location where you found this var funciton as I am new to this organization and not able to find that.

@jlportner
Copy link
Author

I found it in the file src/sage/symbolic/ring.pyx in line 751. I don't know how to properly reference such locations.

@RuchitJagodara
Copy link
Contributor

RuchitJagodara commented Dec 8, 2023

I checked it and I found that the issue is 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, where we are assuming that the variable is in complex plane by default which is correct according to the documentation.

@RuchitJagodara
Copy link
Contributor

RuchitJagodara commented Dec 9, 2023

@jlportner I have created a PR, can you review it ?

@dimpase
Copy link
Member

dimpase commented Dec 10, 2023

How about

sage: y = SR.var("y", domain="complex")
sage: factor(y*conjugate(y))
y*conjugate(y)

I'm not sure whether making domain="complex" the default is what we want.

vbraun pushed a commit to vbraun/sage that referenced this issue Jan 5, 2024
    
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
@vbraun vbraun closed this as completed in 9b73d6c Jan 14, 2024
@mkoeppe mkoeppe added this to the sage-10.3 milestone Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants