passagemath-graphs 10.6.1rc1__cp310-cp310-musllinux_1_2_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_graphs-10.6.1rc1.dist-info/METADATA +292 -0
- passagemath_graphs-10.6.1rc1.dist-info/RECORD +260 -0
- passagemath_graphs-10.6.1rc1.dist-info/WHEEL +5 -0
- passagemath_graphs-10.6.1rc1.dist-info/top_level.txt +2 -0
- passagemath_graphs.libs/libgcc_s-69c45f16.so.1 +0 -0
- passagemath_graphs.libs/libgmp-8e78bd9b.so.10.5.0 +0 -0
- passagemath_graphs.libs/libstdc++-1f1a71be.so.6.0.33 +0 -0
- sage/all__sagemath_graphs.py +39 -0
- sage/combinat/abstract_tree.py +2723 -0
- sage/combinat/all__sagemath_graphs.py +34 -0
- sage/combinat/binary_tree.py +5306 -0
- sage/combinat/cluster_algebra_quiver/all.py +22 -0
- sage/combinat/cluster_algebra_quiver/cluster_seed.py +5208 -0
- sage/combinat/cluster_algebra_quiver/interact.py +124 -0
- sage/combinat/cluster_algebra_quiver/mutation_class.py +625 -0
- sage/combinat/cluster_algebra_quiver/mutation_type.py +1555 -0
- sage/combinat/cluster_algebra_quiver/quiver.py +2290 -0
- sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +2468 -0
- sage/combinat/designs/MOLS_handbook_data.py +570 -0
- sage/combinat/designs/all.py +58 -0
- sage/combinat/designs/bibd.py +1655 -0
- sage/combinat/designs/block_design.py +1071 -0
- sage/combinat/designs/covering_array.py +269 -0
- sage/combinat/designs/covering_design.py +530 -0
- sage/combinat/designs/database.py +5615 -0
- sage/combinat/designs/design_catalog.py +122 -0
- sage/combinat/designs/designs_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/designs_pyx.pxd +21 -0
- sage/combinat/designs/designs_pyx.pyx +993 -0
- sage/combinat/designs/difference_family.py +3951 -0
- sage/combinat/designs/difference_matrices.py +279 -0
- sage/combinat/designs/evenly_distributed_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/evenly_distributed_sets.pyx +661 -0
- sage/combinat/designs/ext_rep.py +1064 -0
- sage/combinat/designs/gen_quadrangles_with_spread.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/gen_quadrangles_with_spread.pyx +339 -0
- sage/combinat/designs/group_divisible_designs.py +361 -0
- sage/combinat/designs/incidence_structures.py +2357 -0
- sage/combinat/designs/latin_squares.py +581 -0
- sage/combinat/designs/orthogonal_arrays.py +2244 -0
- sage/combinat/designs/orthogonal_arrays_build_recursive.py +1780 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +967 -0
- sage/combinat/designs/resolvable_bibd.py +815 -0
- sage/combinat/designs/steiner_quadruple_systems.py +1306 -0
- sage/combinat/designs/subhypergraph_search.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/subhypergraph_search.pyx +530 -0
- sage/combinat/designs/twographs.py +306 -0
- sage/combinat/finite_state_machine.py +14874 -0
- sage/combinat/finite_state_machine_generators.py +2006 -0
- sage/combinat/graph_path.py +448 -0
- sage/combinat/interval_posets.py +3908 -0
- sage/combinat/nu_tamari_lattice.py +269 -0
- sage/combinat/ordered_tree.py +1446 -0
- sage/combinat/posets/all.py +46 -0
- sage/combinat/posets/bubble_shuffle.py +247 -0
- sage/combinat/posets/cartesian_product.py +493 -0
- sage/combinat/posets/d_complete.py +182 -0
- sage/combinat/posets/elements.py +273 -0
- sage/combinat/posets/forest.py +30 -0
- sage/combinat/posets/hasse_cython.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/hasse_cython.pyx +174 -0
- sage/combinat/posets/hasse_diagram.py +3672 -0
- sage/combinat/posets/hochschild_lattice.py +158 -0
- sage/combinat/posets/incidence_algebras.py +794 -0
- sage/combinat/posets/lattices.py +5117 -0
- sage/combinat/posets/linear_extension_iterator.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/linear_extension_iterator.pyx +292 -0
- sage/combinat/posets/linear_extensions.py +1037 -0
- sage/combinat/posets/mobile.py +275 -0
- sage/combinat/posets/moebius_algebra.py +776 -0
- sage/combinat/posets/poset_examples.py +2178 -0
- sage/combinat/posets/posets.py +9360 -0
- sage/combinat/rooted_tree.py +1070 -0
- sage/combinat/shard_order.py +239 -0
- sage/combinat/tamari_lattices.py +384 -0
- sage/combinat/yang_baxter_graph.py +923 -0
- sage/databases/all__sagemath_graphs.py +1 -0
- sage/databases/knotinfo_db.py +1231 -0
- sage/ext_data/all__sagemath_graphs.py +1 -0
- sage/ext_data/graphs/graph_plot_js.html +330 -0
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/graphs/all.py +42 -0
- sage/graphs/asteroidal_triples.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/asteroidal_triples.pyx +320 -0
- sage/graphs/base/all.py +1 -0
- sage/graphs/base/boost_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/boost_graph.pxd +106 -0
- sage/graphs/base/boost_graph.pyx +3045 -0
- sage/graphs/base/c_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/c_graph.pxd +106 -0
- sage/graphs/base/c_graph.pyx +5096 -0
- sage/graphs/base/dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/dense_graph.pxd +28 -0
- sage/graphs/base/dense_graph.pyx +801 -0
- sage/graphs/base/graph_backends.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/graph_backends.pxd +5 -0
- sage/graphs/base/graph_backends.pyx +797 -0
- sage/graphs/base/overview.py +85 -0
- sage/graphs/base/sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/sparse_graph.pxd +90 -0
- sage/graphs/base/sparse_graph.pyx +1653 -0
- sage/graphs/base/static_dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_dense_graph.pxd +5 -0
- sage/graphs/base/static_dense_graph.pyx +1032 -0
- sage/graphs/base/static_sparse_backend.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_backend.pxd +27 -0
- sage/graphs/base/static_sparse_backend.pyx +1583 -0
- sage/graphs/base/static_sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_graph.pxd +37 -0
- sage/graphs/base/static_sparse_graph.pyx +1375 -0
- sage/graphs/bipartite_graph.py +2732 -0
- sage/graphs/centrality.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/centrality.pyx +1038 -0
- sage/graphs/cographs.py +519 -0
- sage/graphs/comparability.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/comparability.pyx +851 -0
- sage/graphs/connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/connectivity.pxd +157 -0
- sage/graphs/connectivity.pyx +4813 -0
- sage/graphs/convexity_properties.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/convexity_properties.pxd +16 -0
- sage/graphs/convexity_properties.pyx +870 -0
- sage/graphs/digraph.py +4754 -0
- sage/graphs/digraph_generators.py +1993 -0
- sage/graphs/distances_all_pairs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/distances_all_pairs.pxd +12 -0
- sage/graphs/distances_all_pairs.pyx +2938 -0
- sage/graphs/domination.py +1363 -0
- sage/graphs/dot2tex_utils.py +100 -0
- sage/graphs/edge_connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/edge_connectivity.pyx +1215 -0
- sage/graphs/generators/all.py +1 -0
- sage/graphs/generators/basic.py +1769 -0
- sage/graphs/generators/chessboard.py +538 -0
- sage/graphs/generators/classical_geometries.py +1611 -0
- sage/graphs/generators/degree_sequence.py +235 -0
- sage/graphs/generators/distance_regular.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generators/distance_regular.pyx +2846 -0
- sage/graphs/generators/families.py +4759 -0
- sage/graphs/generators/intersection.py +565 -0
- sage/graphs/generators/platonic_solids.py +262 -0
- sage/graphs/generators/random.py +2623 -0
- sage/graphs/generators/smallgraphs.py +5741 -0
- sage/graphs/generators/world_map.py +724 -0
- sage/graphs/generic_graph.py +26867 -0
- sage/graphs/generic_graph_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generic_graph_pyx.pxd +34 -0
- sage/graphs/generic_graph_pyx.pyx +1673 -0
- sage/graphs/genus.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/genus.pyx +622 -0
- sage/graphs/graph.py +9645 -0
- sage/graphs/graph_coloring.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_coloring.pyx +2284 -0
- sage/graphs/graph_database.py +1177 -0
- sage/graphs/graph_decompositions/all.py +1 -0
- sage/graphs/graph_decompositions/bandwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/bandwidth.pyx +428 -0
- sage/graphs/graph_decompositions/clique_separators.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/clique_separators.pyx +616 -0
- sage/graphs/graph_decompositions/cutwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/cutwidth.pyx +753 -0
- sage/graphs/graph_decompositions/fast_digraph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/fast_digraph.pxd +13 -0
- sage/graphs/graph_decompositions/fast_digraph.pyx +212 -0
- sage/graphs/graph_decompositions/graph_products.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/graph_products.pyx +508 -0
- sage/graphs/graph_decompositions/modular_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/modular_decomposition.pxd +27 -0
- sage/graphs/graph_decompositions/modular_decomposition.pyx +1536 -0
- sage/graphs/graph_decompositions/slice_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/slice_decomposition.pxd +18 -0
- sage/graphs/graph_decompositions/slice_decomposition.pyx +1106 -0
- sage/graphs/graph_decompositions/tree_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/tree_decomposition.pxd +17 -0
- sage/graphs/graph_decompositions/tree_decomposition.pyx +1996 -0
- sage/graphs/graph_decompositions/vertex_separation.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/vertex_separation.pxd +5 -0
- sage/graphs/graph_decompositions/vertex_separation.pyx +1963 -0
- sage/graphs/graph_editor.py +82 -0
- sage/graphs/graph_generators.py +3314 -0
- sage/graphs/graph_generators_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_generators_pyx.pyx +95 -0
- sage/graphs/graph_input.py +812 -0
- sage/graphs/graph_latex.py +2064 -0
- sage/graphs/graph_list.py +410 -0
- sage/graphs/graph_plot.py +1756 -0
- sage/graphs/graph_plot_js.py +338 -0
- sage/graphs/hyperbolicity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/hyperbolicity.pyx +1704 -0
- sage/graphs/hypergraph_generators.py +364 -0
- sage/graphs/independent_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/independent_sets.pxd +13 -0
- sage/graphs/independent_sets.pyx +402 -0
- sage/graphs/isgci.py +1033 -0
- sage/graphs/isoperimetric_inequalities.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/isoperimetric_inequalities.pyx +489 -0
- sage/graphs/line_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/line_graph.pyx +743 -0
- sage/graphs/lovasz_theta.py +77 -0
- sage/graphs/matching.py +1633 -0
- sage/graphs/matching_covered_graph.py +3590 -0
- sage/graphs/orientations.py +1489 -0
- sage/graphs/partial_cube.py +459 -0
- sage/graphs/path_enumeration.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/path_enumeration.pyx +2040 -0
- sage/graphs/pq_trees.py +1129 -0
- sage/graphs/print_graphs.py +201 -0
- sage/graphs/schnyder.py +865 -0
- sage/graphs/spanning_tree.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/spanning_tree.pyx +1457 -0
- sage/graphs/strongly_regular_db.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/strongly_regular_db.pyx +3340 -0
- sage/graphs/traversals.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/traversals.pxd +9 -0
- sage/graphs/traversals.pyx +1872 -0
- sage/graphs/trees.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/trees.pxd +15 -0
- sage/graphs/trees.pyx +310 -0
- sage/graphs/tutte_polynomial.py +713 -0
- sage/graphs/views.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/views.pyx +794 -0
- sage/graphs/weakly_chordal.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/weakly_chordal.pyx +604 -0
- sage/groups/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pxd +38 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +1666 -0
- sage/knots/all.py +6 -0
- sage/knots/free_knotinfo_monoid.py +507 -0
- sage/knots/gauss_code.py +291 -0
- sage/knots/knot.py +682 -0
- sage/knots/knot_table.py +284 -0
- sage/knots/knotinfo.py +2900 -0
- sage/knots/link.py +4715 -0
- sage/sandpiles/all.py +13 -0
- sage/sandpiles/examples.py +225 -0
- sage/sandpiles/sandpile.py +6365 -0
- sage/topology/all.py +22 -0
- sage/topology/cell_complex.py +1214 -0
- sage/topology/cubical_complex.py +1976 -0
- sage/topology/delta_complex.py +1806 -0
- sage/topology/filtered_simplicial_complex.py +744 -0
- sage/topology/moment_angle_complex.py +823 -0
- sage/topology/simplicial_complex.py +5160 -0
- sage/topology/simplicial_complex_catalog.py +92 -0
- sage/topology/simplicial_complex_examples.py +1680 -0
- sage/topology/simplicial_complex_homset.py +205 -0
- sage/topology/simplicial_complex_morphism.py +836 -0
- sage/topology/simplicial_set.py +4102 -0
- sage/topology/simplicial_set_catalog.py +55 -0
- sage/topology/simplicial_set_constructions.py +2954 -0
- sage/topology/simplicial_set_examples.py +865 -0
- sage/topology/simplicial_set_morphism.py +1464 -0
@@ -0,0 +1,661 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
# sage.doctest: needs sage.rings.finite_rings
|
3
|
+
r"""
|
4
|
+
Evenly distributed sets in finite fields
|
5
|
+
|
6
|
+
This module consists of a simple class :class:`EvenlyDistributedSetsBacktracker`. Its main
|
7
|
+
purpose is to iterate through the evenly distributed sets of a given finite
|
8
|
+
field.
|
9
|
+
|
10
|
+
The naive backtracker implemented here is not directly used to generate
|
11
|
+
difference family as even for small parameters it already takes time to run.
|
12
|
+
Instead, its output has been stored into a database
|
13
|
+
:mod:`sage.combinat.designs.database`. If the backtracker is improved, then one
|
14
|
+
might want to update this database with more values.
|
15
|
+
|
16
|
+
Classes and methods
|
17
|
+
-------------------
|
18
|
+
"""
|
19
|
+
|
20
|
+
cimport cython
|
21
|
+
|
22
|
+
from libc.limits cimport UINT_MAX
|
23
|
+
from libc.string cimport memset, memcpy
|
24
|
+
from memory_allocator cimport MemoryAllocator
|
25
|
+
|
26
|
+
from sage.rings.integer cimport smallInteger
|
27
|
+
|
28
|
+
from sage.categories.fields import Fields
|
29
|
+
|
30
|
+
|
31
|
+
cdef class EvenlyDistributedSetsBacktracker:
|
32
|
+
r"""
|
33
|
+
Set of evenly distributed subsets in finite fields.
|
34
|
+
|
35
|
+
**Definition:** Let `K` be a finite field of cardinality `q` and `k` an
|
36
|
+
integer so that `k(k-1)` divides `q-1`. Let `H = K^*` be the
|
37
|
+
multiplicative group of invertible elements in `K`. A `k`-*evenly
|
38
|
+
distributed set* in `K` is a set `B = \{b_1, b_2, \ldots, b_k\}` of `k`
|
39
|
+
elements of `K` so that the `k(k-1)` differences `\Delta B = \{b_i -
|
40
|
+
b_j; i \not= j\}` hit each coset modulo `H^{2(q-1)/(k(k-1))}` exactly
|
41
|
+
twice.
|
42
|
+
|
43
|
+
Evenly distributed sets were introduced by Wilson [Wi72]_ (see also
|
44
|
+
[BJL99-1]_, Chapter VII.6). He proved that for any `k`, and for any prime power
|
45
|
+
`q` large enough such that `k(k-1)` divides `k` there exists a `k`-evenly
|
46
|
+
distributed set in the field of cardinality `q`. This existence result based
|
47
|
+
on a counting argument (using Dirichlet theorem) does not provide a simple
|
48
|
+
method to generate them.
|
49
|
+
|
50
|
+
From a `k`-evenly distributed set, it is straightforward to build a
|
51
|
+
`(q,k,1)`-difference family (see :meth:`to_difference_family`). Another
|
52
|
+
approach to generate a difference family, somehow dual to this one, is via
|
53
|
+
radical difference family (see in particular
|
54
|
+
:func:`~sage.combinat.designs.difference_family.radical_difference_family`
|
55
|
+
from the module :mod:`~sage.combinat.designs.difference_family`).
|
56
|
+
|
57
|
+
By default, this backtracker only considers evenly distributed sets up to
|
58
|
+
affine automorphisms, i.e. `B` is considered equivalent to `s B + t` for any
|
59
|
+
invertible element `s` and any element `t` in the field `K`. Note that the
|
60
|
+
set of differences is just multiplicatively translated by `s` as `\Delta (s
|
61
|
+
B + t) = s (\Delta B)`, and so that `B` is an evenly distributed set if and
|
62
|
+
only if `sB` is one too. This behaviour can be modified via the argument
|
63
|
+
``up_to_isomorphism`` (see the input section and the examples below).
|
64
|
+
|
65
|
+
INPUT:
|
66
|
+
|
67
|
+
- ``K`` -- a finite field of cardinality `q`
|
68
|
+
|
69
|
+
- ``k`` -- positive integer such that `k(k-1)` divides `q-1`
|
70
|
+
|
71
|
+
- ``up_to_isomorphism`` -- boolean (default: ``True``); whether only consider
|
72
|
+
evenly distributed sets up to automorphisms of the field of the form
|
73
|
+
`x \mapsto ax + b`. If set to ``False`` then the iteration is over all
|
74
|
+
evenly distributed sets that contain ``0`` and ``1``.
|
75
|
+
|
76
|
+
- ``check`` -- boolean (default: ``False``); whether you want to check
|
77
|
+
intermediate steps of the iterator. This is mainly intended for debugging
|
78
|
+
purpose. Setting it to ``True`` will considerably slow the iteration.
|
79
|
+
|
80
|
+
EXAMPLES:
|
81
|
+
|
82
|
+
The main part of the code is contained in the iterator. To get one evenly
|
83
|
+
distributed set just do::
|
84
|
+
|
85
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
86
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(151),6)
|
87
|
+
sage: B = E.an_element()
|
88
|
+
sage: B
|
89
|
+
[0, 1, 69, 36, 57, 89]
|
90
|
+
|
91
|
+
The class has a method to convert it to a difference family::
|
92
|
+
|
93
|
+
sage: E.to_difference_family(B)
|
94
|
+
[[0, 1, 69, 36, 57, 89],
|
95
|
+
[0, 132, 48, 71, 125, 121],
|
96
|
+
[0, 59, 145, 10, 41, 117],
|
97
|
+
[0, 87, 114, 112, 127, 42],
|
98
|
+
[0, 8, 99, 137, 3, 108]]
|
99
|
+
|
100
|
+
It is also possible to run over all evenly distributed sets::
|
101
|
+
|
102
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(13), 4, up_to_isomorphism=False)
|
103
|
+
sage: for B in E: print(B)
|
104
|
+
[0, 1, 11, 5]
|
105
|
+
[0, 1, 4, 6]
|
106
|
+
[0, 1, 9, 3]
|
107
|
+
[0, 1, 8, 10]
|
108
|
+
|
109
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(13), 4, up_to_isomorphism=True)
|
110
|
+
sage: for B in E: print(B)
|
111
|
+
[0, 1, 11, 5]
|
112
|
+
|
113
|
+
|
114
|
+
Or only count them::
|
115
|
+
|
116
|
+
sage: for k in range(13, 200, 12):
|
117
|
+
....: if is_prime_power(k):
|
118
|
+
....: K = GF(k,'a')
|
119
|
+
....: E1 = EvenlyDistributedSetsBacktracker(K, 4, False)
|
120
|
+
....: E2 = EvenlyDistributedSetsBacktracker(K, 4, True)
|
121
|
+
....: print("{:3} {:3} {:3}".format(k, E1.cardinality(), E2.cardinality()))
|
122
|
+
13 4 1
|
123
|
+
25 40 4
|
124
|
+
37 12 1
|
125
|
+
49 24 2
|
126
|
+
61 12 1
|
127
|
+
73 48 4
|
128
|
+
97 64 6
|
129
|
+
109 72 6
|
130
|
+
121 240 20
|
131
|
+
157 96 8
|
132
|
+
169 240 20
|
133
|
+
181 204 17
|
134
|
+
193 336 28
|
135
|
+
|
136
|
+
Note that by definition, the number of evenly distributed sets up to
|
137
|
+
isomorphisms is at most `k(k-1)` times smaller than without isomorphisms.
|
138
|
+
But it might not be exactly `k(k-1)` as some of them might have symmetries::
|
139
|
+
|
140
|
+
sage: B = EvenlyDistributedSetsBacktracker(Zmod(13), 4).an_element()
|
141
|
+
sage: B
|
142
|
+
[0, 1, 11, 5]
|
143
|
+
sage: [9*x + 5 for x in B]
|
144
|
+
[5, 1, 0, 11]
|
145
|
+
sage: [3*x + 11 for x in B]
|
146
|
+
[11, 1, 5, 0]
|
147
|
+
"""
|
148
|
+
# PYTHON DATA
|
149
|
+
cdef K # the underlying field
|
150
|
+
cdef list list_K # the elements of K (i -> x)
|
151
|
+
cdef dict K_to_int # inverse of list_K (x -> i)
|
152
|
+
|
153
|
+
# FLAGS
|
154
|
+
cdef int count # do we count or do we iterate
|
155
|
+
cdef int check # do we need to check (debug)
|
156
|
+
cdef int up_to_isom # do we care only about isomorphisms
|
157
|
+
|
158
|
+
# STATIC DATA
|
159
|
+
cdef unsigned int q # cardinality of the field
|
160
|
+
cdef unsigned int k # size of the subsets
|
161
|
+
cdef unsigned int e # k(k-1)/2
|
162
|
+
cdef unsigned int m # (q-1) / e
|
163
|
+
cdef unsigned int ** diff # qxq array: diff[x][y] = x - y
|
164
|
+
cdef unsigned int ** ratio # qxq array: ratio[x][y] = x / y
|
165
|
+
cdef unsigned int * min_orb # q array : min_orb[x] = min {x, 1-x, 1/x,
|
166
|
+
# 1/(1-x), (x-1)/x, x/(x-1)}
|
167
|
+
|
168
|
+
# DYNAMIC DATA
|
169
|
+
cdef unsigned int * B # current stack of elements of {0,...,q-1}
|
170
|
+
cdef unsigned int * cosets # e array: cosets of differences of elts in B
|
171
|
+
cdef unsigned int * t # e array: temporary variable for updates
|
172
|
+
|
173
|
+
# MANAGEMENT OF MEMORY
|
174
|
+
cdef MemoryAllocator mem
|
175
|
+
|
176
|
+
def __init__(self, K, k, up_to_isomorphism=True, check=False):
|
177
|
+
r"""
|
178
|
+
TESTS::
|
179
|
+
|
180
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
181
|
+
|
182
|
+
sage: EvenlyDistributedSetsBacktracker(Zmod(4),2)
|
183
|
+
Traceback (most recent call last):
|
184
|
+
...
|
185
|
+
ValueError: Ring of integers modulo 4 is not a field
|
186
|
+
|
187
|
+
sage: EvenlyDistributedSetsBacktracker(Zmod(71),7)
|
188
|
+
Traceback (most recent call last):
|
189
|
+
...
|
190
|
+
ValueError: k(k-1)=42 does not divide q-1=70
|
191
|
+
|
192
|
+
For `q=421` which is congruent to 1 modulo `12`, `20`, `30` and `42` we
|
193
|
+
run backtracker with the ``check`` argument set to ``True``::
|
194
|
+
|
195
|
+
sage: for _ in EvenlyDistributedSetsBacktracker(Zmod(421), 4, check=True):
|
196
|
+
....: pass
|
197
|
+
sage: for _ in EvenlyDistributedSetsBacktracker(Zmod(421), 5, check=True):
|
198
|
+
....: pass
|
199
|
+
sage: for _ in EvenlyDistributedSetsBacktracker(Zmod(421), 6, check=True):
|
200
|
+
....: pass
|
201
|
+
sage: for _ in EvenlyDistributedSetsBacktracker(Zmod(421), 7, check=True):
|
202
|
+
....: pass
|
203
|
+
"""
|
204
|
+
self.check = bool(check)
|
205
|
+
self.up_to_isom = bool(up_to_isomorphism)
|
206
|
+
self.count = 0
|
207
|
+
|
208
|
+
cdef unsigned int i,j
|
209
|
+
|
210
|
+
if K not in Fields():
|
211
|
+
raise ValueError(f"{K} is not a field")
|
212
|
+
cdef unsigned int q = K.cardinality()
|
213
|
+
cdef unsigned int e = k*(k-1)/2
|
214
|
+
if (q-1) % (2*e):
|
215
|
+
raise ValueError("k(k-1)={} does not divide q-1={}".format(k*(k-1),q-1))
|
216
|
+
cdef unsigned int m = (q - 1) // e
|
217
|
+
|
218
|
+
self.q = q
|
219
|
+
self.e = e
|
220
|
+
self.k = k
|
221
|
+
self.m = (q - 1) // e
|
222
|
+
self.K = K
|
223
|
+
|
224
|
+
self.mem = MemoryAllocator()
|
225
|
+
self.diff = <unsigned int **> self.mem.calloc(q, sizeof(unsigned int *))
|
226
|
+
self.diff[0] = <unsigned int *> self.mem.malloc(q*q*sizeof(unsigned int))
|
227
|
+
for i in range(1, self.q):
|
228
|
+
self.diff[i] = self.diff[i-1] + q
|
229
|
+
|
230
|
+
self.ratio = <unsigned int **> self.mem.calloc(q, sizeof(unsigned int *))
|
231
|
+
self.ratio[0] = <unsigned int *> self.mem.malloc(q*q*sizeof(unsigned int))
|
232
|
+
for i in range(1, self.q):
|
233
|
+
self.ratio[i] = self.ratio[i-1] + q
|
234
|
+
|
235
|
+
self.B = <unsigned int *> self.mem.malloc(k*sizeof(unsigned int))
|
236
|
+
self.min_orb = <unsigned int *> self.mem.malloc(q*sizeof(unsigned int))
|
237
|
+
self.cosets = <unsigned int *> self.mem.malloc(e*sizeof(unsigned int))
|
238
|
+
self.t = <unsigned int *> self.mem.malloc(e*sizeof(unsigned int))
|
239
|
+
|
240
|
+
x = K.multiplicative_generator()
|
241
|
+
list_K = []
|
242
|
+
for i in range(e):
|
243
|
+
list_K.extend(sorted(x**(j*e+i) for j in range(m)))
|
244
|
+
list_K.append(K.zero())
|
245
|
+
self.list_K = list_K
|
246
|
+
K_to_int = self.K_to_int = {y:i for i,y in enumerate(list_K)}
|
247
|
+
|
248
|
+
zero = K.zero()
|
249
|
+
one = K.one()
|
250
|
+
assert self.K_to_int[zero] == q-1
|
251
|
+
assert self.K_to_int[one] == 0
|
252
|
+
assert set(K) == set(list_K)
|
253
|
+
|
254
|
+
self.min_orb[0] = self.min_orb[q-1] = 0
|
255
|
+
for i,x in enumerate(self.list_K):
|
256
|
+
if x != zero and x != one:
|
257
|
+
self.min_orb[i] = min(K_to_int[z] for z in
|
258
|
+
[x, one/x, one-x, one/(one-x), (x-one)/x, x/(x-one)])
|
259
|
+
for j,y in enumerate(self.list_K):
|
260
|
+
self.diff[i][j] = K_to_int[x-y]
|
261
|
+
if y:
|
262
|
+
self.ratio[i][j] = K_to_int[x/y]
|
263
|
+
else:
|
264
|
+
self.ratio[i][j] = UINT_MAX
|
265
|
+
|
266
|
+
def to_difference_family(self, B, check=True):
|
267
|
+
r"""
|
268
|
+
Given an evenly distributed set ``B`` convert it to a difference family.
|
269
|
+
|
270
|
+
As for any `x\in K^*=H` we have `|\Delta B \cap x
|
271
|
+
H^{2(q-1)/(k(k-1))}|=2` (see :class:`EvenlyDistributedSetsBacktracker`),
|
272
|
+
the difference family is produced as `\{xB:x\in H^{2(q-1)/(k(k-1))}\}`
|
273
|
+
|
274
|
+
This method is useful if you want to obtain the difference family from
|
275
|
+
the output of the iterator.
|
276
|
+
|
277
|
+
INPUT:
|
278
|
+
|
279
|
+
- ``B`` -- an evenly distributed set
|
280
|
+
|
281
|
+
- ``check`` -- boolean (default: ``True``); whether to check the result
|
282
|
+
|
283
|
+
EXAMPLES::
|
284
|
+
|
285
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
286
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(41),5)
|
287
|
+
sage: B = E.an_element(); B
|
288
|
+
[0, 1, 13, 38, 31]
|
289
|
+
sage: D = E.to_difference_family(B); D
|
290
|
+
[[0, 1, 13, 38, 31], [0, 32, 6, 27, 8]]
|
291
|
+
|
292
|
+
sage: from sage.combinat.designs.difference_family import is_difference_family
|
293
|
+
sage: is_difference_family(Zmod(41),D,41,5,1)
|
294
|
+
True
|
295
|
+
|
296
|
+
Setting ``check`` to ``False`` is much faster::
|
297
|
+
|
298
|
+
sage: timeit("df = E.to_difference_family(B, check=True)") # random
|
299
|
+
625 loops, best of 3: 117 µs per loop
|
300
|
+
|
301
|
+
sage: timeit("df = E.to_difference_family(B, check=False)") # random
|
302
|
+
625 loops, best of 3: 1.83 µs per loop
|
303
|
+
"""
|
304
|
+
xe = self.K.multiplicative_generator() ** (self.e)
|
305
|
+
df = [[xe**j*b for b in B] for j in range((self.q-1)/(2*self.e))]
|
306
|
+
if check:
|
307
|
+
from sage.combinat.designs.difference_family import is_difference_family
|
308
|
+
if not is_difference_family(self.K, df, self.q, self.k, 1):
|
309
|
+
raise RuntimeError("a wrong evenly distributed set was "
|
310
|
+
"produced by the Sage library for the parameters:\n"
|
311
|
+
" q={} k={}\n"
|
312
|
+
"Please send an e-mail to "
|
313
|
+
"sage-devel@googlegroups.com".format(self.q, self.k))
|
314
|
+
return df
|
315
|
+
|
316
|
+
def an_element(self):
|
317
|
+
r"""
|
318
|
+
Return an evenly distributed set.
|
319
|
+
|
320
|
+
If there is no such subset raise an
|
321
|
+
:class:`~sage.categories.sets_cat.EmptySetError`.
|
322
|
+
|
323
|
+
EXAMPLES::
|
324
|
+
|
325
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
326
|
+
|
327
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(41),5)
|
328
|
+
sage: E.an_element()
|
329
|
+
[0, 1, 13, 38, 31]
|
330
|
+
|
331
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(61),6)
|
332
|
+
sage: E.an_element()
|
333
|
+
Traceback (most recent call last):
|
334
|
+
...
|
335
|
+
EmptySetError: no 6-evenly distributed set in Ring of integers modulo 61
|
336
|
+
"""
|
337
|
+
from sage.categories.sets_cat import EmptySetError
|
338
|
+
it = iter(self)
|
339
|
+
try:
|
340
|
+
B = next(it)
|
341
|
+
except StopIteration:
|
342
|
+
raise EmptySetError("no {}-evenly distributed set in {}".format(self.k,self.K))
|
343
|
+
self.to_difference_family(B, check=True) # check the validity
|
344
|
+
return B
|
345
|
+
|
346
|
+
def __repr__(self):
|
347
|
+
r"""
|
348
|
+
A string representative.
|
349
|
+
|
350
|
+
EXAMPLES::
|
351
|
+
|
352
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
353
|
+
|
354
|
+
sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4)
|
355
|
+
4-evenly distributed sets (up to isomorphism) in Finite Field in a of size 5^2
|
356
|
+
sage: EvenlyDistributedSetsBacktracker(GF(25,'a'), 4,
|
357
|
+
....: up_to_isomorphism=False)
|
358
|
+
4-evenly distributed sets in Finite Field in a of size 5^2
|
359
|
+
"""
|
360
|
+
return "{}-evenly distributed sets {} in {}".format(
|
361
|
+
self.k,
|
362
|
+
'(up to isomorphism)' if self.up_to_isom else '',
|
363
|
+
self.K)
|
364
|
+
|
365
|
+
def cardinality(self):
|
366
|
+
r"""
|
367
|
+
Return the number of evenly distributed sets.
|
368
|
+
|
369
|
+
Use with precaution as there can be a lot of such sets and this method
|
370
|
+
might be very long to answer!
|
371
|
+
|
372
|
+
EXAMPLES::
|
373
|
+
|
374
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
375
|
+
|
376
|
+
sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'), 4); E
|
377
|
+
4-evenly distributed sets (up to isomorphism)
|
378
|
+
in Finite Field in a of size 5^2
|
379
|
+
sage: E.cardinality()
|
380
|
+
4
|
381
|
+
|
382
|
+
sage: E = EvenlyDistributedSetsBacktracker(GF(25,'a'), 4,
|
383
|
+
....: up_to_isomorphism=False)
|
384
|
+
sage: E.cardinality()
|
385
|
+
40
|
386
|
+
"""
|
387
|
+
cdef n = 0
|
388
|
+
self.count = 1
|
389
|
+
for a in self:
|
390
|
+
n += a
|
391
|
+
self.count = 0
|
392
|
+
return smallInteger(n)
|
393
|
+
|
394
|
+
def _B_relabelled_copies(self):
|
395
|
+
r"""
|
396
|
+
Check whether ``self.B`` is minimal among its relabelization.
|
397
|
+
|
398
|
+
If `B=\{b_1,...,b_k\}` is an evenly distributed set and contains `0` and
|
399
|
+
`1`, then for any two distinct `i,j` we define `f_{ij} : x \mapsto
|
400
|
+
(x-b_j)/(b_i-b_j)` which maps `B` on another evenly distributed set of
|
401
|
+
size `k` containing `0` and `1`. For each pair `i,j` we consider check
|
402
|
+
whether the set `f_{ij}(B)` is smaller than `B`.
|
403
|
+
|
404
|
+
This is an internal function and should only be call by the backtracker
|
405
|
+
implemented in the method ``__iter__``.
|
406
|
+
|
407
|
+
OUTPUT: ``False`` if ``self.B`` is not minimal
|
408
|
+
|
409
|
+
- the list of evenly distributed sets isomorphic to ``self.B``
|
410
|
+
given as a list of tuples if ``self.up_to_isom=0`` or list
|
411
|
+
containing only ``self.B`` as a tuple if ``self.up_to_isom=1``.
|
412
|
+
|
413
|
+
TESTS::
|
414
|
+
|
415
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
416
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(13), 4, up_to_isomorphism=True)
|
417
|
+
sage: E.cardinality() # indirect doctest
|
418
|
+
1
|
419
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(13), 4, up_to_isomorphism=False)
|
420
|
+
sage: E.cardinality() # indirect doctest
|
421
|
+
4
|
422
|
+
|
423
|
+
.. NOTE::
|
424
|
+
|
425
|
+
this method is not seriously optimized. The main goal of this backtracker
|
426
|
+
is to generate one evenly distributed set. In that case, this method
|
427
|
+
will be called only once.
|
428
|
+
"""
|
429
|
+
cdef unsigned int i,j,k,tmp1,tmp2,verify
|
430
|
+
cdef list B = [self.B[i] for i in range(1, self.k)]
|
431
|
+
B.append(self.q-1)
|
432
|
+
cdef list BB = [None]*self.k
|
433
|
+
cdef set relabs = set([tuple(B)])
|
434
|
+
|
435
|
+
# z -> (z - B[i]) / (B[j] - B[i])
|
436
|
+
for i in range(self.k):
|
437
|
+
for j in range(self.k):
|
438
|
+
if i == j:
|
439
|
+
continue
|
440
|
+
tmp1 = self.diff[self.B[j]][self.B[i]]
|
441
|
+
|
442
|
+
verify = 0
|
443
|
+
for k in range(self.k):
|
444
|
+
if k == i:
|
445
|
+
BB[k] = self.q-1
|
446
|
+
elif k == j:
|
447
|
+
BB[k] = 0
|
448
|
+
else:
|
449
|
+
tmp2 = self.ratio[self.diff[self.B[k]][self.B[i]]][tmp1]
|
450
|
+
if tmp2 == 0 or tmp2 == self.q-1 or tmp2 < self.B[2]:
|
451
|
+
# the backtracker should never build a set which by
|
452
|
+
# relabelling is strictly smaller than B[:3]
|
453
|
+
raise RuntimeError("there is a problem got tmp2={}".format(tmp2,self.B[2]))
|
454
|
+
elif tmp2 == self.B[2]:
|
455
|
+
verify = 1
|
456
|
+
BB[k] = tmp2
|
457
|
+
|
458
|
+
if verify:
|
459
|
+
BB.sort()
|
460
|
+
if BB < B:
|
461
|
+
return False
|
462
|
+
|
463
|
+
if not self.up_to_isom:
|
464
|
+
if not verify:
|
465
|
+
BB.sort()
|
466
|
+
relabs.add(tuple(BB))
|
467
|
+
|
468
|
+
return sorted(relabs)
|
469
|
+
|
470
|
+
@cython.cdivision(True)
|
471
|
+
@cython.boundscheck(False)
|
472
|
+
@cython.wraparound(False)
|
473
|
+
def __iter__(self):
|
474
|
+
r"""
|
475
|
+
Iterator through all evenly distributed sets that start with `[0,1]`.
|
476
|
+
|
477
|
+
EXAMPLES::
|
478
|
+
|
479
|
+
sage: from sage.combinat.designs.evenly_distributed_sets import EvenlyDistributedSetsBacktracker
|
480
|
+
|
481
|
+
sage: E = EvenlyDistributedSetsBacktracker(Zmod(13),4)
|
482
|
+
sage: for B in E:
|
483
|
+
....: print(B)
|
484
|
+
[0, 1, 11, 5]
|
485
|
+
"""
|
486
|
+
cdef unsigned int k_m_1 = self.k - 1
|
487
|
+
cdef unsigned int q_m_1 = self.q - 1
|
488
|
+
cdef unsigned int m = self.m
|
489
|
+
|
490
|
+
# in the list B we store the candidate for being an e.d.s.
|
491
|
+
# we always have B[0] = 0 and B[1] = 1
|
492
|
+
# because 0 is in B, the cosets of the elements of B must be
|
493
|
+
# disjoint.
|
494
|
+
cdef unsigned int kk = 2
|
495
|
+
cdef unsigned int * B = self.B
|
496
|
+
B[0] = q_m_1 # the element 0 in K
|
497
|
+
B[1] = 0 # the element 1 in K
|
498
|
+
|
499
|
+
memset(self.cosets, 0, self.e * sizeof(unsigned int))
|
500
|
+
|
501
|
+
self.cosets[0] = 1 # coset 0 is hit by the difference 1-0
|
502
|
+
|
503
|
+
cdef unsigned int x = m
|
504
|
+
while True:
|
505
|
+
if self.check:
|
506
|
+
self._check_cosets(kk)
|
507
|
+
if x < m or x >= q_m_1:
|
508
|
+
raise RuntimeError("got x < m or x > q_m_1 (x={})".format(x))
|
509
|
+
if self.cosets[x/m]:
|
510
|
+
raise RuntimeError("got x={} in an already occupied coset".format(x))
|
511
|
+
|
512
|
+
# try to append x
|
513
|
+
B[kk] = x
|
514
|
+
if self._check_last_element(kk):
|
515
|
+
if kk == k_m_1:
|
516
|
+
ans = self._B_relabelled_copies()
|
517
|
+
|
518
|
+
if self.check and ans:
|
519
|
+
for a in ans:
|
520
|
+
r = [self.list_K[q_m_1]] + [self.list_K[a[r]] for r in range(k_m_1)]
|
521
|
+
self.to_difference_family(r, check=True)
|
522
|
+
|
523
|
+
if ans is False:
|
524
|
+
pass
|
525
|
+
elif self.count:
|
526
|
+
yield len(ans)
|
527
|
+
else:
|
528
|
+
for a in ans:
|
529
|
+
yield [self.list_K[q_m_1]] + [self.list_K[a[r]] for r in range(k_m_1)]
|
530
|
+
|
531
|
+
# remove the differences created by x and increment
|
532
|
+
for j in range(kk):
|
533
|
+
self.cosets[ self.diff[x][B[j]] / m ] = 0
|
534
|
+
x += 1
|
535
|
+
else:
|
536
|
+
kk += 1
|
537
|
+
x += m - x % m
|
538
|
+
else:
|
539
|
+
x += 1
|
540
|
+
|
541
|
+
if self.check:
|
542
|
+
self._check_cosets(kk)
|
543
|
+
|
544
|
+
# now we determine the next element x to be tested
|
545
|
+
while True:
|
546
|
+
if kk == 1:
|
547
|
+
return
|
548
|
+
elif x == q_m_1:
|
549
|
+
kk -= 1
|
550
|
+
x = self.B[kk]
|
551
|
+
# remove the differences created by x and increment
|
552
|
+
for j in range(kk):
|
553
|
+
self.cosets[ self.diff[x][B[j]] / m ] = 0
|
554
|
+
x += 1
|
555
|
+
if self.check:
|
556
|
+
self._check_cosets(kk)
|
557
|
+
elif self.cosets[x / m]:
|
558
|
+
x += m - x % m
|
559
|
+
elif kk == 2:
|
560
|
+
if self.min_orb[x] < x:
|
561
|
+
x += 1
|
562
|
+
else:
|
563
|
+
break
|
564
|
+
else:
|
565
|
+
if self.min_orb[x] < B[2]:
|
566
|
+
x += 1
|
567
|
+
else:
|
568
|
+
break
|
569
|
+
|
570
|
+
@cython.cdivision(True)
|
571
|
+
cdef inline int _check_last_element(self, unsigned int kk) except -1:
|
572
|
+
r"""
|
573
|
+
Add the element ``x`` to ``B`` in position kk if the resulting set is
|
574
|
+
still evenly distributed.
|
575
|
+
|
576
|
+
OUTPUT:
|
577
|
+
|
578
|
+
1 if the element was added, and 0 otherwise.
|
579
|
+
"""
|
580
|
+
cdef unsigned int i, j, x_m_i, x_m_j
|
581
|
+
cdef unsigned int m = self.m
|
582
|
+
cdef unsigned int * B = self.B
|
583
|
+
cdef unsigned int ** diff = self.diff
|
584
|
+
cdef unsigned int x = B[kk]
|
585
|
+
|
586
|
+
# We check two things:
|
587
|
+
# 1. that the newly created differences x-B[i] will not be in a coset
|
588
|
+
# already occuppied
|
589
|
+
#
|
590
|
+
# 2. that by applying some automorphisms we will not get an
|
591
|
+
# element smaller than B[2].
|
592
|
+
#
|
593
|
+
# We should test all linear functions that send a subset of the form
|
594
|
+
# {x, B[i], B[j]} to some {0, 1, ?}.
|
595
|
+
#
|
596
|
+
# Note that if {x, B[i], B[j]} can be mapped to {0, 1, z} by some
|
597
|
+
# function, then it can also be mapped to all {0, 1, z'} where z'=
|
598
|
+
# 1/z, 1-z, 1/(1-z), (z-1)/z and z/(z-1). The attribute
|
599
|
+
# 'min_orbit[z]' is exactly the minimum among these values.
|
600
|
+
#
|
601
|
+
# So, it is enough to test one of these functions. We choose t -> (x
|
602
|
+
# - t)/ (x - B[j]) (that maps x to 0 and B[j] to 1). Its value at
|
603
|
+
# B[i] is just z = (x - B[i]) / (x - B[j]).
|
604
|
+
#
|
605
|
+
# In the special case when kk=2, or equivalently when we are testing if x
|
606
|
+
# fits as a new B[2], then we just check that x is the minimum among
|
607
|
+
# {x, 1/x, 1-x, 1/(1-x), (x-1)/x and x/(x-1)}.
|
608
|
+
|
609
|
+
if self.cosets[diff[x][0] / m] == 1:
|
610
|
+
return 0
|
611
|
+
|
612
|
+
self.cosets[x / m] = 1
|
613
|
+
for i in range(2,kk):
|
614
|
+
x_m_i = diff[x][B[i]]
|
615
|
+
|
616
|
+
# 1. check that the difference x-B[i] was not already in an
|
617
|
+
# occuppied coset
|
618
|
+
if self.cosets[x_m_i / m]:
|
619
|
+
self.cosets[x / m] = 0
|
620
|
+
return 0
|
621
|
+
|
622
|
+
# 2. check relabeling
|
623
|
+
for j in range(i):
|
624
|
+
x_m_j = diff[x][B[j]]
|
625
|
+
if self.min_orb[self.ratio[x_m_i][x_m_j]] < B[2]:
|
626
|
+
self.cosets[x / m] = 0
|
627
|
+
return 0
|
628
|
+
|
629
|
+
# Now check that the x-B[i] belongs to distinct cosets
|
630
|
+
memcpy(self.t, self.cosets, self.e*sizeof(unsigned int))
|
631
|
+
for i in range(1,kk):
|
632
|
+
x_m_i = diff[x][B[i]] / m
|
633
|
+
if self.t[x_m_i]:
|
634
|
+
self.cosets[x / m] = 0
|
635
|
+
return 0
|
636
|
+
self.t[x_m_i] = 1
|
637
|
+
self.t, self.cosets = self.cosets, self.t
|
638
|
+
return 1
|
639
|
+
|
640
|
+
@cython.cdivision(True)
|
641
|
+
cdef int _check_cosets(self, unsigned int kk) except -1:
|
642
|
+
r"""
|
643
|
+
Sanity check (only for debug purposes).
|
644
|
+
"""
|
645
|
+
cdef unsigned int i,j
|
646
|
+
cdef unsigned int m = self.m
|
647
|
+
cdef unsigned int c
|
648
|
+
|
649
|
+
# count the number of elements in self.cosets
|
650
|
+
c = 0
|
651
|
+
for i in range(self.e):
|
652
|
+
c += self.cosets[i]
|
653
|
+
if 2 * c != (kk * (kk-1)):
|
654
|
+
raise RuntimeError("the number of elements in cosets is wrong! Got {} instead of {}.".format(c, (kk*(kk-1))/2))
|
655
|
+
|
656
|
+
for i in range(kk):
|
657
|
+
for j in range(i):
|
658
|
+
if self.cosets[ self.diff[self.B[i]][self.B[j]] / m ] != 1:
|
659
|
+
raise RuntimeError("self.cosets misses the difference B[{}]-B[{}]".format(i, j))
|
660
|
+
|
661
|
+
return 0
|