#15976: IntegerLattice class
-------------------------------------+-------------------------------------
       Reporter:  malb               |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.2
      Component:  linear algebra     |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Martin Albrecht    |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/malb/15976_integer_lattice       |  a13b4aad3e9578866922d01932e6abac02687718
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Hi Martin!

 You asked me to have a look at your code from the categorical point of
 view.

 It really depends what you want to model.

 Currently, you start on top of `SageObject`, which is about as basic as it
 can be. A `SageObject` hasn't even support for different categories. So,
 if for you a lattice is not more than an object, then it's fine.

 A bit less basic is `CategoryObject`, which is for objects in arbitrary
 categories. In particular, it would be a suitable starting point for
 objects that do not have elements (i.e., whose category is not a sub-
 category of the category of sets). So, if you want that your lattice is a
 semigroup, but you do not want to implement elements of the semigroup,
 then it's fine---almost. AFAIK, it ''is'' mathematically possible to
 define the notion of a semigroup just in terms of morphisms and direct
 products, and it is not needed to refer to elements in the definition.
 However, Sage's category framework expects semigroups to be sets, and thus
 the `TestSuite` would complain that element creation fails.

 If your lattices are supposed to be groups (in particular, sets), then the
 lattice should inherit from `Parent`, and you should implement elements as
 well, inheriting from `Element` (or rather `ModuleElement`, since you want
 to add elements). I guess it would be fine to import some implementation
 of integer vectors (I am sure those things exist somewhere in Sage), and
 assign it as a class attribute `IntegerLattice.Element`.

 Next, ''if'' you decide to inherit from `Parent` and assign `.Element`,
 you should do `self._init_category_(Groups())` (or a better category, if
 there is any) during initialisation of your lattice. This should be enough
 to enable element creation and let the test suites
 (`TestSuite(YourLattice).run()`) pass. If it isn't---well, then we'll take
 care of it later.

 It could make sense to have a look at
 `sage.combinat.free_module.CombinatorialFreeModule` and
 `sage.combinat.free_module.CombinatorialFreeModuleElement`. I have not
 much experience with it, but I know that people use it to implement all
 kind of things, including algebras. And it does inherit from `Parent`.

 On a different note: Would it make sense to use `UniqueRepresentation` or
 at least `CachedRepresentation` for lattices? It seems strange to me to
 have a function `Lattice` that does nothing more than hand the arguments
 to the `IntegerLattice` constructor and return the result.

 Provided that you want some kind of caching for your lattices, you could
 do
 {{{
 #!python
 class Lattice(CachedRepresentation, Parent):
     "This is a stub, non-integral lattices will be implemented later"
     Element =
     @staticmethod
     def __classcall_private__(cls, basis, lll_reduce):
         # do some preprocessing of arguments, throw
         # an error if the basis is not integral
         return IntegerLattice(preprocessed_basis, lll_reduce)
     def __cmp__(...):
         # We don't inherit from UniqueRepresentation, hence, we admit the
         # possibility that different bases result in the same lattice.
         # Perhaps move this to IntegerLattice, unless the same algorithm
         # would work for general lattices.

 class IntegerLattice(Lattice):
     ...
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/15976#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to