Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert not coerce padics symbolic function arguments #17790

Closed
rwst opened this issue Feb 17, 2015 · 14 comments
Closed

convert not coerce padics symbolic function arguments #17790

rwst opened this issue Feb 17, 2015 · 14 comments

Comments

@rwst
Copy link

rwst commented Feb 17, 2015

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.

CC: @jdemeyer

Component: symbolics

Author: Ralf Stephan

Branch/Commit: u/rws/builtinfunction_doesn_t_pass_non_sr_coercible_arguments_to_function_code @ e4a30b6

Issue created by migration from https://trac.sagemath.org/ticket/17790

@rwst rwst added this to the sage-6.5 milestone Feb 17, 2015
@rwst
Copy link
Author

rwst commented Mar 5, 2015

comment:1

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.

@rwst rwst modified the milestones: sage-6.5, sage-6.6 Mar 5, 2015
@rwst
Copy link
Author

rwst commented Mar 5, 2015

@rwst
Copy link
Author

rwst commented Mar 5, 2015

Commit: f6e2113

@rwst
Copy link
Author

rwst commented Mar 5, 2015

Author: Ralf Stephan

@rwst
Copy link
Author

rwst commented Mar 5, 2015

comment:3

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

@rwst rwst changed the title BuiltinFunction doesn't pass non-SR-coercible arguments to function code convert not coerce padics symbolic function arguments Mar 5, 2015
@rwst
Copy link
Author

rwst commented Apr 21, 2015

comment:4

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?

@rwst rwst modified the milestones: sage-6.6, sage-6.7 Apr 21, 2015
@rwst
Copy link
Author

rwst commented Jul 1, 2015

comment:5

@jdemeyer, 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?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 17, 2016

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 17, 2016

Changed commit from f6e2113 to 9a29cd1

@sagetrac-tmonteil

This comment has been minimized.

@rwst rwst modified the milestones: sage-6.7, sage-7.3 Jun 21, 2016
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2016

Changed commit from 9a29cd1 to e4a30b6

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2016

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

@fchapoton
Copy link
Contributor

comment:10

one failing doctest see patchbot report

@rwst
Copy link
Author

rwst commented Nov 9, 2017

comment:12

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants