| 32 | }}} |
| 33 | |
| 34 | Now: |
| 35 | {{{ |
| 36 | sage: abgrps = CommutativeAdditiveGroups() |
| 37 | sage: ForgetfulFunctor(abgrps, abgrps) |
| 38 | The identity functor on Category of commutative additive groups |
| 39 | }}} |
| 40 | |
| 41 | 2. Bug: Applying `ForgetfulFunctor` returns `None`. |
| 42 | |
| 43 | Was: |
| 44 | {{{ |
| 45 | sage: fields = Fields() |
| 46 | sage: rings = Rings() |
| 47 | sage: F = ForgetfulFunctor(fields,rings) |
| 48 | sage: F(QQ) |
| 49 | }}} |
| 50 | |
| 51 | Now: |
| 52 | {{{ |
| 53 | sage: fields = Fields() |
| 54 | sage: rings = Rings() |
| 55 | sage: F = ForgetfulFunctor(fields,rings) |
| 56 | sage: F(QQ) |
| 57 | Rational Field |
| 58 | }}} |
| 59 | |
| 60 | 3. Bug: Applying a functor does not complain if the argument is not contained in the domain. |
| 61 | |
| 62 | Was: |
| 63 | {{{ |
| 64 | sage: fields = Fields() |
| 65 | sage: rings = Rings() |
| 66 | sage: F = ForgetfulFunctor(fields,rings) |
| 67 | # Yields None, see previous bug |
| 68 | sage: F(ZZ['x','y']) |
| 69 | }}} |
| 70 | |
| 71 | Now: |
| 72 | {{{ |
| 73 | sage: fields = Fields() |
| 74 | sage: rings = Rings() |
| 75 | sage: F = ForgetfulFunctor(fields,rings) |
| 76 | sage: F(ZZ['x','y']) |
| 77 | Traceback (most recent call last): |
| 78 | ... |
| 79 | TypeError: x (=Multivariate Polynomial Ring in x, y over Integer Ring) is not in Category of fields |
| 80 | }}} |
| 81 | |
| 82 | 4. Bug: Comparing identity functor with any functor only checks domain and codomain |
| 83 | |
| 84 | Was: |
| 85 | {{{ |
| 86 | sage: F = QQ['x'].construction()[0] |
| 87 | sage: F |
| 88 | Poly[x] |
| 89 | sage: F == IdentityFunctor(Rings()) |
| 90 | False |
| 91 | sage: IdentityFunctor(Rings()) == F |
| 92 | True |
| 93 | }}} |
| 94 | |
| 95 | Now: |
| 96 | {{{ |
| 97 | sage: F = QQ['x'].construction()[0] |
| 98 | sage: F |
| 99 | Poly[x] |
| 100 | sage: F == IdentityFunctor(Rings()) |
| 101 | False |
| 102 | sage: IdentityFunctor(Rings()) == F |
| 103 | False |
| 104 | }}} |
| 105 | |
| 106 | 5. Bug: Comparing identity functor with anything that is not a functor produces an error |
| 107 | |
| 108 | Was: |
| 109 | {{{ |
| 110 | sage: IdentityFunctor(Rings()) == QQ |
| 111 | Traceback (most recent call last): |
| 112 | ... |
| 113 | AttributeError: 'RationalField_with_category' object has no attribute 'domain' |
| 114 | }}} |
| 115 | |
| 116 | Now: |
| 117 | {{{ |
| 118 | sage: IdentityFunctor(Rings()) == QQ |
| 119 | False |
| 120 | }}} |
| 121 | |
| 122 | 6. Bug: The matrix functor is ill defined; moreover, ill-definedness does not result in an error. |
| 123 | |
| 124 | Was: |
| 125 | {{{ |
| 126 | sage: F = MatrixSpace(ZZ,2,3).construction()[0] |
| 127 | sage: F(RR) in F.codomain() |
| 128 | False |
| 129 | # The codomain is wrong for non-square matrices! |
| 130 | sage: F.codomain() |
| 131 | Category of rings |
| 132 | }}} |
| 133 | |
| 134 | Now: |
| 135 | {{{ |
| 136 | sage: F = MatrixSpace(ZZ,2,3).construction()[0] |
| 137 | sage: F.codomain() |
| 138 | Category of commutative additive groups |
| 139 | sage: F(RR) in F.codomain() |
| 140 | True |
| 141 | sage: F = MatrixSpace(ZZ,2,2).construction()[0] |
| 142 | sage: F.codomain() |
| 143 | Category of rings |
| 144 | sage: F(RR) in F.codomain() |
| 145 | True |
| 146 | }}} |
| 147 | |
| 148 | 7. Bug: Wrong domain for `VectorFunctor`; and again, functors don't test if the domain is appropriate |
| 149 | |
| 150 | Was: |
| 151 | {{{ |
| 152 | sage: F = FreeModule(ZZ,3).construction()[0] |
| 153 | sage: F |
| 154 | VectorFunctor |
| 155 | sage: F.domain() |
| 156 | Category of objects |
| 157 | sage: F.codomain() |
| 158 | Category of objects |
| 159 | sage: Set([1,2,3]) in F.domain() |
| 160 | True |
| 161 | sage: F(Set([1,2,3])) |
| 162 | Traceback (most recent call last): |
| 163 | ... |
| 164 | AttributeError: 'Set_object_enumerated' object has no attribute 'is_commutative' |
| 165 | }}} |
| 166 | |
| 167 | Now: |
| 168 | {{{ |
| 169 | sage: F = FreeModule(ZZ,3).construction()[0] |
| 170 | sage: F |
| 171 | VectorFunctor |
| 172 | sage: F.domain() |
| 173 | Category of commutative rings |
| 174 | sage: Set([1,2,3]) in F.domain() |
| 175 | False |
| 176 | sage: F(Set([1,2,3])) |
| 177 | Traceback (most recent call last): |
| 178 | ... |
| 179 | TypeError: x (={1, 2, 3}) is not in Category of commutative rings |
| 180 | }}} |
| 181 | |
| 182 | 8. Bug: `BlackBoxConstructionFunctor` is completely unusable |
| 183 | |
| 184 | `BlackBoxConstructionFunctor` should be a class, but is defined as a function. Moreover, the given init method is not using the init method of `ConstructionFunctor`. And the cmp method would raise an error if the second argument has no attribute `.box`. |
| 185 | |
| 186 | The following did not work at all: |
| 187 | {{{ |
| 188 | sage: from sage.categories.pushout import BlackBoxConstructionFunctor |
| 189 | sage: FG = BlackBoxConstructionFunctor(gap) |
| 190 | sage: FS = BlackBoxConstructionFunctor(singular) |
| 191 | sage: FG |
| 192 | BlackBoxConstructionFunctor |
| 193 | sage: FG(ZZ) |
| 194 | Integers |
| 195 | sage: FG(ZZ).parent() |
| 196 | Gap |
| 197 | sage: FS(QQ['t']) |
| 198 | // characteristic : 0 |
| 199 | // number of vars : 1 |
| 200 | // block 1 : ordering lp |
| 201 | // : names t |
| 202 | // block 2 : ordering C |
| 203 | sage: FG == FS |
| 204 | False |
| 205 | sage: FG == loads(dumps(FG)) |
| 206 | True |
24 | | The forgetful functor should coincide with the identity functor, but inside ``ForgetfulFunctor``, the latter is called in the wrong way. |
| 208 | |
| 209 | 9. Nitpicking: The `LocalizationFunctor` is nowhere used (yet) |
| 210 | |
| 211 | Hence, I removed it. |
| 212 | |
| 213 | 10. Bug / New Feature: Make completion and and fraction field construction functors commute. |
| 214 | |
| 215 | The result of them not commuting is the following coercion bug. |
| 216 | |
| 217 | Was: |
| 218 | {{{ |
| 219 | sage: R1.<x> = Zp(5)[] |
| 220 | sage: R2 = Qp(5) |
| 221 | sage: R2(1)+x |
| 222 | Traceback (most recent call last): |
| 223 | ... |
| 224 | TypeError: unsupported operand parent(s) for '+': '5-adic Field with capped relative precision 20' and 'Univariate Polynomial Ring in x over 5-adic Ring with capped relative precision 20' |
| 225 | }}} |
| 226 | |
| 227 | Now: |
| 228 | {{{ |
| 229 | sage: R1.<x> = Zp(5)[] |
| 230 | sage: R2 = Qp(5) |
| 231 | sage: R2(1)+x |
| 232 | (1 + O(5^20))*x + (1 + O(5^20)) |
| 233 | }}} |
| 234 | |
| 235 | 11. New feature: Make the completion functor work on some objects that do not provide a completion method. |
| 236 | |
| 237 | The idea is to use that the completion functor may commute with the construction of the given argument. That may safe the day. |
| 238 | |
| 239 | Was: |
| 240 | {{{ |
| 241 | sage: P.<x> = ZZ[] |
| 242 | sage: C = P.completion(x).construction()[0] |
| 243 | sage: R = FractionField(P) |
| 244 | sage: hasattr(R,'completion') |
| 245 | False |
| 246 | sage: C(R) |
| 247 | Traceback (most recent call last): |
| 248 | ... |
| 249 | AttributeError: 'FractionField_generic' object has no attribute 'completion' |
| 250 | }}} |
| 251 | |
| 252 | Now: |
| 253 | {{{ |
| 254 | sage: P.<x> = ZZ[] |
| 255 | sage: C = P.completion(x).construction()[0] |
| 256 | sage: R = FractionField(P) |
| 257 | sage: hasattr(R,'completion') |
| 258 | False |
| 259 | sage: C(R) |
| 260 | Fraction Field of Power Series Ring in x over Integer Ring |
| 261 | }}} |
| 262 | |
| 263 | 12. Bug / new feature: Coercion for free modules, taking into account a user-defined inner product |
| 264 | |
| 265 | Was: |
| 266 | {{{ |
| 267 | sage: P.<t> = ZZ[] |
| 268 | sage: M1 = FreeModule(P,3) |
| 269 | sage: M2 = QQ^3 |
| 270 | sage: M2([1,1/2,1/3]) + M1([t,t^2+t,3]) # This is ok |
| 271 | (t + 1, t^2 + t + 1/2, 10/3) |
| 272 | sage: M3 = FreeModule(P,3, inner_product_matrix = Matrix(3,3,range(9))) |
| 273 | sage: M2([1,1/2,1/3]) + M3([t,t^2+t,3]) # This is ok |
| 274 | (t + 1, t^2 + t + 1/2, 10/3) |
| 275 | # The user defined inner product matrix is lost! Bug |
| 276 | sage: parent(M2([1,1/2,1/3]) + M3([t,t^2+t,3])).inner_product_matrix() |
| 277 | [1 0 0] |
| 278 | [0 1 0] |
| 279 | [0 0 1] |
| 280 | }}} |
| 281 | |
| 282 | Now: |
| 283 | {{{ |
| 284 | sage: parent(M2([1,1/2,1/3]) + M3([t,t^2+t,3])).inner_product_matrix() |
| 285 | [0 1 2] |
| 286 | [3 4 5] |
| 287 | [6 7 8] |
| 288 | }}} |
| 289 | |
| 290 | However, the real problem is that modules are not part of the coercion model. I tried to implement it, but that turned out to be a can of worms. So, '''I suggest to deal with it on a different ticket'''. Here is one bug that isn't removed, yet: |
| 291 | {{{ |
| 292 | sage: M4 = FreeModule(P,3, inner_product_matrix = Matrix(3,3,[1,1,1,0,1,1,0,0,1])) |
| 293 | sage: M3([t,1,t^2]) + M4([t,t^2+t,3]) # This should result in an error |
| 294 | (2*t, t^2 + t + 1, t^2 + 3) |
| 295 | }}} |
| 296 | Note that there should be no coercion between `M3` and `M4`, since they have different user-defined inner product matrices. |
| 297 | |
| 298 | |
| 299 | 13. Bug / new feature: Quotient rings of univariate polynomial rings do not have a construction method. |
| 300 | |
| 301 | Was: |
| 302 | {{{ |
| 303 | sage: P.<x> = QQ[] |
| 304 | sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) |
| 305 | sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) |
| 306 | sage: from sage.categories.pushout import pushout |
| 307 | sage: pushout(Q1,Q2) |
| 308 | Traceback (most recent call last): |
| 309 | ... |
| 310 | CoercionException: No common base |
| 311 | }}} |
| 312 | |
| 313 | Now: |
| 314 | {{{ |
| 315 | sage: P.<x> = QQ[] |
| 316 | sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) |
| 317 | sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) |
| 318 | sage: from sage.categories.pushout import pushout |
| 319 | sage: pushout(Q1,Q2) |
| 320 | Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 |
| 321 | }}} |
| 322 | |
| 323 | 14. Insufficient coercion of quotient rings, if one modulus divides the other |
| 324 | |
| 325 | Was: |
| 326 | {{{ |
| 327 | sage: P5.<x> = GF(5)[] |
| 328 | sage: Q = P5.quo([(x^2+1)^2]) |
| 329 | sage: P.<x> = ZZ[] |
| 330 | sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) |
| 331 | sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) |
| 332 | sage: Q.has_coerce_map_from(Q1) |
| 333 | False |
| 334 | }}} |
| 335 | |
| 336 | Now: There is a coercion from `Q1` to `Q`. |
| 337 | |
| 338 | 15. Coercion of `GF(p)` versus `Integers(p)` |
| 339 | |
| 340 | I am not sure if this is really a bug. |
| 341 | |
| 342 | Was: |
| 343 | {{{ |
| 344 | sage: from sage.categories.pushout import pushout |
| 345 | sage: pushout(GF(5), Integers(5)) |
| 346 | Ring of integers modulo 5 |
| 347 | }}} |
| 348 | |
| 349 | Now |
| 350 | {{{ |
| 351 | sage: from sage.categories.pushout import pushout |
| 352 | sage: pushout(GF(5), Integers(5)) |
| 353 | Finite Field of size 5 |
| 354 | }}} |
| 355 | |
| 356 | 16. Bug / new feature: Construction for QQbar was missing. |
| 357 | |
| 358 | Now: |
| 359 | {{{ |
| 360 | sage: QQbar.construction() |
| 361 | (AlgebraicClosureFunctor, Rational Field) |
| 362 | }}} |
| 363 | |
| 364 | 17. Bug / new feature: Construction for number fields is missing. |
| 365 | |
| 366 | This became a rather complicated topic, including "coercions for embedded versus non-embedded number fields and coercion for an order from a coercion from the ambient field", "pushout for number fields", "comparison of fractional ideals", "identity of residue fields". See three discussions on sage-algebra and sage-nt |
| 367 | * [http://groups.google.com/group/sage-nt/browse_thread/thread/32b65a5173f43267 Bidirectional coercions] |
| 368 | * [http://groups.google.com/group/sage-nt/browse_thread/thread/5c376dbf7e99ea97 Coercions for number fields] |
| 369 | * [http://groups.google.com/group/sage-nt/browse_thread/thread/54c1e33872d14334 Comparison of fractional ideals] |
| 370 | |
| 371 | __Coercion__ |
| 372 | |
| 373 | Was: |
| 374 | {{{ |
| 375 | sage: K.<r4> = NumberField(x^4-2) |
| 376 | sage: L1.<r2_1> = NumberField(x^2-2, embedding = r4**2) |
| 377 | sage: L2.<r2_2> = NumberField(x^2-2, embedding = -r4**2) |
| 378 | sage: r2_1+r2_2 # indirect doctest |
| 379 | ERROR: An unexpected error occurred while tokenizing input |
| 380 | The following traceback may be corrupted or invalid |
| 381 | The error message is: ('EOF in multi-line statement', (1109, 0)) |
| 382 | |
| 383 | ERROR: An unexpected error occurred while tokenizing input |
| 384 | The following traceback may be corrupted or invalid |
| 385 | The error message is: ('EOF in multi-line statement', (1109, 0)) |
| 386 | |
| 387 | ... |
| 388 | sage: K.has_coerce_map_from(L1.maximal_order()) |
| 389 | False # that's the wrong direction. |
| 390 | sage: L1.has_coerce_map_from(K.maximal_order()) |
| 391 | True |
| 392 | }}} |
| 393 | |
| 394 | Now: |
| 395 | {{{ |
| 396 | sage: K.<r4> = NumberField(x^4-2) |
| 397 | sage: L1.<r2_1> = NumberField(x^2-2, embedding = r4**2) |
| 398 | sage: L2.<r2_2> = NumberField(x^2-2, embedding = -r4**2) |
| 399 | sage: r2_1+r2_2 # indirect doctest |
| 400 | 0 |
| 401 | sage: (r2_1+r2_2).parent() is L1 |
| 402 | True |
| 403 | sage: (r2_2+r2_1).parent() is L2 |
| 404 | True |
| 405 | sage: K.has_coerce_map_from(L1.maximal_order()) |
| 406 | True |
| 407 | sage: L1.has_coerce_map_from(K.maximal_order()) |
| 408 | False |
| 409 | }}} |
| 410 | |
| 411 | __Pushout__ |
| 412 | |
| 413 | Was: |
| 414 | {{{ |
| 415 | sage: P.<x> = QQ[] |
| 416 | sage: L.<b> = NumberField(x^8-x^4+1, embedding=CDF.0) |
| 417 | sage: M1.<c1> = NumberField(x^2+x+1, embedding=b^4-1) |
| 418 | sage: M2.<c2> = NumberField(x^2+1, embedding=-b^6) |
| 419 | sage: M1.coerce_map_from(M2) |
| 420 | sage: M2.coerce_map_from(M1) |
| 421 | sage: c1+c2; parent(c1+c2) #indirect doctest |
| 422 | Traceback (most recent call last): |
| 423 | ... |
| 424 | TypeError: unsupported operand parent(s) for '+': 'Number Field in c1 with defining polynomial x^2 + x + 1' and 'Number Field in c2 with defining polynomial x^2 + 1' |
| 425 | sage: from sage.categories.pushout import pushout |
| 426 | sage: pushout(M1['x'],M2['x']) |
| 427 | Traceback (most recent call last): |
| 428 | ... |
| 429 | CoercionException: No common base |
| 430 | }}} |
| 431 | |
| 432 | Now: Note that we will only have a pushout if the codomains of the embeddings are number fields. Hence, in the second example, we won't use `CDF` as a pushout. |
| 433 | {{{ |
| 434 | sage: P.<x> = QQ[] |
| 435 | sage: L.<b> = NumberField(x^8-x^4+1, embedding=CDF.0) |
| 436 | sage: M1.<c1> = NumberField(x^2+x+1, embedding=b^4-1) |
| 437 | sage: M2.<c2> = NumberField(x^2+1, embedding=-b^6) |
| 438 | sage: M1.coerce_map_from(M2) |
| 439 | sage: M2.coerce_map_from(M1) |
| 440 | sage: c1+c2; parent(c1+c2) #indirect doctest |
| 441 | -b^6 + b^4 - 1 |
| 442 | Number Field in b with defining polynomial x^8 - x^4 + 1 |
| 443 | sage: from sage.categories.pushout import pushout |
| 444 | sage: pushout(M1['x'],M2['x']) |
| 445 | Univariate Polynomial Ring in x over Number Field in b with defining polynomial x^8 - x^4 + 1 |
| 446 | sage: K.<a> = NumberField(x^3-2, embedding=CDF(1/2*I*2^(1/3)*sqrt(3) - 1/2*2^(1/3))) |
| 447 | sage: L.<b> = NumberField(x^6-2, embedding=1.1) |
| 448 | sage: L.coerce_map_from(K) |
| 449 | sage: K.coerce_map_from(L) |
| 450 | sage: pushout(K,L) |
| 451 | Traceback (most recent call last): |
| 452 | ... |
| 453 | CoercionException: ('Ambiguous Base Extension', Number Field in a with defining polynomial x^3 - 2, Number Field in b with defining polynomial x^6 - 2) |
| 454 | }}} |
| 455 | |
| 456 | __Comparison of fractional ideals / identity of Residue Fields__ |
| 457 | |
| 458 | Fractional ideals have a `__cmp__` method that only took into account the Hermite normal form. In addition with coercion, we obtain: |
| 459 | {{{ |
| 460 | sage: L.<b> = NumberField(x^8-x^4+1) |
| 461 | sage: F_2 = L.fractional_ideal(b^2-1) |
| 462 | sage: F_4 = L.fractional_ideal(b^4-1) |
| 463 | sage: F_2==F_4 |
| 464 | True |
| 465 | sage: K.<r4> = NumberField(x^4-2) |
| 466 | sage: L.<r4> = NumberField(x^4-2, embedding=CDF.0) |
| 467 | sage: FK = K.fractional_ideal(K.0) |
| 468 | sage: FL = L.fractional_ideal(L.0) |
| 469 | sage: FK == FL |
| 470 | True |
| 471 | }}} |
| 472 | |
| 473 | Since the residue fields of two equal fractional fields are the same (caching), we obtain: |
| 474 | {{{ |
| 475 | sage: RL = ResidueField(FL) |
| 476 | sage: RK = ResidueField(FK) |
| 477 | sage: RK is RL |
| 478 | True |
| 479 | }}} |
| 480 | |
| 481 | Thus, `RK` is in fact defined with the embedded field `L`, not with the unembedded `K`. Hence, there is no coercion from the order of `K` to `RK`. However, ''conversion'' works (this used to fail!): |
| 482 | |
| 483 | {{{ |
| 484 | sage: OK = K.maximal_order() |
| 485 | sage: RK.has_coerce_map_from(OK) |
| 486 | False |
| 487 | sage: RK(OK.1) |
| 488 | 0 |
| 489 | }}} |
| 490 | |
| 491 | Note that I also had to change some arithmetic stuff in the `_tate` method of elliptic curves: The old implementation relied on the assumption that fractional ideals in an embedded field and in a non-embedded field can't be equal. |