Create a cached version of a function, which only recomputes values it hasn’t already computed. Synonyme: cached_function
INPUT:
If f is a function, do either g = CachedFunction(f) or g = cached_function(f) to make a cached version of f, or put @cached_function right before the definition of f (i.e., use Python decorators):
@cached_function
def f(...):
....
The inputs to the function must be hashable.
EXAMPLES:
sage: @cached_function
... def mul(x, y=2):
... return x*y
...
sage: mul(3)
6
We demonstrate that the result is cached, and that, moreover, the cache takes into account the various ways of providing default arguments:
sage: mul(3) is mul(3,2)
True
sage: mul(3,y=2) is mul(3,2)
True
The user can clear the cache:
sage: a = mul(4)
sage: mul.clear_cache()
sage: a is mul(4)
False
It is also possible to explicitly override the cache with a different value:
sage: mul.set_cache('foo',5)
sage: mul(5,2)
'foo'
Bases: sage.combinat.species.structure.GenericSpeciesStructure
EXAMPLES:
sage: from sage.combinat.species.structure import GenericSpeciesStructure
sage: a = GenericSpeciesStructure(None, [2,3,4], [1,2,3])
sage: a
[2, 3, 4]
sage: a.parent() is None
True
sage: a == loads(dumps(a))
True
Returns the group of permutations whose action on this structure leave it fixed.
EXAMPLES:
sage: P = species.CycleSpecies()
sage: a = P.structures([1, 2, 3, 4]).random_element(); a
(1, 2, 3, 4)
sage: a.automorphism_group()
Permutation Group with generators [(1,2,3,4)]
sage: [a.transport(perm) for perm in a.automorphism_group()]
[(1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4)]
EXAMPLES:
sage: P = species.CycleSpecies()
sage: P.structures(["a","b","c"]).random_element().canonical_label()
('a', 'b', 'c')
Returns this cycle as a permutation group element.
EXAMPLES:
sage: F = species.CycleSpecies()
sage: a = F.structures(["a", "b", "c"]).random_element(); a
('a', 'b', 'c')
sage: a.permutation_group_element()
(1,2,3)
Returns the transport of this structure along the permutation perm.
EXAMPLES:
sage: F = species.CycleSpecies()
sage: a = F.structures(["a", "b", "c"]).random_element(); a
('a', 'b', 'c')
sage: p = PermutationGroupElement((1,2))
sage: a.transport(p)
('a', 'c', 'b')
Bases: sage.combinat.species.species.GenericCombinatorialSpecies
EXAMPLES:
sage: P = species.CycleSpecies()
sage: c = P.generating_series().coefficients(3)
sage: P._check()
True
sage: P == loads(dumps(P))
True