Opened 5 years ago

Closed 2 years ago

#17790 closed defect (wontfix)

convert not coerce padics symbolic function arguments

Reported by: rws Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: symbolics Keywords:
Cc: jdemeyer Merged in:
Authors: Ralf Stephan Reviewers:
Report Upstream: N/A Work issues:
Branch: u/rws/builtinfunction_doesn_t_pass_non_sr_coercible_arguments_to_function_code (Commits) Commit: e4a30b68bd6d81deb579806d50d5d8f7630a558a
Dependencies: Stopgaps:

Description (last modified by tmonteil)

This affects authors of function code but shows also in:

sage: binomial(Qp(5)(8),3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-43da6d5c56db> in <module>()
----> 1 binomial(Qp(Integer(5))(Integer(8)),Integer(3))

/home/ralf/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.GinacFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:9048)()
    842             (0, Integer Ring)
    843         """
--> 844         res = super(GinacFunction, self).__call__(*args, **kwds)
    845 
    846         # Convert to Integer if the output was of type "int" and any of

/home/ralf/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:10572)()
    991             res = self._evalf_try_(*args)
    992             if res is None:
--> 993                 res = super(BuiltinFunction, self).__call__(
    994                         *args, coerce=coerce, hold=hold)
    995 

/home/ralf/sage/src/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6301)()
    485                             nargs[i] = SR.coerce(carg)
    486                         except Exception:
--> 487                             raise TypeError, "cannot coerce arguments: %s"%(err)
    488                 args = nargs
    489         else: # coerce == False

TypeError: cannot coerce arguments: no canonical coercion from 5-adic Field with capped relative precision 20 to Symbolic Ring

test.

Change History (13)

comment:1 Changed 5 years ago by rws

  • Cc jdemeyer added
  • Milestone changed from sage-6.5 to sage-6.6

So, either it's a problem of p-adics not being coercible into SR (which they should be?), or there should not be coercion but conversion in function.pyx.

comment:2 Changed 5 years ago by rws

  • Branch set to u/rws/builtinfunction_doesn_t_pass_non_sr_coercible_arguments_to_function_code

comment:3 Changed 5 years ago by rws

  • Authors set to Ralf Stephan
  • Commit set to f6e21137f97771b916ceae7f16a59805af78291f
  • Status changed from new to needs_review
  • Summary changed from BuiltinFunction doesn't pass non-SR-coercible arguments to function code to convert not coerce padics symbolic function arguments

It was the latter alternative, as there is no coercion. Please review.


New commits:

f6e211317790: add padics to the conversion workaround for symbolic function arguments

comment:4 Changed 5 years ago by rws

  • Milestone changed from sage-6.6 to sage-6.7
  • Status changed from needs_review to needs_work

The recent #17852 makes binomial(Qp(2)(9),5) fail in this branch with TypeError: function did not return a symbolic expression or an element that can be coerced into a symbolic expression. Reason: rings.arith.binomial now returns (correctly) 1 + 5 + 2*5^2 + O(5^20) instead of 56.

So what should Function do when self.eval returns something not coercible?

Last edited 5 years ago by rws (previous) (diff)

comment:5 Changed 4 years ago by rws

@Jeroen, what reason is there in the respective snippet of Function::__call__ l.478-491 not to do the following:

                nargs = [None]*len(args)
                for i in range(len(args)):
                    carg = args[i]
                    try:
                        nargs[i] = SR.coerce(carg)
                    except Exception:
                        nargs[i] = SR(carg)

i.e. not throwing at all. I keep needing exceptions like the Qp of this ticket.

Do we have a fundamental problem here? Why can rings.arith... handle this differently?

comment:6 Changed 3 years ago by git

  • Commit changed from f6e21137f97771b916ceae7f16a59805af78291f to 9a29cd1da4d4a7f974ba34c5d981a43802781294

Branch pushed to git repo; I updated commit sha1. New commits:

89f5b2dMerge branch 'develop' into t/17790/builtinfunction_doesn_t_pass_non_sr_coercible_arguments_to_function_code
9a29cd117790: try coercion then conversion

comment:7 Changed 3 years ago by tmonteil

  • Description modified (diff)

comment:8 Changed 3 years ago by rws

  • Milestone changed from sage-6.7 to sage-7.3
  • Status changed from needs_work to needs_review

comment:9 Changed 3 years ago by git

  • Commit changed from 9a29cd1da4d4a7f974ba34c5d981a43802781294 to e4a30b68bd6d81deb579806d50d5d8f7630a558a

Branch pushed to git repo; I updated commit sha1. New commits:

e4a30b6Merge branch 'develop' into t/17790/builtinfunction_doesn_t_pass_non_sr_coercible_arguments_to_function_code

comment:10 Changed 3 years ago by chapoton

one failing doctest see patchbot report

comment:11 Changed 3 years ago by rws

  • Status changed from needs_review to needs_work

comment:12 Changed 2 years ago by rws

  • Milestone changed from sage-7.3 to sage-duplicate/invalid/wontfix
  • Status changed from needs_work to positive_review

I think this ticket is wontfix because a better solution would be to write a global Python function accepting everything (as in rings.arith...) and dispatch to the symbolic function for symbolic arguments.

In the ticket case just do

sage: from sage.arith.misc import binomial
sage: binomial(Qp(5)(8),3)
1 + 5 + 2*5^2 + O(5^20)

comment:13 Changed 2 years ago by embray

  • Resolution set to wontfix
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.