Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#5105 closed enhancement (fixed)

[with patch; positive review] behaviour of the norm function in the p-adic ring

Reported by: L J P Kilford Owned by: David Roe
Priority: minor Milestone: sage-4.0
Component: padics Keywords:
Cc: Merged in: 4.0.alpha0
Authors: David Roe Reviewers: Robert Bradshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

The p-adic norm seems to be defined differently in SAGE to the standard textbook definition, in which it is usually normalized so that $|p|=1/p$, but this is what SAGE does:

sage: Q11=pAdicField(11)
sage: n=Q11(11)
sage: n.norm()
11 + O(11^21)

Would it be possible to swap it round so that the norm of 11 is given as 1/11?

Attachments (1)

trac_5105.patch (5.6 KB) - added by David Roe 14 years ago.
Implements abs() and exlains the difference between it and norm()

Download all attachments as: .zip

Change History (10)

comment:1 Changed 14 years ago by Michael Abshoff

Milestone: sage-3.4sage-3.4.1

3.4 is for ReST tickets only.

Cheers,

Michael

comment:2 Changed 14 years ago by Francis Clarke

Type: defectenhancement

There is a confusion of terminology here. It's the "field norm" that's defined for p-adics. Thus

sage: Q11 = pAdicField(11, 6)
sage: F.<a> = Q11.ext(x^2 - 2)
sage: (2 + 3*a).norm()
8 + 9*11 + 10*11^2 + 10*11^3 + 10*11^4 + 10*11^5 + O(11^6)
sage: (2 + 3*a)*(2 - 3*a)
8 + 9*11 + 10*11^2 + 10*11^3 + 10*11^4 + 10*11^5 + O(11^6)

So

sage: Q11(22).norm()
2*11 + O(11^7)

is correct, as is

sage: QQ(-163).norm()
-163

What you're wanting is usually called the p-adic absolute value (it's a norm in the functional analysis sense). It would be good if one could do

sage: Q11(22).abs()

and get 1/11. This isn't currently defined, if z is an element of a padic field, the absolute value can be obtained as

z.parent().prime()^(-z.ordp())

comment:3 Changed 14 years ago by David Roe

Summary: behaviour of the norm function in the p-adic ring[with patch; needs review] behaviour of the norm function in the p-adic ring

comment:4 Changed 14 years ago by John Cremona

Summary: [with patch; needs review] behaviour of the norm function in the p-adic ring[with patch; with review, needs work] behaviour of the norm function in the p-adic ring

I thought this looked good, and it applied ok to 3.4.1.rc1, but I got a whole lot of doctest failures in sage/rings/padics:

The following tests failed:


        sage -t  "devel/sage-5105/sage/rings/padics/padic_generic.py"
        sage -t  "devel/sage-5105/sage/rings/padics/padic_ZZ_pX_CA_element.pyx"
        sage -t  "devel/sage-5105/sage/rings/padics/padic_ZZ_pX_element.pyx"
        sage -t  "devel/sage-5105/sage/rings/padics/pow_computer_ext.pyx"
        sage -t  "devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx"
        sage -t  "devel/sage-5105/sage/rings/padics/padic_ZZ_pX_CR_element.pyx"
        sage -t  "devel/sage-5105/sage/rings/padics/padic_printing.pyx"

Most look like this:

sage -t  "devel/sage-5105/sage/rings/padics/padic_generic.py"
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_generic.py", line 304:
    sage: y = W.teichmuller(3); y
Exception raised:
    Traceback (most recent call last):
      File "/home/jec/sage-3.4.1.rc1/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/jec/sage-3.4.1.rc1/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/jec/sage-3.4.1.rc1/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_11[14]>", line 1, in <module>
        y = W.teichmuller(Integer(3)); y###line 304:
    sage: y = W.teichmuller(3); y
      File "sage_object.pyx", line 98, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1342)
      File "padic_generic_element.pyx", line 212, in sage.rings.padics.padic_generic_element.pAdicGenericElement._repr_ (sage/rings/padics/padic_generic_element.c:6185)
      File "padic_printing.pyx", line 373, in sage.rings.padics.padic_printing.pAdicPrinter_class.repr_gen (sage/rings/padics/padic_printing.cpp:8469)
      File "padic_printing.pyx", line 460, in sage.rings.padics.padic_printing.pAdicPrinter_class._repr_gen (sage/rings/padics/padic_printing.cpp:9866)
      File "padic_printing.pyx", line 580, in sage.rings.padics.padic_printing.pAdicPrinter_class._repr_spec (sage/rings/padics/padic_printing.cpp:12415)
      File "padic_ext_element.pyx", line 171, in sage.rings.padics.padic_ext_element.pAdicExtElement._ext_p_list (sage/rings/padics/padic_ext_element.cpp:3643)
      File "padic_ext_element.pyx", line 162, in sage.rings.padics.padic_ext_element.pAdicExtElement.ext_p_list (sage/rings/padics/padic_ext_element.cpp:3540)
    NotImplementedError
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_generic.py", line 310:
    sage: b = A.teichmuller(1 + 2*a - a^2); b
