1 | from sage.categories.pushout import ConstructionFunctor |
---|
2 | from sage.structure.element import RingElement |
---|
3 | |
---|
4 | class FunctorA(ConstructionFunctor): |
---|
5 | rank = 1 |
---|
6 | def _apply_functor(self, R): |
---|
7 | if R is ZZ: |
---|
8 | return A() |
---|
9 | return C() |
---|
10 | |
---|
11 | FA = FunctorA(Rings(),Rings()) |
---|
12 | |
---|
13 | class MyRingElement(RingElement): |
---|
14 | def _mul_(self,other): |
---|
15 | return self.parent()(1) |
---|
16 | |
---|
17 | class FunctorB(ConstructionFunctor): |
---|
18 | rank = 2 |
---|
19 | def _apply_functor(self, R): |
---|
20 | if R is ZZ: |
---|
21 | return B() |
---|
22 | return C() |
---|
23 | |
---|
24 | FB = FunctorB(Rings(),Rings()) |
---|
25 | |
---|
26 | class A(UniqueRepresentation,Parent): |
---|
27 | Element = MyRingElement |
---|
28 | def __init__(self): |
---|
29 | Parent.__init__(self, category=Rings()) |
---|
30 | def _element_constructor_(self, *data): |
---|
31 | return self.element_class(parent=self) |
---|
32 | def _repr_(self): |
---|
33 | return "A" |
---|
34 | def construction(self): |
---|
35 | return FA, ZZ |
---|
36 | |
---|
37 | class B(UniqueRepresentation,Parent): |
---|
38 | Element = MyRingElement |
---|
39 | def __init__(self): |
---|
40 | Parent.__init__(self, category=Rings()) |
---|
41 | def _element_constructor_(self, *data): |
---|
42 | return self.element_class(parent=self) |
---|
43 | def _repr_(self): |
---|
44 | return "B" |
---|
45 | def construction(self): |
---|
46 | return FB, ZZ |
---|
47 | |
---|
48 | class C(UniqueRepresentation,Parent): |
---|
49 | Element = MyRingElement |
---|
50 | def __init__(self): |
---|
51 | Parent.__init__(self, category=Rings()) |
---|
52 | def _element_constructor_(self, *data): |
---|
53 | return self.element_class(parent=self) |
---|
54 | def _repr_(self): |
---|
55 | return "C" |
---|
56 | def _coerce_map_from_(self,R): |
---|
57 | return isinstance(R,(A,B,C)) |
---|