Skip to content

Commit f1f3e87

Browse files
author
Release Manager
committed
gh-40294: Fix loading symbolic expressions containing symbolic functions - Fixes #40292 - Fixes #30018 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40294 Reported by: Ricardo Buring Reviewer(s): Ricardo Buring, user202729
2 parents 1a1d0c4 + 6a06882 commit f1f3e87

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/sage/symbolic/function.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,15 @@ cdef class SymbolicFunction(Function):
13481348
foo(x)^2 + foo(0) + 1
13491349
sage: u.subs(y=0).n() # needs sage.symbolic
13501350
43.0000000000000
1351+
1352+
Check that :issue:`40292` is fixed::
1353+
1354+
sage: # needs sage.symbolic
1355+
sage: var('x,y')
1356+
(x, y)
1357+
sage: u = function('u')(x, y)
1358+
sage: loads(dumps(u))
1359+
u(x, y)
13511360
"""
13521361
return (2, self._name, self._nargs, self._latex_name, self._conversions,
13531362
self._evalf_params_first,

src/sage/symbolic/pynac_impl.pxi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,16 @@ cdef unsigned py_get_serial_for_new_sfunction(stdstring &s,
817817
create one and set up the function tables properly.
818818
"""
819819
from sage.symbolic.function_factory import function_factory
820-
cdef Function fn = function_factory(s.c_str(), nargs)
820+
# The input string s comes from GiNaC::function::function, the constructor
821+
# that reads the function name from an archive.
822+
# The archive is created by GiNaC::function::archive, which sets the name
823+
# to GiNaC::function::registered_functions()[serial].name.
824+
# Functions are registered using GiNaC::function::register_new.
825+
# For symbolic functions this happens in the register_or_update_function
826+
# which is defined in src/sage/symbolic/pynac_function_impl.pxi.
827+
# In there, str_to_bytes is applied to the name.
828+
# Hence we must apply the inverse char_to_str here.
829+
cdef Function fn = function_factory(char_to_str(s.c_str()), nargs)
821830
return fn._serial
822831

823832

0 commit comments

Comments
 (0)