Exception raised:
    Traceback (most recent call last):
      File "/home/jec/sage-3.4.1.rc1/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/jec/sage-3.4.1.rc1/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/jec/sage-3.4.1.rc1/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_11[18]>", line 1, in <module>
        b = A.teichmuller(Integer(1) + Integer(2)*a - a**Integer(2)); b###line 310:
    sage: b = A.teichmuller(1 + 2*a - a^2); b
      File "sage_object.pyx", line 98, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1342)
      File "padic_generic_element.pyx", line 212, in sage.rings.padics.padic_generic_element.pAdicGenericElement._repr_ (sage/rings/padics/padic_generic_element.c:6185)
      File "padic_printing.pyx", line 373, in sage.rings.padics.padic_printing.pAdicPrinter_class.repr_gen (sage/rings/padics/padic_printing.cpp:8469)
      File "padic_printing.pyx", line 460, in sage.rings.padics.padic_printing.pAdicPrinter_class._repr_gen (sage/rings/padics/padic_printing.cpp:9866)
      File "padic_printing.pyx", line 580, in sage.rings.padics.padic_printing.pAdicPrinter_class._repr_spec (sage/rings/padics/padic_printing.cpp:12415)
      File "padic_ext_element.pyx", line 171, in sage.rings.padics.padic_ext_element.pAdicExtElement._ext_p_list (sage/rings/padics/padic_ext_element.cpp:3643)
      File "padic_ext_element.pyx", line 162, in sage.rings.padics.padic_ext_element.pAdicExtElement.ext_p_list (sage/rings/padics/padic_ext_element.cpp:3540)
    NotImplementedError
**********************************************************************
1 items had failures:
   2 of  20 in __main__.example_11

while there also some simpler ones:

File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_CR_element.pyx", line 80:
    sage: y.precision_relative()
Expected:
    20
Got:
    2
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_CR_element.pyx", line 82:
    sage: y.precision_absolute()
Expected:
    24
Got:
    6

and

sage -t  "devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx"
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1214:
    sage: ((1+2*w)^5).norm()
Expected:
    1 + 5^2 + O(5^5)
Got:
    1 + O(5^2)
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1216:
    sage: ((1+2*w)).norm()^5
Expected:
    1 + 5^2 + O(5^5)
Got:
    1 + O(5^2)
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1246:
    sage: a.trace()
Expected:
    3*5 + 2*5^2 + 3*5^3 + 2*5^4 + O(5^5)
Got:
    O(5)
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1248:
    sage: a.trace() + b.trace()
Expected:
    4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
Got:
    O(5)
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1250:
    sage: (a+b).trace()
Expected:
    4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
Got:
    O(5)
**********************************************************************
File "/home/jec/sage-3.4.1.rc1/devel/sage-5105/sage/rings/padics/padic_ZZ_pX_FM_element.pyx", line 1277:
    sage: c._ntl_rep()
Expected:
    [89 9 4 1]
Got:
    [4 4 4]
**********************************************************************
3 items had failures:
   2 of   8 in __main__.example_29
   3 of  11 in __main__.example_30
   1 of   8 in __main__.example_31
***Test Failed*** 6 failures.
For whitespace errors, see the file /home/jec/sage-3.4.1.rc1/tmp/.doctest_padic_ZZ_pX_FM_element.py
         [1.4 s]

I have absolutely no idea what in the patch has caused this, but it needs to be looked at!

comment:5 Changed 14 years ago by Michael Abshoff

Component: number theorypadics
Owner: changed from William Stein to David Roe

comment:6 Changed 14 years ago by Michael Abshoff

Summary: [with patch; with review, needs work] behaviour of the norm function in the p-adic ring[with patch; with review] behaviour of the norm function in the p-adic ring

I guess this is reviewed by #5778 and the issues reported here due to doctest failures have been fixed there.

Cheers,

Michael

Changed 14 years ago by David Roe

Attachment: trac_5105.patch added

Implements abs() and exlains the difference between it and norm()

comment:7 Changed 14 years ago by Michael Abshoff

Summary: [with patch; with review] behaviour of the norm function in the p-adic ring[with patch; positive review] behaviour of the norm function in the p-adic ring

Positive review due to #5778 - credit goes to RobertWB.

Cheers,

Michael

comment:8 Changed 14 years ago by Michael Abshoff

Resolution: fixed
Status: newclosed

Merged in Sage 4.0.alpha0.

Cheers,

Michael

comment:9 Changed 13 years ago by David Loeffler

Authors: David Roe
Merged in: 4.0.alpha0
Reviewers: Robert Bradshaw
Note: See TracTickets for help on using tickets.