Set the default algebraic rules for the operations defined in this
    module

def _algebraic_rules_circuit():
    """Set the default algebraic rules for the operations defined in this
    module"""
    A_CPermutation = wc("A", head=CPermutation)
    B_CPermutation = wc("B", head=CPermutation)
    C_CPermutation = wc("C", head=CPermutation)
    D_CPermutation = wc("D", head=CPermutation)

    A_Concatenation = wc("A", head=Concatenation)
    B_Concatenation = wc("B", head=Concatenation)

    A_SeriesProduct = wc("A", head=SeriesProduct)

    A_Circuit = wc("A", head=Circuit)
    B_Circuit = wc("B", head=Circuit)
    C_Circuit = wc("C", head=Circuit)

    A__Circuit = wc("A__", head=Circuit)
    B__Circuit = wc("B__", head=Circuit)
    C__Circuit = wc("C__", head=Circuit)

    A_SLH = wc("A", head=SLH)
    B_SLH = wc("B", head=SLH)

    j_int = wc("j", head=int)
    k_int = wc("k", head=int)

    SeriesProduct._binary_rules.update(check_rules_dict([
        ('R001', (
            pattern_head(A_CPermutation, B_CPermutation),
            lambda A, B: A.series_with_permutation(B))),
        ('R002', (
            pattern_head(A_SLH, B_SLH),
            lambda A, B: A.series_with_slh(B))),
        ('R003', (
            pattern_head(A_Circuit, B_Circuit),
            lambda A, B: _tensor_decompose_series(A, B))),
        ('R004', (
            pattern_head(A_CPermutation, B_Circuit),
            lambda A, B: _factor_permutation_for_blocks(A, B))),
        ('R005', (
            pattern_head(A_Circuit, pattern(SeriesInverse, A_Circuit)),
            lambda A: cid(A.cdim))),
        ('R006', (
            pattern_head(pattern(SeriesInverse, A_Circuit), A_Circuit),
            lambda A: cid(A.cdim))),
    ]))

    Concatenation._binary_rules.update(check_rules_dict([
        ('R001', (
            pattern_head(A_SLH, B_SLH),
            lambda A, B: A.concatenate_slh(B))),
        ('R002', (
            pattern_head(A_CPermutation, B_CPermutation),
            lambda A, B: CPermutation.create(
                concatenate_permutations(A.permutation, B.permutation)))),
        ('R003', (
            pattern_head(A_CPermutation, CIdentity),
            lambda A: CPermutation.create(
                concatenate_permutations(A.permutation, (0,))))),
        ('R004', (
            pattern_head(CIdentity, B_CPermutation),
            lambda B: CPermutation.create(
                concatenate_permutations((0,), B.permutation)))),
        ('R005', (
            pattern_head(
                pattern(SeriesProduct, A__Circuit, B_CPermutation),
                pattern(SeriesProduct, C__Circuit, D_CPermutation)),
            lambda A, B, C, D: (
                (SeriesProduct.create(*A) + SeriesProduct.create(*C)) <<
                (B + D)))),
        ('R006', (
            pattern_head(
                pattern(SeriesProduct, A__Circuit, B_CPermutation), C_Circuit),
            lambda A, B, C: (
                (SeriesProduct.create(*A) + C) << (B + cid(C.cdim))))),
        ('R007', (
            pattern_head(
                A_Circuit, pattern(SeriesProduct, B__Circuit, C_CPermutation)),
            lambda A, B, C: ((A + SeriesProduct.create(*B)) <<
                             (cid(A.cdim) + C)))),
    ]))

    Feedback._rules.update(check_rules_dict([
        ('R001', (
            pattern_head(A_SeriesProduct, out_port=j_int, in_port=k_int),
            lambda A, j, k: _series_feedback(A, out_port=j, in_port=k))),
        ('R002', (
            pattern_head(
                pattern(SeriesProduct, A_CPermutation, B__Circuit),
                out_port=j_int, in_port=k_int),
            lambda A, B, j, k: _pull_out_perm_lhs(A, B, j, k))),
        ('R003', (
            pattern_head(
                pattern(SeriesProduct, A_Concatenation, B__Circuit),
                out_port=j_int, in_port=k_int),
            lambda A, B, j, k: _pull_out_unaffected_blocks_lhs(A, B, j, k))),
        ('R004', (
            pattern_head(
                pattern(SeriesProduct, A__Circuit, B_CPermutation),
                out_port=j_int, in_port=k_int),
            lambda A, B, j, k: _pull_out_perm_rhs(A, B, j, k))),
        ('R005', (
            pattern_head(
                pattern(SeriesProduct, A__Circuit, B_Concatenation),
                out_port=j_int, in_port=k_int),
            lambda A, B, j, k: _pull_out_unaffected_blocks_rhs(A, B, j, k))),
    ]))