Opened 5 years ago

Improve coercion discovery

Reported by: Owned by: saraedum major sage-8.0 coercion roed N/A

Currently, `parent.pyx`, when discovering coercion maps, has a line that says

```cdef int num_paths = 1 # this is the number of paths we find before settling on the best (the one with lowest coerce_cost).                                                                                                           # setting this to 1 will make it return the first path found.
```

This is unfortunate because sometimes it leads to the discovery of very unfortunate coercions:

```sage: W.coerce_map_from(int)
Composite map:
From: Set of Python objects of type 'int'
To:   Eisenstein Extension of Unramified Extension of 5-adic Ring with floating precision 20 in a defined by x^2 + 4*x + 2 in w defined by x^2 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + 4*5^20
Defn:   Native morphism:
From: Set of Python objects of type 'int'
To:   Integer Ring
then
Ring Coercion morphism:
From: Integer Ring
To:   5-adic Ring with floating precision 20
then
Conversion map:
From: 5-adic Ring with floating precision 20
To:   Unramified Extension of 5-adic Ring with floating precision 20 in a defined by x^2 + 4*x + 2
then
Conversion map:
From: Unramified Extension of 5-adic Ring with floating precision 20 in a defined by x^2 + 4*x + 2
To:   Eisenstein Extension of Unramified Extension of 5-adic Ring with floating precision 20 in a defined by x^2 + 4*x + 2 in w defined by x^2 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + 4*5^20
```

even though there would have been a much easier way via

```sage: W.coerce_map_from(ZZ)
Ring Coercion morphism:
From: Integer Ring
To:   Eisenstein Extension of Unramified Extension of 5-adic Ring with floating precision 20 in a defined by x^2 + 4*x + 2 in w defined by x^2 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + 4*5^20
```

This constant should be replaced by a more sophisticated heuristic. Also, it should take into account that nobody ever sets the `_coerce_cost` on their own coercion maps.

comment:1 Changed 5 years ago by saraedum

• Description modified (diff)
Note: See TracTickets for help on using tickets.