On Nov 11, 2008, at 1:53 AM, Ralf Hemmecke wrote: > On 11/10/2008 10:31 PM, koffie wrote: >>> sage: C = VectorSpaces(GF(5)) >>> sage: C >>> Category of vector spaces over Finite Field of size 5 >>> sage: W = (ZZ^3).span([[1,2,3],[4,5,3]]) >>> sage: W >>> >>> Free module of degree 3 and rank 2 over Integer Ring >>> Echelon basis matrix: >>> [1 2 3] >>> [0 3 9] >>> sage: C(W) >>> >>> Vector space of degree 3 and dimension 2 over Finite Field of size 5 >>> Basis matrix: >>> [1 0 2] >>> [0 1 3] >>> >>> That looks to me as if C is like a coercion function. >> >>> Ralf >> >> Wel looking at it mathematically, you would like C to be some functor >> from free modules over Z to vectorspases over Finite Fields of >> size 5. > > I have nothing against functors. However, as I understand, C is a > >>> Category of vector spaces over Finite Field of size 5 > > and that does not sound like a "functor". > >> And taking this in mind I think this is a good behaviour of C(W), >> since this behaviour is for example similar to that of F5(x) in the >> example below: >> sage: F5=GF(5) >> sage: F5 >> Finite Field of size 5 >> sage: x=ZZ(102) >> sage: F5(x) >> 2 > >> That is F5() tries to make an element in F5() of 102 as C tries to >> make a vectorfield over GF(5) out of W. So maybe it is also not >> bad to >> have coercion functions defined for categories. > > In in the above form "ZZ(102)" and "F5(x)" you basically use ZZ and F5 > to denote a type cast. That is what I called "coercion" (which is > basically a function ZZ -> F5).
In Sage, we use the term "coercion" to denote a canonical (using the term a bit loosely), implicit map between Parents (or objects of a concrete category). E.g. from ZZ to F5 would be a "coercion," but there is a "conversion" and not a "coercion" the other direction. Coercions are invoked to do arithmetic, but conversions are not. For example sage: F5.coerce_map_from(ZZ) Natural morphism: From: Integer Ring To: Finite Field of size 5 sage: f = F5.coerce_map_from(ZZ) sage: f(3) 3 sage: f(943) 3 sage: ZZ.coerce_map_from(F5) # there isn't one sage: ZZ.convert_map_from(F5) Conversion via _integer_ method map: From: Finite Field of size 5 To: Integer Ring Eventually, that last one will be a lift map (that's essentially what it is, but I haven't gotten around to moving the finite fields to the new model yet... currently it's exposing the implementation details). > My question now (still being a bit unfamiliar with python) would be, > where can I find the documentation of what is allowed for x in > something > like F5(x). I guess F5("some string") does not work. I'd like to be > sure > that code I write does not break at runtime. A pointer to the > documentation is highly appreciated. F5(...) calls the F5.__call__ method. If F5 were a type, this (eventually, in the basic case) calls the __init__ method on an instance of that type. Depending on what was implemented, anything could be valid. They are used as constructors, and the general philosophy is "make an element of the right type if at all possible." Thus, sage: F5("some string") Traceback (most recent call last): ... TypeError: unable to convert x (=some string) to an integer sage: F5('2') 2 Just as this casting notation works to force elements in one object into another by invoking the appropriate morphism, it can be used to force objects in one category into another by invoking the appropriate functor. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---