passagemath-combinat 10.6.31rc3__cp314-cp314-macosx_13_0_x86_64.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.
Potentially problematic release.
This version of passagemath-combinat might be problematic. Click here for more details.
- passagemath_combinat-10.6.31rc3.dist-info/METADATA +160 -0
- passagemath_combinat-10.6.31rc3.dist-info/RECORD +399 -0
- passagemath_combinat-10.6.31rc3.dist-info/WHEEL +6 -0
- passagemath_combinat-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_combinat.dylibs/libgmp.10.dylib +0 -0
- passagemath_combinat.dylibs/libsymmetrica.3.0.0.dylib +0 -0
- sage/algebras/affine_nil_temperley_lieb.py +263 -0
- sage/algebras/all.py +25 -0
- sage/algebras/all__sagemath_combinat.py +35 -0
- sage/algebras/askey_wilson.py +935 -0
- sage/algebras/associated_graded.py +345 -0
- sage/algebras/cellular_basis.py +350 -0
- sage/algebras/cluster_algebra.py +2766 -0
- sage/algebras/down_up_algebra.py +860 -0
- sage/algebras/free_algebra.py +1698 -0
- sage/algebras/free_algebra_element.py +345 -0
- sage/algebras/free_algebra_quotient.py +405 -0
- sage/algebras/free_algebra_quotient_element.py +295 -0
- sage/algebras/free_zinbiel_algebra.py +885 -0
- sage/algebras/hall_algebra.py +783 -0
- sage/algebras/hecke_algebras/all.py +4 -0
- sage/algebras/hecke_algebras/ariki_koike_algebra.py +1796 -0
- sage/algebras/hecke_algebras/ariki_koike_specht_modules.py +475 -0
- sage/algebras/hecke_algebras/cubic_hecke_algebra.py +3520 -0
- sage/algebras/hecke_algebras/cubic_hecke_base_ring.py +1473 -0
- sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py +1079 -0
- sage/algebras/iwahori_hecke_algebra.py +3095 -0
- sage/algebras/jordan_algebra.py +1773 -0
- sage/algebras/lie_conformal_algebras/abelian_lie_conformal_algebra.py +113 -0
- sage/algebras/lie_conformal_algebras/affine_lie_conformal_algebra.py +156 -0
- sage/algebras/lie_conformal_algebras/all.py +18 -0
- sage/algebras/lie_conformal_algebras/bosonic_ghosts_lie_conformal_algebra.py +134 -0
- sage/algebras/lie_conformal_algebras/examples.py +43 -0
- sage/algebras/lie_conformal_algebras/fermionic_ghosts_lie_conformal_algebra.py +131 -0
- sage/algebras/lie_conformal_algebras/finitely_freely_generated_lca.py +139 -0
- sage/algebras/lie_conformal_algebras/free_bosons_lie_conformal_algebra.py +174 -0
- sage/algebras/lie_conformal_algebras/free_fermions_lie_conformal_algebra.py +167 -0
- sage/algebras/lie_conformal_algebras/freely_generated_lie_conformal_algebra.py +107 -0
- sage/algebras/lie_conformal_algebras/graded_lie_conformal_algebra.py +135 -0
- sage/algebras/lie_conformal_algebras/lie_conformal_algebra.py +353 -0
- sage/algebras/lie_conformal_algebras/lie_conformal_algebra_element.py +236 -0
- sage/algebras/lie_conformal_algebras/lie_conformal_algebra_with_basis.py +78 -0
- sage/algebras/lie_conformal_algebras/lie_conformal_algebra_with_structure_coefs.py +328 -0
- sage/algebras/lie_conformal_algebras/n2_lie_conformal_algebra.py +117 -0
- sage/algebras/lie_conformal_algebras/neveu_schwarz_lie_conformal_algebra.py +86 -0
- sage/algebras/lie_conformal_algebras/virasoro_lie_conformal_algebra.py +82 -0
- sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py +205 -0
- sage/algebras/nil_coxeter_algebra.py +191 -0
- sage/algebras/q_commuting_polynomials.py +673 -0
- sage/algebras/q_system.py +608 -0
- sage/algebras/quantum_clifford.py +959 -0
- sage/algebras/quantum_groups/ace_quantum_onsager.py +693 -0
- sage/algebras/quantum_groups/all.py +9 -0
- sage/algebras/quantum_groups/fock_space.py +2219 -0
- sage/algebras/quantum_groups/q_numbers.py +207 -0
- sage/algebras/quantum_groups/quantum_group_gap.py +2695 -0
- sage/algebras/quantum_groups/representations.py +591 -0
- sage/algebras/quantum_matrix_coordinate_algebra.py +1006 -0
- sage/algebras/quantum_oscillator.py +623 -0
- sage/algebras/quaternion_algebra.py +20 -0
- sage/algebras/quaternion_algebra_element.py +55 -0
- sage/algebras/rational_cherednik_algebra.py +525 -0
- sage/algebras/schur_algebra.py +670 -0
- sage/algebras/shuffle_algebra.py +1011 -0
- sage/algebras/splitting_algebra.py +779 -0
- sage/algebras/tensor_algebra.py +709 -0
- sage/algebras/yangian.py +1082 -0
- sage/algebras/yokonuma_hecke_algebra.py +1018 -0
- sage/all__sagemath_combinat.py +35 -0
- sage/combinat/SJT.py +255 -0
- sage/combinat/affine_permutation.py +2405 -0
- sage/combinat/algebraic_combinatorics.py +55 -0
- sage/combinat/all.py +53 -0
- sage/combinat/all__sagemath_combinat.py +195 -0
- sage/combinat/alternating_sign_matrix.py +2063 -0
- sage/combinat/baxter_permutations.py +346 -0
- sage/combinat/bijectionist.py +3220 -0
- sage/combinat/binary_recurrence_sequences.py +1180 -0
- sage/combinat/blob_algebra.py +685 -0
- sage/combinat/catalog_partitions.py +27 -0
- sage/combinat/chas/all.py +23 -0
- sage/combinat/chas/fsym.py +1180 -0
- sage/combinat/chas/wqsym.py +2601 -0
- sage/combinat/cluster_complex.py +326 -0
- sage/combinat/colored_permutations.py +2039 -0
- sage/combinat/colored_permutations_representations.py +964 -0
- sage/combinat/composition_signed.py +142 -0
- sage/combinat/composition_tableau.py +855 -0
- sage/combinat/constellation.py +1729 -0
- sage/combinat/core.py +751 -0
- sage/combinat/counting.py +12 -0
- sage/combinat/crystals/affine.py +742 -0
- sage/combinat/crystals/affine_factorization.py +518 -0
- sage/combinat/crystals/affinization.py +331 -0
- sage/combinat/crystals/alcove_path.py +2013 -0
- sage/combinat/crystals/all.py +22 -0
- sage/combinat/crystals/bkk_crystals.py +141 -0
- sage/combinat/crystals/catalog.py +115 -0
- sage/combinat/crystals/catalog_elementary_crystals.py +18 -0
- sage/combinat/crystals/catalog_infinity_crystals.py +33 -0
- sage/combinat/crystals/catalog_kirillov_reshetikhin.py +18 -0
- sage/combinat/crystals/crystals.py +257 -0
- sage/combinat/crystals/direct_sum.py +260 -0
- sage/combinat/crystals/elementary_crystals.py +1251 -0
- sage/combinat/crystals/fast_crystals.py +441 -0
- sage/combinat/crystals/fully_commutative_stable_grothendieck.py +1205 -0
- sage/combinat/crystals/generalized_young_walls.py +1076 -0
- sage/combinat/crystals/highest_weight_crystals.py +436 -0
- sage/combinat/crystals/induced_structure.py +695 -0
- sage/combinat/crystals/infinity_crystals.py +730 -0
- sage/combinat/crystals/kac_modules.py +863 -0
- sage/combinat/crystals/kirillov_reshetikhin.py +4196 -0
- sage/combinat/crystals/kyoto_path_model.py +497 -0
- sage/combinat/crystals/letters.cpython-314-darwin.so +0 -0
- sage/combinat/crystals/letters.pxd +79 -0
- sage/combinat/crystals/letters.pyx +3056 -0
- sage/combinat/crystals/littelmann_path.py +1518 -0
- sage/combinat/crystals/monomial_crystals.py +1262 -0
- sage/combinat/crystals/multisegments.py +462 -0
- sage/combinat/crystals/mv_polytopes.py +467 -0
- sage/combinat/crystals/pbw_crystal.py +511 -0
- sage/combinat/crystals/pbw_datum.cpython-314-darwin.so +0 -0
- sage/combinat/crystals/pbw_datum.pxd +4 -0
- sage/combinat/crystals/pbw_datum.pyx +487 -0
- sage/combinat/crystals/polyhedral_realization.py +372 -0
- sage/combinat/crystals/spins.cpython-314-darwin.so +0 -0
- sage/combinat/crystals/spins.pxd +21 -0
- sage/combinat/crystals/spins.pyx +756 -0
- sage/combinat/crystals/star_crystal.py +290 -0
- sage/combinat/crystals/subcrystal.py +464 -0
- sage/combinat/crystals/tensor_product.py +1177 -0
- sage/combinat/crystals/tensor_product_element.cpython-314-darwin.so +0 -0
- sage/combinat/crystals/tensor_product_element.pxd +35 -0
- sage/combinat/crystals/tensor_product_element.pyx +1870 -0
- sage/combinat/crystals/virtual_crystal.py +420 -0
- sage/combinat/cyclic_sieving_phenomenon.py +204 -0
- sage/combinat/debruijn_sequence.cpython-314-darwin.so +0 -0
- sage/combinat/debruijn_sequence.pyx +355 -0
- sage/combinat/decorated_permutation.py +270 -0
- sage/combinat/degree_sequences.cpython-314-darwin.so +0 -0
- sage/combinat/degree_sequences.pyx +588 -0
- sage/combinat/derangements.py +527 -0
- sage/combinat/descent_algebra.py +1008 -0
- sage/combinat/diagram.py +1551 -0
- sage/combinat/diagram_algebras.py +5886 -0
- sage/combinat/dyck_word.py +4349 -0
- sage/combinat/e_one_star.py +1623 -0
- sage/combinat/enumerated_sets.py +123 -0
- sage/combinat/expnums.cpython-314-darwin.so +0 -0
- sage/combinat/expnums.pyx +148 -0
- sage/combinat/fast_vector_partitions.cpython-314-darwin.so +0 -0
- sage/combinat/fast_vector_partitions.pyx +346 -0
- sage/combinat/fqsym.py +1977 -0
- sage/combinat/free_dendriform_algebra.py +954 -0
- sage/combinat/free_prelie_algebra.py +1141 -0
- sage/combinat/fully_commutative_elements.py +1077 -0
- sage/combinat/fully_packed_loop.py +1523 -0
- sage/combinat/gelfand_tsetlin_patterns.py +1409 -0
- sage/combinat/gray_codes.py +311 -0
- sage/combinat/grossman_larson_algebras.py +667 -0
- sage/combinat/growth.py +4352 -0
- sage/combinat/hall_polynomial.py +188 -0
- sage/combinat/hillman_grassl.py +866 -0
- sage/combinat/integer_matrices.py +329 -0
- sage/combinat/integer_vectors_mod_permgroup.py +1238 -0
- sage/combinat/k_tableau.py +4564 -0
- sage/combinat/kazhdan_lusztig.py +215 -0
- sage/combinat/key_polynomial.py +885 -0
- sage/combinat/knutson_tao_puzzles.py +2286 -0
- sage/combinat/lr_tableau.py +311 -0
- sage/combinat/matrices/all.py +24 -0
- sage/combinat/matrices/hadamard_matrix.py +3790 -0
- sage/combinat/matrices/latin.py +2912 -0
- sage/combinat/misc.py +401 -0
- sage/combinat/multiset_partition_into_sets_ordered.py +3541 -0
- sage/combinat/ncsf_qsym/all.py +21 -0
- sage/combinat/ncsf_qsym/combinatorics.py +317 -0
- sage/combinat/ncsf_qsym/generic_basis_code.py +1427 -0
- sage/combinat/ncsf_qsym/ncsf.py +5637 -0
- sage/combinat/ncsf_qsym/qsym.py +4053 -0
- sage/combinat/ncsf_qsym/tutorial.py +447 -0
- sage/combinat/ncsym/all.py +21 -0
- sage/combinat/ncsym/bases.py +855 -0
- sage/combinat/ncsym/dual.py +593 -0
- sage/combinat/ncsym/ncsym.py +2076 -0
- sage/combinat/necklace.py +551 -0
- sage/combinat/non_decreasing_parking_function.py +634 -0
- sage/combinat/nu_dyck_word.py +1474 -0
- sage/combinat/output.py +861 -0
- sage/combinat/parallelogram_polyomino.py +4326 -0
- sage/combinat/parking_functions.py +1602 -0
- sage/combinat/partition_algebra.py +1998 -0
- sage/combinat/partition_kleshchev.py +1982 -0
- sage/combinat/partition_shifting_algebras.py +584 -0
- sage/combinat/partition_tuple.py +3114 -0
- sage/combinat/path_tableaux/all.py +13 -0
- sage/combinat/path_tableaux/catalog.py +29 -0
- sage/combinat/path_tableaux/dyck_path.py +380 -0
- sage/combinat/path_tableaux/frieze.py +476 -0
- sage/combinat/path_tableaux/path_tableau.py +728 -0
- sage/combinat/path_tableaux/semistandard.py +510 -0
- sage/combinat/perfect_matching.py +779 -0
- sage/combinat/plane_partition.py +3300 -0
- sage/combinat/q_bernoulli.cpython-314-darwin.so +0 -0
- sage/combinat/q_bernoulli.pyx +128 -0
- sage/combinat/quickref.py +81 -0
- sage/combinat/recognizable_series.py +2051 -0
- sage/combinat/regular_sequence.py +4316 -0
- sage/combinat/regular_sequence_bounded.py +543 -0
- sage/combinat/restricted_growth.py +81 -0
- sage/combinat/ribbon.py +20 -0
- sage/combinat/ribbon_shaped_tableau.py +489 -0
- sage/combinat/ribbon_tableau.py +1180 -0
- sage/combinat/rigged_configurations/all.py +46 -0
- sage/combinat/rigged_configurations/bij_abstract_class.py +548 -0
- sage/combinat/rigged_configurations/bij_infinity.py +370 -0
- sage/combinat/rigged_configurations/bij_type_A.py +163 -0
- sage/combinat/rigged_configurations/bij_type_A2_dual.py +338 -0
- sage/combinat/rigged_configurations/bij_type_A2_even.py +218 -0
- sage/combinat/rigged_configurations/bij_type_A2_odd.py +199 -0
- sage/combinat/rigged_configurations/bij_type_B.py +900 -0
- sage/combinat/rigged_configurations/bij_type_C.py +267 -0
- sage/combinat/rigged_configurations/bij_type_D.py +771 -0
- sage/combinat/rigged_configurations/bij_type_D_tri.py +392 -0
- sage/combinat/rigged_configurations/bij_type_D_twisted.py +576 -0
- sage/combinat/rigged_configurations/bij_type_E67.py +402 -0
- sage/combinat/rigged_configurations/bijection.py +143 -0
- sage/combinat/rigged_configurations/kleber_tree.py +1475 -0
- sage/combinat/rigged_configurations/kr_tableaux.py +1898 -0
- sage/combinat/rigged_configurations/rc_crystal.py +461 -0
- sage/combinat/rigged_configurations/rc_infinity.py +540 -0
- sage/combinat/rigged_configurations/rigged_configuration_element.py +2403 -0
- sage/combinat/rigged_configurations/rigged_configurations.py +1918 -0
- sage/combinat/rigged_configurations/rigged_partition.cpython-314-darwin.so +0 -0
- sage/combinat/rigged_configurations/rigged_partition.pxd +15 -0
- sage/combinat/rigged_configurations/rigged_partition.pyx +680 -0
- sage/combinat/rigged_configurations/tensor_product_kr_tableaux.py +499 -0
- sage/combinat/rigged_configurations/tensor_product_kr_tableaux_element.py +428 -0
- sage/combinat/rsk.py +3438 -0
- sage/combinat/schubert_polynomial.py +508 -0
- sage/combinat/set_partition.py +3318 -0
- sage/combinat/set_partition_iterator.cpython-314-darwin.so +0 -0
- sage/combinat/set_partition_iterator.pyx +136 -0
- sage/combinat/set_partition_ordered.py +1590 -0
- sage/combinat/sf/abreu_nigro.py +346 -0
- sage/combinat/sf/all.py +52 -0
- sage/combinat/sf/character.py +576 -0
- sage/combinat/sf/classical.py +319 -0
- sage/combinat/sf/dual.py +996 -0
- sage/combinat/sf/elementary.py +549 -0
- sage/combinat/sf/hall_littlewood.py +1028 -0
- sage/combinat/sf/hecke.py +336 -0
- sage/combinat/sf/homogeneous.py +464 -0
- sage/combinat/sf/jack.py +1428 -0
- sage/combinat/sf/k_dual.py +1458 -0
- sage/combinat/sf/kfpoly.py +447 -0
- sage/combinat/sf/llt.py +789 -0
- sage/combinat/sf/macdonald.py +2019 -0
- sage/combinat/sf/monomial.py +525 -0
- sage/combinat/sf/multiplicative.py +113 -0
- sage/combinat/sf/new_kschur.py +1786 -0
- sage/combinat/sf/ns_macdonald.py +964 -0
- sage/combinat/sf/orthogonal.py +246 -0
- sage/combinat/sf/orthotriang.py +355 -0
- sage/combinat/sf/powersum.py +963 -0
- sage/combinat/sf/schur.py +880 -0
- sage/combinat/sf/sf.py +1653 -0
- sage/combinat/sf/sfa.py +7053 -0
- sage/combinat/sf/symplectic.py +253 -0
- sage/combinat/sf/witt.py +721 -0
- sage/combinat/shifted_primed_tableau.py +2735 -0
- sage/combinat/shuffle.py +830 -0
- sage/combinat/sidon_sets.py +146 -0
- sage/combinat/similarity_class_type.py +1721 -0
- sage/combinat/sine_gordon.py +618 -0
- sage/combinat/six_vertex_model.py +784 -0
- sage/combinat/skew_partition.py +2053 -0
- sage/combinat/skew_tableau.py +2989 -0
- sage/combinat/sloane_functions.py +8935 -0
- sage/combinat/specht_module.py +1403 -0
- sage/combinat/species/all.py +48 -0
- sage/combinat/species/characteristic_species.py +321 -0
- sage/combinat/species/composition_species.py +273 -0
- sage/combinat/species/cycle_species.py +284 -0
- sage/combinat/species/empty_species.py +155 -0
- sage/combinat/species/functorial_composition_species.py +148 -0
- sage/combinat/species/generating_series.py +673 -0
- sage/combinat/species/library.py +148 -0
- sage/combinat/species/linear_order_species.py +169 -0
- sage/combinat/species/misc.py +83 -0
- sage/combinat/species/partition_species.py +290 -0
- sage/combinat/species/permutation_species.py +268 -0
- sage/combinat/species/product_species.py +423 -0
- sage/combinat/species/recursive_species.py +476 -0
- sage/combinat/species/set_species.py +192 -0
- sage/combinat/species/species.py +820 -0
- sage/combinat/species/structure.py +539 -0
- sage/combinat/species/subset_species.py +243 -0
- sage/combinat/species/sum_species.py +225 -0
- sage/combinat/subword.py +564 -0
- sage/combinat/subword_complex.py +2122 -0
- sage/combinat/subword_complex_c.cpython-314-darwin.so +0 -0
- sage/combinat/subword_complex_c.pyx +119 -0
- sage/combinat/super_tableau.py +821 -0
- sage/combinat/superpartition.py +1154 -0
- sage/combinat/symmetric_group_algebra.py +3774 -0
- sage/combinat/symmetric_group_representations.py +1830 -0
- sage/combinat/t_sequences.py +877 -0
- sage/combinat/tableau.py +9506 -0
- sage/combinat/tableau_residues.py +860 -0
- sage/combinat/tableau_tuple.py +5353 -0
- sage/combinat/tiling.py +2432 -0
- sage/combinat/triangles_FHM.py +777 -0
- sage/combinat/tutorial.py +1857 -0
- sage/combinat/vector_partition.py +337 -0
- sage/combinat/words/abstract_word.py +1722 -0
- sage/combinat/words/all.py +59 -0
- sage/combinat/words/alphabet.py +268 -0
- sage/combinat/words/finite_word.py +7201 -0
- sage/combinat/words/infinite_word.py +113 -0
- sage/combinat/words/lyndon_word.py +652 -0
- sage/combinat/words/morphic.py +351 -0
- sage/combinat/words/morphism.py +3878 -0
- sage/combinat/words/paths.py +2932 -0
- sage/combinat/words/shuffle_product.py +278 -0
- sage/combinat/words/suffix_trees.py +1873 -0
- sage/combinat/words/word.py +765 -0
- sage/combinat/words/word_char.cpython-314-darwin.so +0 -0
- sage/combinat/words/word_char.pyx +847 -0
- sage/combinat/words/word_datatypes.cpython-314-darwin.so +0 -0
- sage/combinat/words/word_datatypes.pxd +4 -0
- sage/combinat/words/word_datatypes.pyx +1067 -0
- sage/combinat/words/word_generators.py +2026 -0
- sage/combinat/words/word_infinite_datatypes.py +1218 -0
- sage/combinat/words/word_options.py +99 -0
- sage/combinat/words/words.py +2396 -0
- sage/data_structures/all__sagemath_combinat.py +1 -0
- sage/databases/all__sagemath_combinat.py +13 -0
- sage/databases/findstat.py +4897 -0
- sage/databases/oeis.py +2058 -0
- sage/databases/sloane.py +393 -0
- sage/dynamics/all__sagemath_combinat.py +14 -0
- sage/dynamics/cellular_automata/all.py +7 -0
- sage/dynamics/cellular_automata/catalog.py +34 -0
- sage/dynamics/cellular_automata/elementary.py +612 -0
- sage/dynamics/cellular_automata/glca.py +477 -0
- sage/dynamics/cellular_automata/solitons.py +1463 -0
- sage/dynamics/finite_dynamical_system.py +1249 -0
- sage/dynamics/finite_dynamical_system_catalog.py +382 -0
- sage/games/all.py +7 -0
- sage/games/hexad.py +704 -0
- sage/games/quantumino.py +591 -0
- sage/games/sudoku.py +889 -0
- sage/games/sudoku_backtrack.cpython-314-darwin.so +0 -0
- sage/games/sudoku_backtrack.pyx +189 -0
- sage/groups/all__sagemath_combinat.py +1 -0
- sage/groups/indexed_free_group.py +489 -0
- sage/libs/all__sagemath_combinat.py +6 -0
- sage/libs/lrcalc/__init__.py +1 -0
- sage/libs/lrcalc/lrcalc.py +525 -0
- sage/libs/symmetrica/__init__.py +7 -0
- sage/libs/symmetrica/all.py +101 -0
- sage/libs/symmetrica/kostka.pxi +168 -0
- sage/libs/symmetrica/part.pxi +193 -0
- sage/libs/symmetrica/plet.pxi +42 -0
- sage/libs/symmetrica/sab.pxi +196 -0
- sage/libs/symmetrica/sb.pxi +332 -0
- sage/libs/symmetrica/sc.pxi +192 -0
- sage/libs/symmetrica/schur.pxi +956 -0
- sage/libs/symmetrica/symmetrica.cpython-314-darwin.so +0 -0
- sage/libs/symmetrica/symmetrica.pxi +1172 -0
- sage/libs/symmetrica/symmetrica.pyx +39 -0
- sage/monoids/all.py +13 -0
- sage/monoids/automatic_semigroup.py +1054 -0
- sage/monoids/free_abelian_monoid.py +315 -0
- sage/monoids/free_abelian_monoid_element.cpython-314-darwin.so +0 -0
- sage/monoids/free_abelian_monoid_element.pxd +16 -0
- sage/monoids/free_abelian_monoid_element.pyx +397 -0
- sage/monoids/free_monoid.py +335 -0
- sage/monoids/free_monoid_element.py +431 -0
- sage/monoids/hecke_monoid.py +65 -0
- sage/monoids/string_monoid.py +817 -0
- sage/monoids/string_monoid_element.py +547 -0
- sage/monoids/string_ops.py +143 -0
- sage/monoids/trace_monoid.py +972 -0
- sage/rings/all__sagemath_combinat.py +2 -0
- sage/sat/all.py +4 -0
- sage/sat/boolean_polynomials.py +405 -0
- sage/sat/converters/__init__.py +6 -0
- sage/sat/converters/anf2cnf.py +14 -0
- sage/sat/converters/polybori.py +611 -0
- sage/sat/solvers/__init__.py +5 -0
- sage/sat/solvers/cryptominisat.py +287 -0
- sage/sat/solvers/dimacs.py +783 -0
- sage/sat/solvers/picosat.py +228 -0
- sage/sat/solvers/sat_lp.py +156 -0
- sage/sat/solvers/satsolver.cpython-314-darwin.so +0 -0
- sage/sat/solvers/satsolver.pxd +3 -0
- sage/sat/solvers/satsolver.pyx +405 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-combinat
|
|
2
|
+
"""
|
|
3
|
+
Derangements
|
|
4
|
+
|
|
5
|
+
AUTHORS:
|
|
6
|
+
|
|
7
|
+
- Alasdair McAndrew (2010-05): Initial version
|
|
8
|
+
- Travis Scrimshaw (2013-03-30): Put derangements into category framework
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# ****************************************************************************
|
|
12
|
+
# Copyright (C) 2010 Alasdair McAndrew <amca01@gmail.com>,
|
|
13
|
+
# 2013 Travis Scrimshaw <tscrim@ucdavis.edu>
|
|
14
|
+
#
|
|
15
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
16
|
+
#
|
|
17
|
+
# This code is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20
|
+
# General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# The full text of the GPL is available at:
|
|
23
|
+
#
|
|
24
|
+
# https://www.gnu.org/licenses/
|
|
25
|
+
# ****************************************************************************
|
|
26
|
+
|
|
27
|
+
from sage.structure.parent import Parent
|
|
28
|
+
from sage.structure.unique_representation import UniqueRepresentation
|
|
29
|
+
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
|
|
30
|
+
from sage.misc.misc_c import prod
|
|
31
|
+
from sage.misc.prandom import random, randrange
|
|
32
|
+
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
|
|
33
|
+
from sage.rings.integer_ring import ZZ
|
|
34
|
+
from sage.rings.rational_field import QQ
|
|
35
|
+
from sage.rings.integer import Integer
|
|
36
|
+
from sage.combinat.combinat import CombinatorialElement
|
|
37
|
+
from sage.combinat.permutation import Permutation, Permutations
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Derangement(CombinatorialElement):
|
|
41
|
+
r"""
|
|
42
|
+
A derangement.
|
|
43
|
+
|
|
44
|
+
A derangement on a set `S` is a permutation `\sigma` such that `\sigma(x)
|
|
45
|
+
\neq x` for all `x \in S`, i.e. `\sigma` is a permutation of `S` with no
|
|
46
|
+
fixed points.
|
|
47
|
+
|
|
48
|
+
EXAMPLES::
|
|
49
|
+
|
|
50
|
+
sage: D = Derangements(4)
|
|
51
|
+
sage: elt = D([4,3,2,1])
|
|
52
|
+
sage: TestSuite(elt).run()
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def to_permutation(self):
|
|
56
|
+
"""
|
|
57
|
+
Return the permutation corresponding to ``self``.
|
|
58
|
+
|
|
59
|
+
EXAMPLES::
|
|
60
|
+
|
|
61
|
+
sage: D = Derangements(4)
|
|
62
|
+
sage: p = D([4,3,2,1]).to_permutation(); p
|
|
63
|
+
[4, 3, 2, 1]
|
|
64
|
+
sage: type(p)
|
|
65
|
+
<class 'sage.combinat.permutation.StandardPermutations_all_with_category.element_class'>
|
|
66
|
+
sage: D = Derangements([1, 3, 3, 4])
|
|
67
|
+
sage: D[0].to_permutation()
|
|
68
|
+
Traceback (most recent call last):
|
|
69
|
+
...
|
|
70
|
+
ValueError: can only convert to a permutation for derangements of [1, 2, ..., n]
|
|
71
|
+
"""
|
|
72
|
+
if self.parent()._set != tuple(range(1, len(self) + 1)):
|
|
73
|
+
raise ValueError("can only convert to a permutation for derangements of [1, 2, ..., n]")
|
|
74
|
+
return Permutation(list(self))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Derangements(UniqueRepresentation, Parent):
|
|
78
|
+
r"""
|
|
79
|
+
The class of all derangements of a set or multiset.
|
|
80
|
+
|
|
81
|
+
A derangement on a set `S` is a permutation `\sigma` such that `\sigma(x)
|
|
82
|
+
\neq x` for all `x \in S`, i.e. `\sigma` is a permutation of `S` with no
|
|
83
|
+
fixed points.
|
|
84
|
+
|
|
85
|
+
For an integer, or a list or string with all elements
|
|
86
|
+
distinct, the derangements are obtained by a standard result described
|
|
87
|
+
in [BV2004]_. For a list or string with repeated elements, the derangements
|
|
88
|
+
are formed by computing all permutations of the input and discarding all
|
|
89
|
+
non-derangements.
|
|
90
|
+
|
|
91
|
+
INPUT:
|
|
92
|
+
|
|
93
|
+
- ``x`` -- can be an integer which corresponds to derangements of
|
|
94
|
+
`\{1, 2, 3, \ldots, x\}`, a list, or a string
|
|
95
|
+
|
|
96
|
+
REFERENCES:
|
|
97
|
+
|
|
98
|
+
- [BV2004]_
|
|
99
|
+
- :wikipedia:`Derangement`
|
|
100
|
+
|
|
101
|
+
EXAMPLES::
|
|
102
|
+
|
|
103
|
+
sage: D1 = Derangements([2,3,4,5])
|
|
104
|
+
sage: D1.list()
|
|
105
|
+
[[3, 4, 5, 2],
|
|
106
|
+
[5, 4, 2, 3],
|
|
107
|
+
[3, 5, 2, 4],
|
|
108
|
+
[4, 5, 3, 2],
|
|
109
|
+
[4, 2, 5, 3],
|
|
110
|
+
[5, 2, 3, 4],
|
|
111
|
+
[5, 4, 3, 2],
|
|
112
|
+
[4, 5, 2, 3],
|
|
113
|
+
[3, 2, 5, 4]]
|
|
114
|
+
sage: D1.cardinality()
|
|
115
|
+
9
|
|
116
|
+
sage: D1.random_element() # random
|
|
117
|
+
[4, 2, 5, 3]
|
|
118
|
+
sage: D2 = Derangements([1,2,3,1,2,3])
|
|
119
|
+
sage: D2.cardinality()
|
|
120
|
+
10
|
|
121
|
+
sage: D2.list()
|
|
122
|
+
[[2, 1, 1, 3, 3, 2],
|
|
123
|
+
[2, 1, 2, 3, 3, 1],
|
|
124
|
+
[2, 3, 1, 2, 3, 1],
|
|
125
|
+
[2, 3, 1, 3, 1, 2],
|
|
126
|
+
[2, 3, 2, 3, 1, 1],
|
|
127
|
+
[3, 1, 1, 2, 3, 2],
|
|
128
|
+
[3, 1, 2, 2, 3, 1],
|
|
129
|
+
[3, 1, 2, 3, 1, 2],
|
|
130
|
+
[3, 3, 1, 2, 1, 2],
|
|
131
|
+
[3, 3, 2, 2, 1, 1]]
|
|
132
|
+
sage: D2.random_element() # random
|
|
133
|
+
[2, 3, 1, 3, 1, 2]
|
|
134
|
+
"""
|
|
135
|
+
@staticmethod
|
|
136
|
+
def __classcall_private__(cls, x):
|
|
137
|
+
"""
|
|
138
|
+
Normalize ``x`` to ensure a unique representation.
|
|
139
|
+
|
|
140
|
+
EXAMPLES::
|
|
141
|
+
|
|
142
|
+
sage: D = Derangements(4)
|
|
143
|
+
sage: D2 = Derangements([1, 2, 3, 4])
|
|
144
|
+
sage: D3 = Derangements((1, 2, 3, 4))
|
|
145
|
+
sage: D is D2
|
|
146
|
+
True
|
|
147
|
+
sage: D is D3
|
|
148
|
+
True
|
|
149
|
+
"""
|
|
150
|
+
if x in ZZ:
|
|
151
|
+
x = tuple(range(1, x + 1))
|
|
152
|
+
return super().__classcall__(cls, tuple(x))
|
|
153
|
+
|
|
154
|
+
def __init__(self, x):
|
|
155
|
+
"""
|
|
156
|
+
Initialize ``self``.
|
|
157
|
+
|
|
158
|
+
EXAMPLES::
|
|
159
|
+
|
|
160
|
+
sage: D = Derangements(4)
|
|
161
|
+
sage: TestSuite(D).run()
|
|
162
|
+
sage: D = Derangements('abcd')
|
|
163
|
+
sage: TestSuite(D).run()
|
|
164
|
+
sage: D = Derangements([2, 2, 1, 1])
|
|
165
|
+
sage: TestSuite(D).run()
|
|
166
|
+
"""
|
|
167
|
+
Parent.__init__(self, category=FiniteEnumeratedSets())
|
|
168
|
+
self._set = x
|
|
169
|
+
self.__multi = len(set(x)) < len(x)
|
|
170
|
+
|
|
171
|
+
def _repr_(self):
|
|
172
|
+
"""
|
|
173
|
+
Return a string representation of ``self``.
|
|
174
|
+
|
|
175
|
+
EXAMPLES::
|
|
176
|
+
|
|
177
|
+
sage: Derangements(4)
|
|
178
|
+
Derangements of the set [1, 2, 3, 4]
|
|
179
|
+
sage: Derangements('abcd')
|
|
180
|
+
Derangements of the set ['a', 'b', 'c', 'd']
|
|
181
|
+
sage: Derangements([2,2,1,1])
|
|
182
|
+
Derangements of the multiset [2, 2, 1, 1]
|
|
183
|
+
"""
|
|
184
|
+
if self.__multi:
|
|
185
|
+
return "Derangements of the multiset %s" % list(self._set)
|
|
186
|
+
return "Derangements of the set %s" % list(self._set)
|
|
187
|
+
|
|
188
|
+
def _element_constructor_(self, der):
|
|
189
|
+
"""
|
|
190
|
+
Construct an element of ``self`` from ``der``.
|
|
191
|
+
|
|
192
|
+
EXAMPLES::
|
|
193
|
+
|
|
194
|
+
sage: D = Derangements(4)
|
|
195
|
+
sage: elt = D([3,1,4,2]); elt
|
|
196
|
+
[3, 1, 4, 2]
|
|
197
|
+
sage: elt.parent() is D
|
|
198
|
+
True
|
|
199
|
+
"""
|
|
200
|
+
if isinstance(der, Derangement):
|
|
201
|
+
if der.parent() is self:
|
|
202
|
+
return der
|
|
203
|
+
raise ValueError("cannot convert %s to an element of %s" % (der, self))
|
|
204
|
+
return self.element_class(self, der)
|
|
205
|
+
|
|
206
|
+
Element = Derangement
|
|
207
|
+
|
|
208
|
+
def __iter__(self):
|
|
209
|
+
"""
|
|
210
|
+
Iterate through ``self``.
|
|
211
|
+
|
|
212
|
+
EXAMPLES::
|
|
213
|
+
|
|
214
|
+
sage: D = Derangements(4)
|
|
215
|
+
sage: D.list() # indirect doctest
|
|
216
|
+
[[2, 3, 4, 1],
|
|
217
|
+
[4, 3, 1, 2],
|
|
218
|
+
[2, 4, 1, 3],
|
|
219
|
+
[3, 4, 2, 1],
|
|
220
|
+
[3, 1, 4, 2],
|
|
221
|
+
[4, 1, 2, 3],
|
|
222
|
+
[4, 3, 2, 1],
|
|
223
|
+
[3, 4, 1, 2],
|
|
224
|
+
[2, 1, 4, 3]]
|
|
225
|
+
sage: D = Derangements([1,44,918,67])
|
|
226
|
+
sage: D.list()
|
|
227
|
+
[[44, 918, 67, 1],
|
|
228
|
+
[67, 918, 1, 44],
|
|
229
|
+
[44, 67, 1, 918],
|
|
230
|
+
[918, 67, 44, 1],
|
|
231
|
+
[918, 1, 67, 44],
|
|
232
|
+
[67, 1, 44, 918],
|
|
233
|
+
[67, 918, 44, 1],
|
|
234
|
+
[918, 67, 1, 44],
|
|
235
|
+
[44, 1, 67, 918]]
|
|
236
|
+
sage: D = Derangements(['A','AT','CAT','CATS'])
|
|
237
|
+
sage: D.list()
|
|
238
|
+
[['AT', 'CAT', 'CATS', 'A'],
|
|
239
|
+
['CATS', 'CAT', 'A', 'AT'],
|
|
240
|
+
['AT', 'CATS', 'A', 'CAT'],
|
|
241
|
+
['CAT', 'CATS', 'AT', 'A'],
|
|
242
|
+
['CAT', 'A', 'CATS', 'AT'],
|
|
243
|
+
['CATS', 'A', 'AT', 'CAT'],
|
|
244
|
+
['CATS', 'CAT', 'AT', 'A'],
|
|
245
|
+
['CAT', 'CATS', 'A', 'AT'],
|
|
246
|
+
['AT', 'A', 'CATS', 'CAT']]
|
|
247
|
+
sage: D = Derangements('CART')
|
|
248
|
+
sage: D.list()
|
|
249
|
+
[['A', 'R', 'T', 'C'],
|
|
250
|
+
['T', 'R', 'C', 'A'],
|
|
251
|
+
['A', 'T', 'C', 'R'],
|
|
252
|
+
['R', 'T', 'A', 'C'],
|
|
253
|
+
['R', 'C', 'T', 'A'],
|
|
254
|
+
['T', 'C', 'A', 'R'],
|
|
255
|
+
['T', 'R', 'A', 'C'],
|
|
256
|
+
['R', 'T', 'C', 'A'],
|
|
257
|
+
['A', 'C', 'T', 'R']]
|
|
258
|
+
sage: D = Derangements([1,1,2,2,3,3])
|
|
259
|
+
sage: D.list()
|
|
260
|
+
[[2, 2, 3, 3, 1, 1],
|
|
261
|
+
[2, 3, 1, 3, 1, 2],
|
|
262
|
+
[2, 3, 1, 3, 2, 1],
|
|
263
|
+
[2, 3, 3, 1, 1, 2],
|
|
264
|
+
[2, 3, 3, 1, 2, 1],
|
|
265
|
+
[3, 2, 1, 3, 1, 2],
|
|
266
|
+
[3, 2, 1, 3, 2, 1],
|
|
267
|
+
[3, 2, 3, 1, 1, 2],
|
|
268
|
+
[3, 2, 3, 1, 2, 1],
|
|
269
|
+
[3, 3, 1, 1, 2, 2]]
|
|
270
|
+
sage: D = Derangements('SATTAS')
|
|
271
|
+
sage: D.list()
|
|
272
|
+
[['A', 'S', 'S', 'A', 'T', 'T'],
|
|
273
|
+
['A', 'S', 'A', 'S', 'T', 'T'],
|
|
274
|
+
['A', 'T', 'S', 'S', 'T', 'A'],
|
|
275
|
+
['A', 'T', 'S', 'A', 'S', 'T'],
|
|
276
|
+
['A', 'T', 'A', 'S', 'S', 'T'],
|
|
277
|
+
['T', 'S', 'S', 'A', 'T', 'A'],
|
|
278
|
+
['T', 'S', 'A', 'S', 'T', 'A'],
|
|
279
|
+
['T', 'S', 'A', 'A', 'S', 'T'],
|
|
280
|
+
['T', 'T', 'S', 'A', 'S', 'A'],
|
|
281
|
+
['T', 'T', 'A', 'S', 'S', 'A']]
|
|
282
|
+
sage: D = Derangements([1,1,2,2,2])
|
|
283
|
+
sage: D.list()
|
|
284
|
+
[]
|
|
285
|
+
sage: D = Derangements(0)
|
|
286
|
+
sage: D.list()
|
|
287
|
+
[[]]
|
|
288
|
+
"""
|
|
289
|
+
if self.__multi:
|
|
290
|
+
for p in Permutations(self._set):
|
|
291
|
+
if not self._fixed_point(p):
|
|
292
|
+
yield self.element_class(self, list(p))
|
|
293
|
+
else:
|
|
294
|
+
for d in self._iter_der(len(self._set)):
|
|
295
|
+
yield self.element_class(self, [self._set[i - 1] for i in d])
|
|
296
|
+
|
|
297
|
+
def _iter_der(self, n):
|
|
298
|
+
r"""
|
|
299
|
+
Iterate through all derangements of the list `[1, 2, 3, \ldots, n]`
|
|
300
|
+
using the method given in [BV2004]_.
|
|
301
|
+
|
|
302
|
+
EXAMPLES::
|
|
303
|
+
|
|
304
|
+
sage: D = Derangements(4)
|
|
305
|
+
sage: list(D._iter_der(4))
|
|
306
|
+
[[2, 3, 4, 1],
|
|
307
|
+
[4, 3, 1, 2],
|
|
308
|
+
[2, 4, 1, 3],
|
|
309
|
+
[3, 4, 2, 1],
|
|
310
|
+
[3, 1, 4, 2],
|
|
311
|
+
[4, 1, 2, 3],
|
|
312
|
+
[4, 3, 2, 1],
|
|
313
|
+
[3, 4, 1, 2],
|
|
314
|
+
[2, 1, 4, 3]]
|
|
315
|
+
"""
|
|
316
|
+
if n == 0:
|
|
317
|
+
yield []
|
|
318
|
+
return
|
|
319
|
+
elif n == 1:
|
|
320
|
+
return
|
|
321
|
+
elif n == 2:
|
|
322
|
+
yield [2, 1]
|
|
323
|
+
elif n == 3:
|
|
324
|
+
yield [2, 3, 1]
|
|
325
|
+
yield [3, 1, 2]
|
|
326
|
+
elif n >= 4:
|
|
327
|
+
for d in self._iter_der(n - 1):
|
|
328
|
+
for i in range(1, n):
|
|
329
|
+
s = d[:]
|
|
330
|
+
ii = d.index(i)
|
|
331
|
+
s[ii] = n
|
|
332
|
+
yield s + [i]
|
|
333
|
+
for d in self._iter_der(n - 2):
|
|
334
|
+
for i in range(1, n):
|
|
335
|
+
s = d[:]
|
|
336
|
+
s = [x >= i and x + 1 or x for x in s]
|
|
337
|
+
s.insert(i - 1, n)
|
|
338
|
+
yield s + [i]
|
|
339
|
+
|
|
340
|
+
def _fixed_point(self, a):
|
|
341
|
+
"""
|
|
342
|
+
Return ``True`` if ``a`` has a point in common with ``self._set``.
|
|
343
|
+
|
|
344
|
+
EXAMPLES::
|
|
345
|
+
|
|
346
|
+
sage: D = Derangements(5)
|
|
347
|
+
sage: D._fixed_point([3,1,2,5,4])
|
|
348
|
+
False
|
|
349
|
+
sage: D._fixed_point([5,4,3,2,1])
|
|
350
|
+
True
|
|
351
|
+
"""
|
|
352
|
+
return any(x == y for (x, y) in zip(a, self._set))
|
|
353
|
+
|
|
354
|
+
def _count_der(self, n):
|
|
355
|
+
"""
|
|
356
|
+
Count the number of derangements of `n` using the recursion
|
|
357
|
+
`D_2 = 1, D_3 = 2, D_n = (n-1) (D_{n-1} + D_{n-2})`.
|
|
358
|
+
|
|
359
|
+
EXAMPLES::
|
|
360
|
+
|
|
361
|
+
sage: D = Derangements(5)
|
|
362
|
+
sage: D._count_der(2)
|
|
363
|
+
1
|
|
364
|
+
sage: D._count_der(3)
|
|
365
|
+
2
|
|
366
|
+
sage: D._count_der(5)
|
|
367
|
+
44
|
|
368
|
+
"""
|
|
369
|
+
if n == 0:
|
|
370
|
+
return Integer(1)
|
|
371
|
+
if n == 1:
|
|
372
|
+
return Integer(0)
|
|
373
|
+
if n == 2:
|
|
374
|
+
return Integer(1)
|
|
375
|
+
if n == 3:
|
|
376
|
+
return Integer(2)
|
|
377
|
+
# n >= 4
|
|
378
|
+
last = Integer(2)
|
|
379
|
+
second_last = Integer(1)
|
|
380
|
+
for i in range(4, n + 1):
|
|
381
|
+
current = (i - 1) * (last + second_last)
|
|
382
|
+
second_last = last
|
|
383
|
+
last = current
|
|
384
|
+
return last
|
|
385
|
+
|
|
386
|
+
def cardinality(self):
|
|
387
|
+
r"""
|
|
388
|
+
Counts the number of derangements of a positive integer, a
|
|
389
|
+
list, or a string. The list or string may contain repeated
|
|
390
|
+
elements. If an integer `n` is given, the value returned
|
|
391
|
+
is the number of derangements of `[1, 2, 3, \ldots, n]`.
|
|
392
|
+
|
|
393
|
+
For an integer, or a list or string with all elements
|
|
394
|
+
distinct, the value is obtained by the standard result
|
|
395
|
+
`D_2 = 1, D_3 = 2, D_n = (n-1) (D_{n-1} + D_{n-2})`.
|
|
396
|
+
|
|
397
|
+
For a list or string with repeated elements, the number of
|
|
398
|
+
derangements is computed by Macmahon's theorem. If the numbers
|
|
399
|
+
of repeated elements are `a_1, a_2, \ldots, a_k` then the number
|
|
400
|
+
of derangements is given by the coefficient of `x_1 x_2 \cdots
|
|
401
|
+
x_k` in the expansion of `\prod_{i=0}^k (S - s_i)^{a_i}` where
|
|
402
|
+
`S = x_1 + x_2 + \cdots + x_k`.
|
|
403
|
+
|
|
404
|
+
EXAMPLES::
|
|
405
|
+
|
|
406
|
+
sage: D = Derangements(5)
|
|
407
|
+
sage: D.cardinality()
|
|
408
|
+
44
|
|
409
|
+
sage: D = Derangements([1,44,918,67,254])
|
|
410
|
+
sage: D.cardinality()
|
|
411
|
+
44
|
|
412
|
+
sage: D = Derangements(['A','AT','CAT','CATS','CARTS'])
|
|
413
|
+
sage: D.cardinality()
|
|
414
|
+
44
|
|
415
|
+
sage: D = Derangements('UNCOPYRIGHTABLE')
|
|
416
|
+
sage: D.cardinality()
|
|
417
|
+
481066515734
|
|
418
|
+
sage: D = Derangements([1,1,2,2,3,3])
|
|
419
|
+
sage: D.cardinality()
|
|
420
|
+
10
|
|
421
|
+
sage: D = Derangements('SATTAS')
|
|
422
|
+
sage: D.cardinality()
|
|
423
|
+
10
|
|
424
|
+
sage: D = Derangements([1,1,2,2,2])
|
|
425
|
+
sage: D.cardinality()
|
|
426
|
+
0
|
|
427
|
+
sage: D = Derangements(0)
|
|
428
|
+
sage: D.cardinality()
|
|
429
|
+
1
|
|
430
|
+
"""
|
|
431
|
+
if self.__multi:
|
|
432
|
+
sL = set(self._set)
|
|
433
|
+
A = [self._set.count(i) for i in sL]
|
|
434
|
+
R = PolynomialRing(QQ, 'x', len(A))
|
|
435
|
+
S = sum(R.gens())
|
|
436
|
+
e = prod((S - x)**y for (x, y) in zip(R.gens(), A))
|
|
437
|
+
return Integer(e.coefficient(dict(zip(R.gens(), A))))
|
|
438
|
+
return self._count_der(len(self._set))
|
|
439
|
+
|
|
440
|
+
def _rand_der(self):
|
|
441
|
+
r"""
|
|
442
|
+
Produces a random derangement of `[1, 2, \ldots, n]`.
|
|
443
|
+
|
|
444
|
+
This is an
|
|
445
|
+
implementation of the algorithm described by Martinez et. al. in
|
|
446
|
+
[MPP2008]_.
|
|
447
|
+
|
|
448
|
+
EXAMPLES::
|
|
449
|
+
|
|
450
|
+
sage: D = Derangements(4)
|
|
451
|
+
sage: d = D._rand_der()
|
|
452
|
+
sage: d in D
|
|
453
|
+
True
|
|
454
|
+
"""
|
|
455
|
+
n = len(self._set)
|
|
456
|
+
A = list(range(1, n + 1))
|
|
457
|
+
mark = [x < 0 for x in A]
|
|
458
|
+
i, u = n, n
|
|
459
|
+
while u >= 2:
|
|
460
|
+
if not mark[i - 1]:
|
|
461
|
+
while True:
|
|
462
|
+
j = randrange(1, i)
|
|
463
|
+
if not mark[j - 1]:
|
|
464
|
+
A[i - 1], A[j - 1] = A[j - 1], A[i - 1]
|
|
465
|
+
break
|
|
466
|
+
p = random()
|
|
467
|
+
if p < (u - 1) * self._count_der(u - 2) // self._count_der(u):
|
|
468
|
+
mark[j - 1] = True
|
|
469
|
+
u -= 1
|
|
470
|
+
u -= 1
|
|
471
|
+
i -= 1
|
|
472
|
+
return A
|
|
473
|
+
|
|
474
|
+
def random_element(self):
|
|
475
|
+
r"""
|
|
476
|
+
Produce all derangements of a positive integer, a list, or
|
|
477
|
+
a string. The list or string may contain repeated elements.
|
|
478
|
+
If an integer `n` is given, then a random
|
|
479
|
+
derangements of `[1, 2, 3, \ldots, n]` is returned
|
|
480
|
+
|
|
481
|
+
For an integer, or a list or string with all elements
|
|
482
|
+
distinct, the value is obtained by an algorithm described in
|
|
483
|
+
[MPP2008]_. For a list or string with repeated elements the
|
|
484
|
+
derangement is formed by choosing an element at random from the list of
|
|
485
|
+
all possible derangements.
|
|
486
|
+
|
|
487
|
+
OUTPUT:
|
|
488
|
+
|
|
489
|
+
A single list or string containing a derangement, or an
|
|
490
|
+
empty list if there are no derangements.
|
|
491
|
+
|
|
492
|
+
EXAMPLES::
|
|
493
|
+
|
|
494
|
+
sage: D = Derangements(4)
|
|
495
|
+
sage: D.random_element() # random
|
|
496
|
+
[2, 3, 4, 1]
|
|
497
|
+
sage: D = Derangements(['A','AT','CAT','CATS','CARTS','CARETS'])
|
|
498
|
+
sage: D.random_element() # random
|
|
499
|
+
['AT', 'CARTS', 'A', 'CAT', 'CARETS', 'CATS']
|
|
500
|
+
sage: D = Derangements('UNCOPYRIGHTABLE')
|
|
501
|
+
sage: D.random_element() # random
|
|
502
|
+
['C', 'U', 'I', 'H', 'O', 'G', 'N', 'B', 'E', 'L', 'A', 'R', 'P', 'Y', 'T']
|
|
503
|
+
sage: D = Derangements([1,1,1,1,2,2,2,2,3,3,3,3])
|
|
504
|
+
sage: D.random_element() # random
|
|
505
|
+
[3, 2, 2, 3, 1, 3, 1, 3, 2, 1, 1, 2]
|
|
506
|
+
sage: D = Derangements('ESSENCES')
|
|
507
|
+
sage: D.random_element() # random
|
|
508
|
+
['N', 'E', 'E', 'C', 'S', 'S', 'S', 'E']
|
|
509
|
+
sage: D = Derangements([1,1,2,2,2])
|
|
510
|
+
sage: D.random_element()
|
|
511
|
+
[]
|
|
512
|
+
|
|
513
|
+
TESTS:
|
|
514
|
+
|
|
515
|
+
Check that index error discovered in :issue:`29974` is fixed::
|
|
516
|
+
|
|
517
|
+
sage: D = Derangements([1,1,2,2])
|
|
518
|
+
sage: _ = [D.random_element() for _ in range(20)]
|
|
519
|
+
"""
|
|
520
|
+
if self.__multi:
|
|
521
|
+
L = list(self)
|
|
522
|
+
if len(L) == 0:
|
|
523
|
+
return self.element_class(self, [])
|
|
524
|
+
i = randrange(len(L))
|
|
525
|
+
return L[i]
|
|
526
|
+
temp = self._rand_der()
|
|
527
|
+
return self.element_class(self, [self._set[ii - 1] for ii in temp])
|