|
66 | 66 | from sage.misc.unknown import Unknown
|
67 | 67 | from sage.cpython.string import bytes_to_str
|
68 | 68 | from sage.modules.free_module_element import vector
|
| 69 | +from sage.combinat.T_sequences import T_sequences_smallcases |
69 | 70 |
|
70 | 71 |
|
71 | 72 | def normalise_hadamard(H):
|
@@ -732,7 +733,7 @@ def hadamard_matrix_cooper_wallis_construction(x1, x2, x3, x4, A, B, C, D, check
|
732 | 733 | before returing it.
|
733 | 734 |
|
734 | 735 | EXAMPLES::
|
735 |
| - |
| 736 | +
|
736 | 737 | sage: from sage.combinat.matrices.hadamard_matrix import hadamard_matrix_cooper_wallis_construction
|
737 | 738 | sage: from sage.combinat.T_sequences import T_sequences_smallcases
|
738 | 739 | sage: seqs = T_sequences_smallcases(19)
|
@@ -787,6 +788,83 @@ def hadamard_matrix_cooper_wallis_construction(x1, x2, x3, x4, A, B, C, D, check
|
787 | 788 | assert is_hadamard_matrix(H)
|
788 | 789 | return H
|
789 | 790 |
|
| 791 | +def hadamard_matrix_cooper_wallis_smallcases(n, check=True, existence=False): |
| 792 | + r""" |
| 793 | + Construct hadamard matrices using the Cooper-Wallis construction for some small values of `n`. |
| 794 | +
|
| 795 | + This functions uses the data from :func:`sage.combinat.T_sequences.T_sequences_smallcases` |
| 796 | + and :func:`williamson_type_quadruples_smallcases` |
| 797 | + to construct an hadamard matrix of order `n` using the Cooper-Wallis construction |
| 798 | + detailed at :func:`hadamard_matrix_cooper_wallis_construction`. |
| 799 | +
|
| 800 | + INPUT: |
| 801 | + |
| 802 | + - ``n`` -- integer, the order of the matrix to be constructed |
| 803 | +
|
| 804 | + - ``check`` -- bolean: if True (default), check the the matrix is an hadamard matrix before returning |
| 805 | +
|
| 806 | + - ``existence`` -- boolean (default False): if True, only check if matrix exists |
| 807 | +
|
| 808 | + OUTPUT: |
| 809 | +
|
| 810 | + If ``existence`` is false, returns the hadamard matrix of order `n`. It raises an error if no data |
| 811 | + is available to construct the matrix of the given order. |
| 812 | + If ``existence`` is true, returns a boolean representing whether the matrix can be constructed or not. |
| 813 | +
|
| 814 | + .. SEEALSO:: |
| 815 | +
|
| 816 | + :func:`hadamard_matrix_cooper_wallis_construction` |
| 817 | +
|
| 818 | + EXAMPLES: |
| 819 | +
|
| 820 | + By default The function returns the hadamard matrix :: |
| 821 | +
|
| 822 | + sage: from sage.combinat.matrices.hadamard_matrix import hadamard_matrix_cooper_wallis_smallcases |
| 823 | + sage: hadamard_matrix_cooper_wallis_smallcases(28) |
| 824 | + 28 x 28 dense matrix over Integer Ring... |
| 825 | +
|
| 826 | + If ``existence`` is set to True, the function returns a boolean :: |
| 827 | + |
| 828 | + sage: hadamard_matrix_cooper_wallis_smallcases(20, existence=True) |
| 829 | + True |
| 830 | +
|
| 831 | + TESTS:: |
| 832 | +
|
| 833 | + sage: from sage.combinat.matrices.hadamard_matrix import hadamard_matrix_cooper_wallis_smallcases, is_hadamard_matrix |
| 834 | + sage: is_hadamard_matrix(hadamard_matrix_cooper_wallis_smallcases(188)) |
| 835 | + True |
| 836 | + sage: hadamard_matrix_cooper_wallis_smallcases(64, existence=True) |
| 837 | + False |
| 838 | + sage: hadamard_matrix_cooper_wallis_smallcases(64) |
| 839 | + Traceback (most recent call last): |
| 840 | + ... |
| 841 | + ValueError: The Cooper-Wallis construction for hadamard matrices of order 64 is not yet implemented. |
| 842 | + sage: hadamard_matrix_cooper_wallis_smallcases(14) |
| 843 | + Traceback (most recent call last): |
| 844 | + ... |
| 845 | + AssertionError |
| 846 | + """ |
| 847 | + assert n%4 == 0 and n > 0 |
| 848 | + |
| 849 | + for T_seq_len in divisors(n//4): |
| 850 | + will_size = n//(4* T_seq_len) |
| 851 | + if T_sequences_smallcases(T_seq_len, existence=True) and williamson_type_quadruples_smallcases(will_size, existence=True): |
| 852 | + if existence: |
| 853 | + return True |
| 854 | + |
| 855 | + e1, e2, e3, e4 = T_sequences_smallcases(T_seq_len, check=False) |
| 856 | + will_matrices = williamson_type_quadruples_smallcases(will_size) |
| 857 | + A, B, C, D = map(matrix.circulant, will_matrices) |
| 858 | + M = hadamard_matrix_cooper_wallis_construction(e1, e2, e3, e4, A, B, C, D, check=False) |
| 859 | + |
| 860 | + if check: |
| 861 | + assert is_hadamard_matrix(M) |
| 862 | + return M |
| 863 | + |
| 864 | + if existence: |
| 865 | + return False |
| 866 | + raise ValueError("The Cooper-Wallis construction for hadamard matrices of order %s is not yet implemented." % n) |
| 867 | + |
790 | 868 | def _get_baumert_hall_units(n, existence=False):
|
791 | 869 | r"""
|
792 | 870 | Construct Baumert-Hall units of size n from available 4-symbol delta codes.
|
|
0 commit comments