#6253: [with patch, needs review] Constant functions
-------------------------+--------------------------------------------------
Reporter: nthiery | Owner: nthiery
Type: enhancement | Status: assigned
Priority: major | Milestone: sage-4.0.2
Component: misc | Keywords: constant functions
Reviewer: | Author: nthiery
Merged: |
-------------------------+--------------------------------------------------
Changes (by nthiery):
* status: new => assigned
Old description:
> This trivial patch adds basic support for constant functions
>
> Such a function could be written as lambda x: constant, but that's not
> picklable. Besides, this should eventually be cythoned for speed.
New description:
This trivial patch adds basic support for constant functions
Such a function could be written as lambda x: constant, but that's not
picklable. Besides, this should eventually be cythoned for speed.
Prerequisite for #4326.
--
Comment:
Replying to [comment:2 mhansen]:
> How is this intended to be used?
One of my use case looks like:
def my_objects(<some parameters>, predicate = ConstantFunction(True)):
"""
Returns all the objects blah blah blah (as an EnumeratedSet)
Optionally, a predicate can be specified to select only those objects
satisfying the predicate
Another one looks like:
def generating_series(..., weight = ConstantFunction(1)):
...
> What are your typical constants?
So far, True, 1, Integer(1)
Btw: with UniqueRepresentation, the two first yield the same constant
function with the current implementation, thanks to this horror:
sage: { 1: 'a', True: 'b' }
{1: 'b'}
Fixed patch in a couple minutes.
> Are there instances where you'd want a non-constant function to be used
in the same place?
Yes. Actually, that's the case in all the situations I encountered so far
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6253#comment:4>
Sage <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---