Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 't/13580/map_reduce' into 13580
Browse files Browse the repository at this point in the history
  • Loading branch information
hivert committed May 20, 2015
2 parents e00f17b + d188cd8 commit 92e6e68
Show file tree
Hide file tree
Showing 5 changed files with 1,282 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/doc/en/reference/combinat/module_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Comprehensive Module list
sage/combinat/kazhdan_lusztig
sage/combinat/knutson_tao_puzzles
sage/combinat/lyndon_word
sage/combinat/map_reduce
sage/combinat/matrices/__init__
sage/combinat/matrices/all
sage/combinat/matrices/dancing_links
Expand Down
26 changes: 26 additions & 0 deletions src/sage/combinat/backtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ def __init__(self, roots = None, children = None, post_process = None,
self._algorithm = algorithm
Parent.__init__(self, facade = facade, category = EnumeratedSets().or_subcategory(category))

__len__ = None

def _repr_(self):
r"""
TESTS::
Expand Down Expand Up @@ -717,6 +719,30 @@ def __contains__(self, elt):
stack.append( iter(self.children(node)) )
return False

def map_reduce(self, map_function = None,
reduce_function = None,
reduce_init = None):
r"""
Apply en Map Reduce algorithm on ``self``
EXAMPLES::
sage: F = SearchForest( [([i],i, i) for i in range(1,10)],
... lambda (list, sum, last):
... [(list + [i], sum + i, i) for i in range(1,last)],
... lambda x: x)
sage: y = var('y')
sage: F.map_reduce(
... lambda (li, sum, _): y**sum, lambda x,y: x + y, 0 )
y^45 + y^44 + y^43 + 2*y^42 + 2*y^41 + 3*y^40 + 4*y^39 + 5*y^38 + 6*y^37 + 8*y^36 + 9*y^35 + 10*y^34 + 12*y^33 + 13*y^32 + 15*y^31 + 17*y^30 + 18*y^29 + 19*y^28 + 21*y^27 + 21*y^26 + 22*y^25 + 23*y^24 + 23*y^23 + 23*y^22 + 23*y^21 + 22*y^20 + 21*y^19 + 21*y^18 + 19*y^17 + 18*y^16 + 17*y^15 + 15*y^14 + 13*y^13 + 12*y^12 + 10*y^11 + 9*y^10 + 8*y^9 + 6*y^8 + 5*y^7 + 4*y^6 + 3*y^5 + 2*y^4 + 2*y^3 + y^2 + y
"""
from sage.combinat.map_reduce import SearchForestMapReduce
return SearchForestMapReduce(forest = self,
map_function = map_function,
reduce_function = reduce_function,
reduce_init = reduce_init).run()


class PositiveIntegerSemigroup(UniqueRepresentation, SearchForest):
r"""
The commutative additive semigroup of positive integers.
Expand Down
1 change: 1 addition & 0 deletions src/sage/combinat/enumerated_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
- :func:`~sage.sets.recursively_enumerated_set.RecursivelyEnumeratedSet`
- :class:`~sage.combinat.backtrack.GenericBacktracker`
- :ref:`sage.combinat.map_reduce`
- :ref:`sage.combinat.tiling`
- :ref:`sage.combinat.dlx`
- :ref:`sage.combinat.matrices.dlxcpp`
Expand Down
Loading

0 comments on commit 92e6e68

Please sign in to comment.