sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.33k stars 453 forks source link

polynomial .reduce returns type int over p-adic field #13903

Closed bhutz closed 11 years ago

bhutz commented 11 years ago

The .reduce() function for a polynomial ring can return an 'int' type when the base field is a p-adic field.

R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex')
G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3]
type((y2^3).reduce(G))

It should be returning an element of the polynomial ring.

This was noticed since it causes .variety() to fail.

R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex')
G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3]
I=ideal(G)
I.variety()

Some discussion at: https://groups.google.com/forum/?fromgroups=#!topic/sage-support/Ar7z2b5cOic

Apply:

attachment: trac_13903-reviewed.patch

Component: algebra

Keywords: polynomial reduce

Author: John Perry

Reviewer: Karl-Dieter Crisman

Merged: sage-5.6.beta3

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

johnperry-math commented 11 years ago

Description changed:

--- 
+++ 
@@ -1,18 +1,15 @@
 The .reduce() function for a polynomial ring can return an 'int' type when the base field is a p-adic field.

-R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex')
-G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3]
-type((y2^3).reduce(G))
-
+```
+R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') G=[y1^2^ + y2^2^, y1*y2 + y2^2^, y2^3^] type((y2^3^).reduce(G))
+```
 It should be returning an element of the polynomial ring.

 This was noticed since it causes .variety() to fail.

-R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex')
-G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3]
+```
+R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') G=[y1^2^ + y2^2^, y1*y2 + y2^2^, y2^3^]
 I=ideal(G)
 I.variety()
-
-
+```
 Some discussion at: https://groups.google.com/forum/?fromgroups=#!topic/sage-support/Ar7z2b5cOic
-
johnperry-math commented 11 years ago
comment:1

I fixed some formatting issues with the ticket description.

johnperry-math commented 11 years ago

Description changed:

--- 
+++ 
@@ -1,14 +1,17 @@
 The .reduce() function for a polynomial ring can return an 'int' type when the base field is a p-adic field.

-R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') G=[y1^2^ + y2^2^, y1y2 + y2^2^, y2^3^] type((y2^3^).reduce(G)) +R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') +G=[y1^2 + y2^2, y1y2 + y2^2, y2^3] +type((y2^3).reduce(G))

 It should be returning an element of the polynomial ring.

 This was noticed since it causes .variety() to fail.

-R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') G=[y1^2^ + y2^2^, y1y2 + y2^2^, y2^3^] +R.<y1,y2>=PolynomialRing(Qp(5),2, order='lex') +G=[y1^2 + y2^2, y1y2 + y2^2, y2^3] I=ideal(G) I.variety()

johnperry-math commented 11 years ago
comment:2

And promptly broke them, as well. (It looked good before I hit submit, honest!) Okay, I'll try again...

I can work on this, if no one else has their heart set on it.

kcrisman commented 11 years ago

Changed author from Ben Hutz to none

kcrisman commented 11 years ago
comment:3

Please do! If it's a simple fix of type, maybe I can review it for you.

johnperry-math commented 11 years ago
comment:4

Replying to @kcrisman:

Please do! If it's a simple fix of type, maybe I can review it for you.

It would be very easy if I could figure out how I pooched my development environment. I have a working fix, but mercurial doesn't seem to notice the changes. I hate it when this happens.

johnperry-math commented 11 years ago

Attachment: trac_13903.patch.gz

simple patch + doctest

johnperry-math commented 11 years ago
comment:5

I said it was an easy fix. This bug has burned me in other contexts, so it wasn't hard to find and fix.

johnperry-math commented 11 years ago

Description changed:

--- 
+++ 
@@ -16,3 +16,7 @@
 I.variety()

Some discussion at: https://groups.google.com/forum/?fromgroups=#!topic/sage-support/Ar7z2b5cOic + +Apply: + +* attachment: trac_13903.patch

kcrisman commented 11 years ago
comment:7

I still get

sage: I=ideal(G)
sage: I.variety()
verbose 0 (3482: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation.
verbose 0 (1359: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
verbose 0 (2365: multi_polynomial_ideal.py, variety) Warning: falling back to very slow toy implementation.
verbose 0 (3482: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation.
[{y1: O(5^20), y2: O(5^20)}]

but presumably that's okay. I'm uploading a slight refresh of your patch to use our new(ish) :trac: markup, and fixed the other non-occurrence of that in the file (there were several with the new markup already).

kcrisman commented 11 years ago

Attachment: trac_13903-reviewed.patch.gz

Apply only this

kcrisman commented 11 years ago
comment:8

Patchbot, apply trac_13903-reviewed.patch

kcrisman commented 11 years ago

Reviewer: Karl-Dieter Crisman

kcrisman commented 11 years ago

Author: John Perry

kcrisman commented 11 years ago

Description changed:

--- 
+++ 
@@ -19,4 +19,4 @@

 **Apply**:

-* [attachment: trac_13903.patch](https://github.com/sagemath/sage-prod/files/10656872/trac_13903.patch.gz)
+* [attachment: trac_13903-reviewed.patch](https://github.com/sagemath/sage-prod/files/10656873/trac_13903-reviewed.patch.gz)
johnperry-math commented 11 years ago
comment:9

Replying to @kcrisman:

I still get

sage: I=ideal(G)
sage: I.variety()
verbose 0 (3482: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation.
verbose 0 (1359: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
verbose 0 (2365: multi_polynomial_ideal.py, variety) Warning: falling back to very slow toy implementation.
verbose 0 (3482: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation.
[{y1: O(5^20), y2: O(5^20)}]

but presumably that's okay.

If you mean that the warnings are bothering you, then yes, that's okay. Unless I misread the Singular manual, it doesn't deal with Qp, though I could be wrong (I know next to nothing about p-adics, and Singular does deal with Zp). If Singular DOES implement Qp, then we haven't yet implemented that interface. That should be another ticket, though, because this bug would likely pop up even if we weren't in Qp.

I'm uploading a slight refresh of your patch to use our new(ish) :trac: markup...

Hunh. I didn't know about that. I wonder if I can remember it for the future... ;-)

bhutz commented 11 years ago
comment:10

Thanks. This looked good on my tests as well.

Yes, that result from .variety() is the correct final answer, well really the result is the point (1:0:0) in projective space Qp, but up to precision that is what is returned. The warnings I ignored ;)

jdemeyer commented 11 years ago

Merged: sage-5.6.beta3