Opened 5 years ago

Last modified 5 years ago

#23240 new enhancement

Improve coercion discovery

Reported by: saraedum Owned by:
Priority: major Milestone: sage-8.0
Component: coercion Keywords:
Cc: roed Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by saraedum)

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.

Change History (1)

comment:1 Changed 5 years ago by saraedum

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