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

characteristic() should be an integer #12988

Closed
saraedum opened this issue May 21, 2012 · 14 comments
Closed

characteristic() should be an integer #12988

saraedum opened this issue May 21, 2012 · 14 comments

Comments

@saraedum
Copy link
Member

Currently characteristic() does not return an Integer for some rings:

sage: type(ZZ.characteristic())
<type 'int'>

This is annoying because one cannot for example do:

sage: ZZ.characteristic().is_prime()
AttributeError: 'int' object has no attribute 'is_prime'

I don't see a good reason not to make characteristic always an Integer. The minimal performance loss should not be an issue in any computation that I can imagine.

Depends on #13043

Component: algebra

Keywords: ZZ characteristic sd40.5

Author: Julian Rueth

Reviewer: David Roe, Jeroen Demeyer

Merged: sage-5.1.beta2

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

@saraedum saraedum added this to the sage-5.1 milestone May 21, 2012
@saraedum
Copy link
Member Author

comment:1

I believe it is easiest to check that this is correct through the test framework of the categories.

I added a test to Rings and also one to Fields() checking that it's a prime or zero.

@jdemeyer
Copy link

Changed keywords from ZZ, characteristic to ZZ characteristic sd40.5

@jdemeyer
Copy link

Author: Julian Rueth

@dandrake
Copy link
Contributor

comment:3

It seems like the test suite is not being run:

drake@sagenb:~/s/sage-5.1.beta0$ ./sage -t devel/sage/sage/categories/algebras_with_basis.py
sage -t  "devel/sage/sage/categories/algebras_with_basis.py"
**********************************************************************
File "/home/drake/s/sage-5.1.beta0/devel/sage/sage/categories/algebras_with_basis.py", line 60:
    sage: TestSuite(A).run(verbose=True)
Expected:
    running ._test_additive_associativity() . . . pass
    running ._test_an_element() . . . pass
    running ._test_associativity() . . . pass
    running ._test_category() . . . pass
    running ._test_characteristic() . . . pass
    running ._test_distributivity() . . . pass
    running ._test_elements() . . .
      Running the test suite of self.an_element()
      running ._test_category() . . . pass
      running ._test_eq() . . . pass
      running ._test_not_implemented_methods() . . . pass
      running ._test_pickling() . . . pass      pass
    running ._test_elements_eq() . . . pass
    running ._test_eq() . . . pass
    running ._test_not_implemented_methods() . . . pass
    running ._test_one() . . . pass
    running ._test_pickling() . . . pass
    running ._test_prod() . . . pass
    running ._test_some_elements() . . . pass
    running ._test_zero() . . . pass
Got:
    running ._test_additive_associativity() . . . pass
    running ._test_an_element() . . . pass
    running ._test_associativity() . . . pass
    running ._test_category() . . . pass
    running ._test_distributivity() . . . pass
    running ._test_elements() . . .
      Running the test suite of self.an_element()
      running ._test_category() . . . pass
      running ._test_eq() . . . pass
      running ._test_not_implemented_methods() . . . pass
      running ._test_pickling() . . . pass
      pass
    running ._test_elements_eq() . . . pass
    running ._test_eq() . . . pass
    running ._test_not_implemented_methods() . . . pass
    running ._test_one() . . . pass
    running ._test_pickling() . . . pass
    running ._test_prod() . . . pass
    running ._test_some_elements() . . . pass
    running ._test_zero() . . . pass

It's expecting to see the characteristic test, but that test is not run. I don't know the categories and test frameworks well enough to fix this. Do you see what's wrong?

@saraedum
Copy link
Member Author

comment:4

That's strange. I'll run the doctests again to see if this also happens here.

Actually _test_characteristic didn't catch wrong characteristic() implementations in some cases which is related to #13043. I'll upload an updated patch soon.

@saraedum
Copy link
Member Author

Dependencies: #13043

@saraedum
Copy link
Member Author

Attachment: trac_12988.patch.gz

move characteristic() to the category of rings and check that it is in ZZ

@dandrake
Copy link
Contributor

comment:6

This now passes doctests, and every example that I've tried successfully returns Integer characteristic. But I would like someone who understands the category framework and the test framework a bit better to look at this. Consider your patch to have a weak positive review.

@roed314
Copy link
Contributor

roed314 commented May 28, 2012

comment:7

This looks good to me.

@jdemeyer
Copy link

Reviewer: David Roe

@jdemeyer
Copy link

comment:9

3 doctest failures with sage-5.1.beta1:

sage -t  "devel/sage-main/sage/rings/padics/padic_base_leaves.py"
**********************************************************************
File "/usr/local/src/sage-5.1.beta1/devel/sage-main/sage/rings/padics/padic_base_leaves.py", line 168:
    sage: TestSuite(R).run()
Expected nothing
Got:
    Failure in _test_characteristic:
    Traceback (most recent call last):
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/misc/sage_unittest.py", line 275, in run
        test_method(tester = tester)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/categories/rings.py", line 258, in _test_characteristic
        tester.assertEqual(type(characteristic),sage.rings.integer.Integer)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 509, in assertEqual
        assertion_func(first, second, msg=msg)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 502, in _baseAssertEqual
        raise self.failureException(msg)
    AssertionError: <type 'int'> != <type 'sage.rings.integer.Integer'>
    ------------------------------------------------------------
    The following tests failed: _test_characteristic
**********************************************************************
File "/usr/local/src/sage-5.1.beta1/devel/sage-main/sage/rings/padics/padic_base_leaves.py", line 175:
    sage: TestSuite(R).run()
Expected nothing
Got:
    Failure in _test_characteristic:
    Traceback (most recent call last):
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/misc/sage_unittest.py", line 275, in run
        test_method(tester = tester)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/categories/rings.py", line 258, in _test_characteristic
        tester.assertEqual(type(characteristic),sage.rings.integer.Integer)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 509, in assertEqual
        assertion_func(first, second, msg=msg)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 502, in _baseAssertEqual
        raise self.failureException(msg)
    AssertionError: <type 'int'> != <type 'sage.rings.integer.Integer'>
    ------------------------------------------------------------
    The following tests failed: _test_characteristic
**********************************************************************
File "/usr/local/src/sage-5.1.beta1/devel/sage-main/sage/rings/padics/padic_base_leaves.py", line 182:
    sage: TestSuite(R).run()
Expected nothing
Got:
    Failure in _test_characteristic:
    Traceback (most recent call last):
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/misc/sage_unittest.py", line 275, in run
        test_method(tester = tester)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python/site-packages/sage/categories/rings.py", line 258, in _test_characteristic
        tester.assertEqual(type(characteristic),sage.rings.integer.Integer)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 509, in assertEqual
        assertion_func(first, second, msg=msg)
      File "/usr/local/src/sage-5.1.beta1/local/lib/python2.7/unittest/case.py", line 502, in _baseAssertEqual
        raise self.failureException(msg)
    AssertionError: <type 'int'> != <type 'sage.rings.integer.Integer'>
    ------------------------------------------------------------
    The following tests failed: _test_characteristic
**********************************************************************

@saraedum
Copy link
Member Author

Attachment: trac_12988_padic.patch.gz

fix characteristic for padics

@jdemeyer
Copy link

jdemeyer commented Jun 1, 2012

Changed reviewer from David Roe to David Roe, Jeroen Demeyer

@jdemeyer
Copy link

jdemeyer commented Jun 2, 2012

Merged: sage-5.1.beta2

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

5 participants