#18257: fix symbolic/pynac.pyx doctests
-----------------------------+------------------------
       Reporter:  rws        |        Owner:
           Type:  defect     |       Status:  new
       Priority:  minor      |    Milestone:  sage-6.7
      Component:  symbolics  |   Resolution:
       Keywords:             |    Merged in:
        Authors:             |    Reviewers:
Report Upstream:  N/A        |  Work issues:
         Branch:             |       Commit:
   Dependencies:             |     Stopgaps:
-----------------------------+------------------------

Comment (by rws):

 Replying to [comment:1 kcrisman]:
 > I agree that this is worth fixing permanently, but unless there is an
 obvious fix we shouldn't let this hold up adding more symbolic functions.
 This is not really difficult.

 The central database is a dictionary globally defined in
 `symbolic/function.pyx` named `sfunction_serial_dict`. It has pairs with
 key of type `unsigned` and values of `Function` objects (which can be
 `GinacFunctions` or `BuiltinFunctions`). Accordingly this database is
 filled with all known Pynac `function`s (which have the `GinacFunction`
 façade) first and then those defined via `BuiltinFunction`. The `unsigned`
 key is the serial number which, on each new function registration, is
 incremented by one, namely in
 
`GiNaC::function::register_new()`(https://github.com/pynac/pynac/blob/master/ginac/function.cpp#L1445)
 by just adding to the Pynac registry and reporting its size minus one.
 After the GiNaC functions have been added, the global `GINAC_FN_SERIAL` is
 set which is then accessed via `get_ginac_serial()` to get the start key
 of the Sage defined functions.

 There is a problem if ever a function is deregistered. Can this happen? No
 mechanism in Pynac exists for this at the moment, so it's  not a practical
 consideration.

 So the solution is easy: instead of simply adding `100` to the start
 point, we try all keys from the start key to the latest key used---this
 need not be a static variable set on registration. Since functions are
 never deregistered the latest is, again, just the size of the GiNaC
 registry minus one. This can be had from a call to
 `g_registered_functions().size()` in `symbolic/pynac.pyx`.
 {{{
 cdef get_fn_serial_c():
     return g_registered_functions().size()

 def get_fn_serial():
     return get_fn_serial_c()

 sage: from sage.symbolic.pynac import get_fn_serial
 sage: get_fn_serial()
 127
 sage: from sage.symbolic.pynac import get_ginac_serial
 sage: get_ginac_serial()
 40
 sage: from sage.symbolic.function import get_sfunction_from_serial
 sage: for i in range(get_ginac_serial(), get_fn_serial()):
     print get_sfunction_from_serial(i)
 ... // prints all known functions
 sage: print get_sfunction_from_serial(get_fn_serial()+1)
 None
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/18257#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to