class CommutativeMatcher65527(CommutativeMatcher):
    _instance = None
    patterns = {
    0: (0, Multiset({0: 1}), [
      (VariableWithCount('i2.2.2.0', 1, 1, S(0)), Add)
]),
    1: (1, Multiset({1: 1}), [
      (VariableWithCount('i2.3.0', 1, 1, S(0)), Add)
]),
    2: (2, Multiset({2: 1}), [
      (VariableWithCount('i2.2.1.2.0', 1, 1, S(0)), Add)
]),
    3: (3, Multiset({3: 1}), [
      (VariableWithCount('i2.2.3.0', 1, 1, S(0)), Add)
]),
    4: (4, Multiset({4: 1}), [
      (VariableWithCount('i2.1.1.3.0', 1, 1, S(0)), Add)
]),
    5: (5, Multiset({5: 1}), [
      (VariableWithCount('i2.2.1.3.0', 1, 1, S(0)), Add)
]),
    6: (6, Multiset({6: 1}), [
      (VariableWithCount('i2.2.2.3.0', 1, 1, S(0)), Add)
])
}
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher65527._instance is None:
            CommutativeMatcher65527._instance = CommutativeMatcher65527()
        return CommutativeMatcher65527._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 65526
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 65528
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 65529
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 65691
            if len(subjects) >= 1:
                tmp5 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.0', tmp5)
                except ValueError:
                    pass
                else:
                    pass
                    # State 65692
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst2
                subjects.appendleft(tmp5)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 65829
            if len(subjects) >= 1:
                tmp8 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.1.0', tmp8)
                except ValueError:
                    pass
                else:
                    pass
                    # State 65830
                    if len(subjects) == 0:
                        pass
                        # 2: x*d
                        yield 2, subst2
                subjects.appendleft(tmp8)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 66090
            if len(subjects) >= 1:
                tmp11 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.3.1.0', tmp11)
                except ValueError:
                    pass
                else:
                    pass
                    # State 66091
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst2
                subjects.appendleft(tmp11)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.1.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 90902
            if len(subjects) >= 1:
                tmp14 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.1.1.3.1.0', tmp14)
                except ValueError:
                    pass
                else:
                    pass
                    # State 90903
                    if len(subjects) == 0:
                        pass
                        # 4: x*d
                        yield 4, subst2
                subjects.appendleft(tmp14)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 91564
            if len(subjects) >= 1:
                tmp17 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.3.1.0', tmp17)
                except ValueError:
                    pass
                else:
                    pass
                    # State 91565
                    if len(subjects) == 0:
                        pass
                        # 5: x*f
                        yield 5, subst2
                subjects.appendleft(tmp17)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 94148
            if len(subjects) >= 1:
                tmp20 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.3.1.0', tmp20)
                except ValueError:
                    pass
                else:
                    pass
                    # State 94149
                    if len(subjects) == 0:
                        pass
                        # 6: x*f
                        yield 6, subst2
                subjects.appendleft(tmp20)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp22 = subjects.popleft()
            associative1 = tmp22
            associative_type1 = type(tmp22)
            subjects23 = deque(tmp22._args)
            matcher = CommutativeMatcher65531.get()
            tmp24 = subjects23
            subjects23 = []
            for s in tmp24:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp24, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 65532
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 65693
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 65831
                    if len(subjects) == 0:
                        pass
                        # 2: x*d
                        yield 2, subst1
                if pattern_index == 3:
                    pass
                    # State 66092
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst1
                if pattern_index == 4:
                    pass
                    # State 90904
                    if len(subjects) == 0:
                        pass
                        # 4: x*d
                        yield 4, subst1
                if pattern_index == 5:
                    pass
                    # State 91566
                    if len(subjects) == 0:
                        pass
                        # 5: x*f
                        yield 5, subst1
                if pattern_index == 6:
                    pass
                    # State 94150
                    if len(subjects) == 0:
                        pass
                        # 6: x*f
                        yield 6, subst1
            subjects.appendleft(tmp22)
        return
        yield
class CommutativeMatcher102344(CommutativeMatcher):
    _instance = None
    patterns = {
    0: (0, Multiset({0: 1}), [
      (VariableWithCount('i2.2.2.0', 1, 1, None), Mul),
      (VariableWithCount('i2.2.2.0_1', 1, 1, S(1)), Mul)
])
}
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher102344._instance is None:
            CommutativeMatcher102344._instance = CommutativeMatcher102344()
        return CommutativeMatcher102344._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 102343
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.1.0', S(0))
        except ValueError:
            pass
        else:
            pass
            # State 102345
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.2.2.1.1.0_1', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 102346
                if len(subjects) >= 1:
                    tmp3 = subjects.popleft()
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.2.2.1.1.0', tmp3)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 102347
                        if len(subjects) == 0:
                            pass
                            # 0: c + x*d /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f4) and (cons_f5)
                            yield 0, subst3
                    subjects.appendleft(tmp3)
            if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                tmp5 = subjects.popleft()
                associative1 = tmp5
                associative_type1 = type(tmp5)
                subjects6 = deque(tmp5._args)
                matcher = CommutativeMatcher102349.get()
                tmp7 = subjects6
                subjects6 = []
                for s in tmp7:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp7, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 102350
                        if len(subjects) == 0:
                            pass
                            # 0: c + x*d /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f4) and (cons_f5)
                            yield 0, subst2
                subjects.appendleft(tmp5)
        if len(subjects) >= 1 and isinstance(subjects[0], Add):
            tmp8 = subjects.popleft()
            associative1 = tmp8
            associative_type1 = type(tmp8)
            subjects9 = deque(tmp8._args)
            matcher = CommutativeMatcher102352.get()
            tmp10 = subjects9
            subjects9 = []
            for s in tmp10:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp10, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 102358
                    if len(subjects) == 0:
                        pass
                        # 0: c + x*d /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f4) and (cons_f5)
                        yield 0, subst1
            subjects.appendleft(tmp8)
        return
        yield
class CommutativeMatcher22434(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                 None), Mul),
                              (VariableWithCount('i2.2.1.2.2.2.1.0_1', 1, 1,
                                                 S(1)), Mul)]),
        1: (1, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher22434._instance is None:
            CommutativeMatcher22434._instance = CommutativeMatcher22434()
        return CommutativeMatcher22434._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 22433
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 33924
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.2.2.2.1.1', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 33925
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2.1.2', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 33926
                            if len(subjects2) == 0:
                                pass
                                # State 33927
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**m
                                    yield 0, subst2
                        subjects2.appendleft(tmp5)
                subjects2.appendleft(tmp3)
            subjects.appendleft(tmp1)
        return
        yield
class CommutativeMatcher73095(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i3.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i3.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i3.1.2.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher73095._instance is None:
            CommutativeMatcher73095._instance = CommutativeMatcher73095()
        return CommutativeMatcher73095._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 73094
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i3.1.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 73096
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp2 = subjects.popleft()
                subjects3 = deque(tmp2._args)
                # State 73097
                if len(subjects3) >= 1:
                    tmp4 = subjects3.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i3.1.2.1.1', tmp4)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 73098
                        if len(subjects3) >= 1:
                            tmp6 = subjects3.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i3.1.2.1.2', tmp6)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 73099
                                if len(subjects3) == 0:
                                    pass
                                    # State 73100
                                    if len(subjects) == 0:
                                        pass
                                        # 0: d*x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f198)
                                        yield 0, subst3
                                        # 1: d*x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f491)
                                        yield 1, subst3
                                        # 2: d*x**n /; (cons_f29) and (cons_f4) and (cons_f70) and (cons_f71)
                                        yield 2, subst3
                            subjects3.appendleft(tmp6)
                    subjects3.appendleft(tmp4)
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp8 = subjects.popleft()
            associative1 = tmp8
            associative_type1 = type(tmp8)
            subjects9 = deque(tmp8._args)
            matcher = CommutativeMatcher73102.get()
            tmp10 = subjects9
            subjects9 = []
            for s in tmp10:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp10, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 73107
                    if len(subjects) == 0:
                        pass
                        # 0: d*x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f198)
                        yield 0, subst1
                        # 1: d*x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f29) and (cons_f491)
                        yield 1, subst1
                        # 2: d*x**n /; (cons_f29) and (cons_f4) and (cons_f70) and (cons_f71)
                        yield 2, subst1
            subjects.appendleft(tmp8)
        return
        yield
Example #5
0
def ac_operand_lists(t1: Operation, t2: Operation)\
                    -> List[List[Tuple[Expression, Expression]]]:
    """Find all the sets of operand unification problems
    we can get from t1 and t2"""
    # Remove common operations
    t1_op_set = Multiset(t1.operands)
    t2_op_set = Multiset(t2.operands)
    common_ops = t1_op_set & t2_op_set
    t1_op_set -= common_ops
    t2_op_set -= common_ops

    t1_duplicate_vars = any(
        isinstance(e, Wildcard) and n > 1 for e, n in t1_op_set.items())
    t2_duplicate_vars = any(
        isinstance(e, Wildcard) and n > 1 for e, n in t2_op_set.items())
    if t1_duplicate_vars and t2_duplicate_vars:
        raise (NotImplementedError(
            "Possible nontermination on this algo, dispatch slowward"))  # noqa
    elif t1_duplicate_vars or t2_duplicate_vars:
        print("Redundant solutions really gosh darn likely")

    ret = []

    op_function = get_head(t1)

    t1_ops = to_ac_operands(t1_op_set)
    t2_ops = to_ac_operands(t2_op_set)

    all_t1_ops = t1_ops.consts + t1_ops.terms + t1_ops.vars
    all_t2_ops = t2_ops.consts + t2_ops.terms + t2_ops.vars

    t1_n_consts = len(t1_ops.consts)
    t2_n_consts = len(t2_ops.consts)
    t1_n_terms = len(t1_ops.terms)
    t2_n_terms = len(t2_ops.terms)
    t1_n_vars = len(t1_ops.vars)
    t2_n_vars = len(t2_ops.vars)
    t1_n_ops = len(all_t1_ops)
    t2_n_ops = len(all_t2_ops)

    t1_var_start = t1_n_ops - t1_n_vars
    t2_var_start = t2_n_ops - t2_n_vars

    t1_equal_consts = [
        idx for idx in range(0, t1_n_consts - 1)
        if t1_ops.consts[idx] == t1_ops.consts[idx + 1]
    ]
    t2_equal_consts = [
        idx for idx in range(0, t2_n_consts - 1)
        if t2_ops.consts[idx] == t2_ops.consts[idx + 1]
    ]
    t1_equal_terms = [
        idx for idx in range(0, t1_n_terms - 1)
        if t1_ops.terms[idx] == t1_ops.terms[idx + 1]
    ]
    t2_equal_terms = [
        idx for idx in range(0, t2_n_terms - 1)
        if t2_ops.terms[idx] == t2_ops.terms[idx + 1]
    ]
    t1_equal_vars = [
        idx for idx in range(0, t1_n_vars - 1)
        if t1_ops.vars[idx] == t1_ops.vars[idx + 1]
    ]
    t2_equal_vars = [
        idx for idx in range(0, t2_n_vars - 1)
        if t2_ops.vars[idx] == t2_ops.vars[idx + 1]
    ]

    for const_rows_true_idx in ints_walking_range(t2_var_start, t2_n_ops,
                                                  t1_n_consts):
        # Drop clear violations of the repeat property here
        if some_pairs_sorted(const_rows_true_idx, t1_equal_consts):
            continue

        for const_cols_true_idx in ints_walking_range(t1_var_start, t1_n_ops,
                                                      t2_n_consts):
            if some_pairs_sorted(const_cols_true_idx, t2_equal_consts):
                continue

            for term_rows_true_idx in ints_walking_range(
                    t2_n_consts, t2_n_ops, t1_n_terms):
                if some_pairs_sorted(term_rows_true_idx, t1_equal_terms):
                    continue

                for term_cols_true_idx in ints_walking_range(
                        t1_n_consts, t1_n_ops, t2_n_terms):
                    if some_pairs_sorted(term_cols_true_idx, t2_equal_terms):
                        continue

                    # Term mismatch
                    if any(row_nr < t1_var_start and (term_rows_true_idx[
                            row_nr - t1_n_consts] != rel_col_nr + t2_n_consts)
                           for rel_col_nr, row_nr in enumerate(
                               term_cols_true_idx)):
                        continue

                    if any(col_nr < t2_var_start and (term_cols_true_idx[
                            col_nr - t2_n_consts] != rel_row_nr + t1_n_consts)
                           for rel_row_nr, col_nr in enumerate(
                               term_rows_true_idx)):
                        continue

                    set_cols = (set(const_rows_true_idx)
                                | set(term_rows_true_idx))
                    set_rows = (set(const_cols_true_idx)
                                | set(term_cols_true_idx))

                    for var_mat in all_boolean_matrices(t1_n_vars, t2_n_vars):
                        # Filter out failures of unification
                        if any(row_sum == 0 and raw_idx[0] +
                               t1_var_start not in set_rows
                               for raw_idx, row_sum in np.ndenumerate(
                                   np.sum(var_mat, axis=1))):
                            continue

                        if any(col_sum == 0 and raw_idx[0] +
                               t2_var_start not in set_cols
                               for raw_idx, col_sum in np.ndenumerate(
                                   np.sum(var_mat, axis=0))):
                            continue

                        if any(
                                compare_equal_variable_vectors(
                                    i, var_mat[i, :], var_mat[i + 1, :],
                                    const_cols_true_idx, term_cols_true_idx)
                                for i in t1_equal_vars):
                            continue
                        if any(
                                compare_equal_variable_vectors(
                                    i, var_mat[:, i], var_mat[:, i + 1],
                                    const_rows_true_idx, term_rows_true_idx)
                                for i in t2_equal_vars):
                            continue

                        operand_tuples = []
                        t1_var_unifiers = defaultdict(
                            list
                        )  # type: DefaultDict[Expression, List[Expression]] # noqa: E501
                        t2_var_unifiers = defaultdict(
                            list
                        )  # type: DefaultDict[Expression, List[Expression]] # noqa: E501
                        for const, var_idx in zip(t1_ops.consts,
                                                  const_rows_true_idx):
                            var = all_t2_ops[var_idx]
                            t2_var_unifiers[var].append(const)
                        for const, var_idx in zip(t2_ops.consts,
                                                  const_cols_true_idx):
                            var = all_t1_ops[var_idx]
                            t1_var_unifiers[var].append(const)
                        for term, var_idx in zip(t1_ops.terms,
                                                 term_rows_true_idx):
                            expr = all_t2_ops[var_idx]
                            if isinstance(expr, Wildcard):
                                t2_var_unifiers[expr].append(term)
                            else:
                                operand_tuples.append((term, expr))
                        for term, var_idx in zip(t2_ops.terms,
                                                 term_cols_true_idx):
                            expr = all_t1_ops[var_idx]
                            if isinstance(expr, Wildcard):
                                t1_var_unifiers[expr].append(term)
                            # Else case handled above

                        for idxs in np.transpose(np.nonzero(var_mat)):
                            row = t1_ops.vars[idxs[0]]
                            col = t2_ops.vars[idxs[1]]
                            t1_var_unifiers[row].append(col)
                            t2_var_unifiers[col].append(row)
                        for d in [t1_var_unifiers, t2_var_unifiers]:
                            for var, ops in d.items():
                                if len(ops) == 1:
                                    operand_tuples.append((var, ops[0]))
                                else:
                                    operand_tuples.append(
                                        (var, op_function(*ops)))

                        ret.append(operand_tuples)
    return ret
Example #6
0
class CommutativeMatcher106130(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i5.1.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher106130._instance is None:
            CommutativeMatcher106130._instance = CommutativeMatcher106130()
        return CommutativeMatcher106130._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 106129
        if len(subjects) >= 1 and isinstance(subjects[0], log):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 106131
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i5.1.2.0', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 106132
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i5.1.2.2', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 106133
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i5.1.2.1', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 106134
                            if len(subjects2) == 0:
                                pass
                                # State 106135
                                if len(subjects) == 0:
                                    pass
                                    # 0: log(c*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1713)
                                    yield 0, subst3
                        subjects2.appendleft(tmp5)
                if len(subjects2) >= 1 and isinstance(subjects2[0], Pow):
                    tmp7 = subjects2.popleft()
                    subjects8 = deque(tmp7._args)
                    # State 106136
                    if len(subjects8) >= 1:
                        tmp9 = subjects8.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i5.1.2.1', tmp9)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 106137
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i5.1.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 106138
                                if len(subjects8) == 0:
                                    pass
                                    # State 106139
                                    if len(subjects2) == 0:
                                        pass
                                        # State 106140
                                        if len(subjects) == 0:
                                            pass
                                            # 0: log(c*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1713)
                                            yield 0, subst3
                            if len(subjects8) >= 1:
                                tmp12 = subjects8.popleft()
                                subst3 = Substitution(subst2)
                                try:
                                    subst3.try_add_variable('i5.1.2.2', tmp12)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 106138
                                    if len(subjects8) == 0:
                                        pass
                                        # State 106139
                                        if len(subjects2) == 0:
                                            pass
                                            # State 106140
                                            if len(subjects) == 0:
                                                pass
                                                # 0: log(c*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1713)
                                                yield 0, subst3
                                subjects8.appendleft(tmp12)
                        subjects8.appendleft(tmp9)
                    subjects2.appendleft(tmp7)
            if len(subjects2) >= 1 and isinstance(subjects2[0], Mul):
                tmp14 = subjects2.popleft()
                associative1 = tmp14
                associative_type1 = type(tmp14)
                subjects15 = deque(tmp14._args)
                matcher = CommutativeMatcher106142.get()
                tmp16 = subjects15
                subjects15 = []
                for s in tmp16:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp16, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 106149
                        if len(subjects2) == 0:
                            pass
                            # State 106150
                            if len(subjects) == 0:
                                pass
                                # 0: log(c*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1713)
                                yield 0, subst1
                subjects2.appendleft(tmp14)
            subjects.appendleft(tmp1)
        return
        yield
class CommutativeMatcher99759(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.1.1.3.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher99759._instance is None:
            CommutativeMatcher99759._instance = CommutativeMatcher99759()
        return CommutativeMatcher99759._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 99758
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.1.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 99760
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.1.1.3.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 99761
                    if len(subjects) == 0:
                        pass
                        # 0: x*d
                        yield 0, subst2
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp4 = subjects.popleft()
            associative1 = tmp4
            associative_type1 = type(tmp4)
            subjects5 = deque(tmp4._args)
            matcher = CommutativeMatcher99763.get()
            tmp6 = subjects5
            subjects5 = []
            for s in tmp6:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp6, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 99764
                    if len(subjects) == 0:
                        pass
                        # 0: x*d
                        yield 0, subst1
            subjects.appendleft(tmp4)
        return
        yield
class CommutativeMatcher23213(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        3: (3, Multiset({3: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        4: (4, Multiset({4: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        5: (5, Multiset({5: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)]),
        6: (6, Multiset({6: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher23213._instance is None:
            CommutativeMatcher23213._instance = CommutativeMatcher23213()
        return CommutativeMatcher23213._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 23212
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 23214
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.2.1.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 23215
                subst3 = Substitution(subst2)
                try:
                    subst3.try_add_variable('i2.2.1.2.2.2.1.0_1', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 23216
                    if len(subjects) >= 1:
                        tmp4 = subjects.popleft()
                        subst4 = Substitution(subst3)
                        try:
                            subst4.try_add_variable('i2.2.1.2.2.2.1.0', tmp4)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 23217
                            if len(subjects) == 0:
                                pass
                                # 0: (e + x*f)**p
                                yield 0, subst4
                        subjects.appendleft(tmp4)
                subst3 = Substitution(subst2)
                try:
                    subst3.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 34520
                    if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                        tmp7 = subjects.popleft()
                        subjects8 = deque(tmp7._args)
                        # State 34521
                        if len(subjects8) >= 1:
                            tmp9 = subjects8.popleft()
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable(
                                    'i2.2.1.2.2.2.1.1', tmp9)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 34522
                                if len(subjects8) >= 1:
                                    tmp11 = subjects8.popleft()
                                    subst5 = Substitution(subst4)
                                    try:
                                        subst5.try_add_variable(
                                            'i2.2.1.2.2.2.1.2', tmp11)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 34523
                                        if len(subjects8) == 0:
                                            pass
                                            # State 34524
                                            if len(subjects) == 0:
                                                pass
                                                # 4: (e + f*x**m)**p
                                                yield 4, subst5
                                    subjects8.appendleft(tmp11)
                            subjects8.appendleft(tmp9)
                        subjects.appendleft(tmp7)
                if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                    tmp13 = subjects.popleft()
                    associative1 = tmp13
                    associative_type1 = type(tmp13)
                    subjects14 = deque(tmp13._args)
                    matcher = CommutativeMatcher23219.get()
                    tmp15 = subjects14
                    subjects14 = []
                    for s in tmp15:
                        matcher.add_subject(s)
                    for pattern_index, subst3 in matcher.match(tmp15, subst2):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 23220
                            if len(subjects) == 0:
                                pass
                                # 0: (e + x*f)**p
                                yield 0, subst3
                        if pattern_index == 1:
                            pass
                            # State 34529
                            if len(subjects) == 0:
                                pass
                                # 4: (e + f*x**m)**p
                                yield 4, subst3
                    subjects.appendleft(tmp13)
            if len(subjects) >= 1:
                tmp16 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.1', tmp16)
                except ValueError:
                    pass
                else:
                    pass
                    # State 45531
                    if len(subjects) == 0:
                        pass
                        # 6: v**p
                        yield 6, subst2
                subjects.appendleft(tmp16)
            if len(subjects) >= 1 and isinstance(subjects[0], Add):
                tmp18 = subjects.popleft()
                associative1 = tmp18
                associative_type1 = type(tmp18)
                subjects19 = deque(tmp18._args)
                matcher = CommutativeMatcher23222.get()
                tmp20 = subjects19
                subjects19 = []
                for s in tmp20:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp20, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 23228
                        if len(subjects) == 0:
                            pass
                            # 0: (e + x*f)**p
                            yield 0, subst2
                    if pattern_index == 1:
                        pass
                        # State 28930
                        if len(subjects) == 0:
                            pass
                            # 2: (e + f*x**m)**p
                            yield 2, subst2
                    if pattern_index == 2:
                        pass
                        # State 34530
                        if len(subjects) == 0:
                            pass
                            # 4: (e + f*x**m)**p
                            yield 4, subst2
                    if pattern_index == 3:
                        pass
                        # State 44004
                        if len(subjects) == 0:
                            pass
                            # 5: (e + f*x + g*x**2)**p
                            yield 5, subst2
                subjects.appendleft(tmp18)
            if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                tmp21 = subjects.popleft()
                associative1 = tmp21
                associative_type1 = type(tmp21)
                subjects22 = deque(tmp21._args)
                matcher = CommutativeMatcher31369.get()
                tmp23 = subjects22
                subjects22 = []
                for s in tmp23:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp23, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 31393
                        if len(subjects) == 0:
                            pass
                            # 3: (x**m*(f + e*x**r))**p
                            yield 3, subst2
                subjects.appendleft(tmp21)
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp24 = subjects.popleft()
            subjects25 = deque(tmp24._args)
            # State 23229
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.2.1.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 23230
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.2.1.0_1', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 23231
                    if len(subjects25) >= 1:
                        tmp28 = subjects25.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.2.1.2.2.2.1.0', tmp28)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 23232
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.2.1.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 23233
                                if len(subjects25) == 0:
                                    pass
                                    # State 23234
                                    if len(subjects) == 0:
                                        pass
                                        # 0: (e + x*f)**p
                                        yield 0, subst4
                            if len(subjects25) >= 1:
                                tmp31 = subjects25.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable(
                                        'i2.2.1.2.2.2', tmp31)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 23233
                                    if len(subjects25) == 0:
                                        pass
                                        # State 23234
                                        if len(subjects) == 0:
                                            pass
                                            # 0: (e + x*f)**p
                                            yield 0, subst4
                                subjects25.appendleft(tmp31)
                        subjects25.appendleft(tmp28)
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 34531
                    if len(subjects25) >= 1 and isinstance(subjects25[0], Pow):
                        tmp34 = subjects25.popleft()
                        subjects35 = deque(tmp34._args)
                        # State 34532
                        if len(subjects35) >= 1:
                            tmp36 = subjects35.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable(
                                    'i2.2.1.2.2.2.1.1', tmp36)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 34533
                                if len(subjects35) >= 1:
                                    tmp38 = subjects35.popleft()
                                    subst4 = Substitution(subst3)
                                    try:
                                        subst4.try_add_variable(
                                            'i2.2.1.2.2.2.1.2', tmp38)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 34534
                                        if len(subjects35) == 0:
                                            pass
                                            # State 34535
                                            subst5 = Substitution(subst4)
                                            try:
                                                subst5.try_add_variable(
                                                    'i2.2.1.2.2.2', 1)
                                            except ValueError:
                                                pass
                                            else:
                                                pass
                                                # State 34536
                                                if len(subjects25) == 0:
                                                    pass
                                                    # State 34537
                                                    if len(subjects) == 0:
                                                        pass
                                                        # 4: (e + f*x**m)**p
                                                        yield 4, subst5
                                            if len(subjects25) >= 1:
                                                tmp41 = subjects25.popleft()
                                                subst5 = Substitution(subst4)
                                                try:
                                                    subst5.try_add_variable(
                                                        'i2.2.1.2.2.2', tmp41)
                                                except ValueError:
                                                    pass
                                                else:
                                                    pass
                                                    # State 34536
                                                    if len(subjects25) == 0:
                                                        pass
                                                        # State 34537
                                                        if len(subjects) == 0:
                                                            pass
                                                            # 4: (e + f*x**m)**p
                                                            yield 4, subst5
                                                subjects25.appendleft(tmp41)
                                    subjects35.appendleft(tmp38)
                            subjects35.appendleft(tmp36)
                        subjects25.appendleft(tmp34)
                if len(subjects25) >= 1 and isinstance(subjects25[0], Mul):
                    tmp43 = subjects25.popleft()
                    associative1 = tmp43
                    associative_type1 = type(tmp43)
                    subjects44 = deque(tmp43._args)
                    matcher = CommutativeMatcher23236.get()
                    tmp45 = subjects44
                    subjects44 = []
                    for s in tmp45:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp45, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 23237
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 23238
                                if len(subjects25) == 0:
                                    pass
                                    # State 23239
                                    if len(subjects) == 0:
                                        pass
                                        # 0: (e + x*f)**p
                                        yield 0, subst3
                            if len(subjects25) >= 1:
                                tmp47 = []
                                tmp47.append(subjects25.popleft())
                                while True:
                                    if len(tmp47) > 1:
                                        tmp48 = create_operation_expression(
                                            associative1, tmp47)
                                    elif len(tmp47) == 1:
                                        tmp48 = tmp47[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i2.2.1.2.2.2', tmp48)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 23238
                                        if len(subjects25) == 0:
                                            pass
                                            # State 23239
                                            if len(subjects) == 0:
                                                pass
                                                # 0: (e + x*f)**p
                                                yield 0, subst3
                                    if len(subjects25) == 0:
                                        break
                                    tmp47.append(subjects25.popleft())
                                subjects25.extendleft(reversed(tmp47))
                        if pattern_index == 1:
                            pass
                            # State 34542
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 34543
                                if len(subjects25) == 0:
                                    pass
                                    # State 34544
                                    if len(subjects) == 0:
                                        pass
                                        # 4: (e + f*x**m)**p
                                        yield 4, subst3
                            if len(subjects25) >= 1:
                                tmp51 = []
                                tmp51.append(subjects25.popleft())
                                while True:
                                    if len(tmp51) > 1:
                                        tmp52 = create_operation_expression(
                                            associative1, tmp51)
                                    elif len(tmp51) == 1:
                                        tmp52 = tmp51[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i2.2.1.2.2.2', tmp52)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 34543
                                        if len(subjects25) == 0:
                                            pass
                                            # State 34544
                                            if len(subjects) == 0:
                                                pass
                                                # 4: (e + f*x**m)**p
                                                yield 4, subst3
                                    if len(subjects25) == 0:
                                        break
                                    tmp51.append(subjects25.popleft())
                                subjects25.extendleft(reversed(tmp51))
                    subjects25.appendleft(tmp43)
            if len(subjects25) >= 1:
                tmp54 = subjects25.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.2.2.1', tmp54)
                except ValueError:
                    pass
                else:
                    pass
                    # State 25607
                    if len(subjects25) >= 1:
                        tmp56 = subjects25.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', tmp56)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 25608
                            if len(subjects25) == 0:
                                pass
                                # State 25609
                                if len(subjects) == 0:
                                    pass
                                    # 1: v**p
                                    yield 1, subst2
                        subjects25.appendleft(tmp56)
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2.2.2', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 45532
                        if len(subjects25) == 0:
                            pass
                            # State 45533
                            if len(subjects) == 0:
                                pass
                                # 6: v**p
                                yield 6, subst2
                    if len(subjects25) >= 1:
                        tmp59 = subjects25.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', tmp59)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 45532
                            if len(subjects25) == 0:
                                pass
                                # State 45533
                                if len(subjects) == 0:
                                    pass
                                    # 6: v**p
                                    yield 6, subst2
                        subjects25.appendleft(tmp59)
                subjects25.appendleft(tmp54)
            if len(subjects25) >= 1 and isinstance(subjects25[0], Add):
                tmp61 = subjects25.popleft()
                associative1 = tmp61
                associative_type1 = type(tmp61)
                subjects62 = deque(tmp61._args)
                matcher = CommutativeMatcher23241.get()
                tmp63 = subjects62
                subjects62 = []
                for s in tmp63:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp63, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 23247
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 23248
                            if len(subjects25) == 0:
                                pass
                                # State 23249
                                if len(subjects) == 0:
                                    pass
                                    # 0: (e + x*f)**p
                                    yield 0, subst2
                        if len(subjects25) >= 1:
                            tmp65 = []
                            tmp65.append(subjects25.popleft())
                            while True:
                                if len(tmp65) > 1:
                                    tmp66 = create_operation_expression(
                                        associative1, tmp65)
                                elif len(tmp65) == 1:
                                    tmp66 = tmp65[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp66)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 23248
                                    if len(subjects25) == 0:
                                        pass
                                        # State 23249
                                        if len(subjects) == 0:
                                            pass
                                            # 0: (e + x*f)**p
                                            yield 0, subst2
                                if len(subjects25) == 0:
                                    break
                                tmp65.append(subjects25.popleft())
                            subjects25.extendleft(reversed(tmp65))
                    if pattern_index == 1:
                        pass
                        # State 28941
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 28942
                            if len(subjects25) == 0:
                                pass
                                # State 28943
                                if len(subjects) == 0:
                                    pass
                                    # 2: (e + f*x**m)**p
                                    yield 2, subst2
                        if len(subjects25) >= 1:
                            tmp69 = []
                            tmp69.append(subjects25.popleft())
                            while True:
                                if len(tmp69) > 1:
                                    tmp70 = create_operation_expression(
                                        associative1, tmp69)
                                elif len(tmp69) == 1:
                                    tmp70 = tmp69[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp70)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 28942
                                    if len(subjects25) == 0:
                                        pass
                                        # State 28943
                                        if len(subjects) == 0:
                                            pass
                                            # 2: (e + f*x**m)**p
                                            yield 2, subst2
                                if len(subjects25) == 0:
                                    break
                                tmp69.append(subjects25.popleft())
                            subjects25.extendleft(reversed(tmp69))
                    if pattern_index == 2:
                        pass
                        # State 34545
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 34546
                            if len(subjects25) == 0:
                                pass
                                # State 34547
                                if len(subjects) == 0:
                                    pass
                                    # 4: (e + f*x**m)**p
                                    yield 4, subst2
                        if len(subjects25) >= 1:
                            tmp73 = []
                            tmp73.append(subjects25.popleft())
                            while True:
                                if len(tmp73) > 1:
                                    tmp74 = create_operation_expression(
                                        associative1, tmp73)
                                elif len(tmp73) == 1:
                                    tmp74 = tmp73[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp74)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 34546
                                    if len(subjects25) == 0:
                                        pass
                                        # State 34547
                                        if len(subjects) == 0:
                                            pass
                                            # 4: (e + f*x**m)**p
                                            yield 4, subst2
                                if len(subjects25) == 0:
                                    break
                                tmp73.append(subjects25.popleft())
                            subjects25.extendleft(reversed(tmp73))
                    if pattern_index == 3:
                        pass
                        # State 44012
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 44013
                            if len(subjects25) == 0:
                                pass
                                # State 44014
                                if len(subjects) == 0:
                                    pass
                                    # 5: (e + f*x + g*x**2)**p
                                    yield 5, subst2
                        if len(subjects25) >= 1:
                            tmp77 = []
                            tmp77.append(subjects25.popleft())
                            while True:
                                if len(tmp77) > 1:
                                    tmp78 = create_operation_expression(
                                        associative1, tmp77)
                                elif len(tmp77) == 1:
                                    tmp78 = tmp77[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp78)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 44013
                                    if len(subjects25) == 0:
                                        pass
                                        # State 44014
                                        if len(subjects) == 0:
                                            pass
                                            # 5: (e + f*x + g*x**2)**p
                                            yield 5, subst2
                                if len(subjects25) == 0:
                                    break
                                tmp77.append(subjects25.popleft())
                            subjects25.extendleft(reversed(tmp77))
                subjects25.appendleft(tmp61)
            if len(subjects25) >= 1 and isinstance(subjects25[0], Mul):
                tmp80 = subjects25.popleft()
                associative1 = tmp80
                associative_type1 = type(tmp80)
                subjects81 = deque(tmp80._args)
                matcher = CommutativeMatcher31395.get()
                tmp82 = subjects81
                subjects81 = []
                for s in tmp82:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp82, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 31419
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 31420
                            if len(subjects25) == 0:
                                pass
                                # State 31421
                                if len(subjects) == 0:
                                    pass
                                    # 3: (x**m*(f + e*x**r))**p
                                    yield 3, subst2
                        if len(subjects25) >= 1:
                            tmp84 = []
                            tmp84.append(subjects25.popleft())
                            while True:
                                if len(tmp84) > 1:
                                    tmp85 = create_operation_expression(
                                        associative1, tmp84)
                                elif len(tmp84) == 1:
                                    tmp85 = tmp84[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp85)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 31420
                                    if len(subjects25) == 0:
                                        pass
                                        # State 31421
                                        if len(subjects) == 0:
                                            pass
                                            # 3: (x**m*(f + e*x**r))**p
                                            yield 3, subst2
                                if len(subjects25) == 0:
                                    break
                                tmp84.append(subjects25.popleft())
                            subjects25.extendleft(reversed(tmp84))
                subjects25.appendleft(tmp80)
            subjects.appendleft(tmp24)
        return
        yield
class CommutativeMatcher17761(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(1)), Mul)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher17761._instance is None:
            CommutativeMatcher17761._instance = CommutativeMatcher17761()
        return CommutativeMatcher17761._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 17760
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.0', S(0))
        except ValueError:
            pass
        else:
            pass
            # State 17762
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.3.1.1.0_1', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 17763
                if len(subjects) >= 1:
                    tmp3 = subjects.popleft()
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.3.1.1.0', tmp3)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 17764
                        if len(subjects) == 0:
                            pass
                            # 0: c + x*d
                            yield 0, subst3
                    subjects.appendleft(tmp3)
            if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                tmp5 = subjects.popleft()
                associative1 = tmp5
                associative_type1 = type(tmp5)
                subjects6 = deque(tmp5._args)
                matcher = CommutativeMatcher17766.get()
                tmp7 = subjects6
                subjects6 = []
                for s in tmp7:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp7, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 17767
                        if len(subjects) == 0:
                            pass
                            # 0: c + x*d
                            yield 0, subst2
                subjects.appendleft(tmp5)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0', S(0))
        except ValueError:
            pass
        else:
            pass
            # State 18083
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.2.1.3.1.1.0_1', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 18084
                if len(subjects) >= 1:
                    tmp10 = subjects.popleft()
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.2.1.3.1.1.0', tmp10)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 18085
                        if len(subjects) == 0:
                            pass
                            # 1: c + x*d
                            yield 1, subst3
                    subjects.appendleft(tmp10)
            if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                tmp12 = subjects.popleft()
                associative1 = tmp12
                associative_type1 = type(tmp12)
                subjects13 = deque(tmp12._args)
                matcher = CommutativeMatcher18087.get()
                tmp14 = subjects13
                subjects13 = []
                for s in tmp14:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp14, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 18088
                        if len(subjects) == 0:
                            pass
                            # 1: c + x*d
                            yield 1, subst2
                subjects.appendleft(tmp12)
        if len(subjects) >= 1 and isinstance(subjects[0], Add):
            tmp15 = subjects.popleft()
            associative1 = tmp15
            associative_type1 = type(tmp15)
            subjects16 = deque(tmp15._args)
            matcher = CommutativeMatcher17769.get()
            tmp17 = subjects16
            subjects16 = []
            for s in tmp17:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp17, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 17775
                    if len(subjects) == 0:
                        pass
                        # 0: c + x*d
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 18092
                    if len(subjects) == 0:
                        pass
                        # 1: c + x*d
                        yield 1, subst1
            subjects.appendleft(tmp15)
        return
        yield
class CommutativeMatcher84681(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.4.0', 1, 1,
                                                     S(0)), Add)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i2.4.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher84681._instance is None:
            CommutativeMatcher84681._instance = CommutativeMatcher84681()
        return CommutativeMatcher84681._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 84680
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 84682
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.3.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 84683
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.4.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 84999
            if len(subjects) >= 1:
                tmp5 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.4.1.0', tmp5)
                except ValueError:
                    pass
                else:
                    pass
                    # State 85000
                    if len(subjects) == 0:
                        pass
                        # 1: x*d
                        yield 1, subst2
                subjects.appendleft(tmp5)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.4.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 86405
            if len(subjects) >= 1:
                tmp8 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.4.1.0', tmp8)
                except ValueError:
                    pass
                else:
                    pass
                    # State 86406
                    if len(subjects) == 0:
                        pass
                        # 2: x*f
                        yield 2, subst2
                subjects.appendleft(tmp8)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp10 = subjects.popleft()
            associative1 = tmp10
            associative_type1 = type(tmp10)
            subjects11 = deque(tmp10._args)
            matcher = CommutativeMatcher84685.get()
            tmp12 = subjects11
            subjects11 = []
            for s in tmp12:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp12, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 84686
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 85001
                    if len(subjects) == 0:
                        pass
                        # 1: x*d
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 86407
                    if len(subjects) == 0:
                        pass
                        # 2: x*f
                        yield 2, subst1
            subjects.appendleft(tmp10)
        return
        yield
Example #11
0
class CommutativeMatcher36468(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher36468._instance is None:
            CommutativeMatcher36468._instance = CommutativeMatcher36468()
        return CommutativeMatcher36468._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 36467
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 36469
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.2.1.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 36470
                subst3 = Substitution(subst2)
                try:
                    subst3.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 36471
                    if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                        tmp4 = subjects.popleft()
                        subjects5 = deque(tmp4._args)
                        # State 36472
                        if len(subjects5) >= 1:
                            tmp6 = subjects5.popleft()
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.2.1.1', tmp6)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 36473
                                if len(subjects5) >= 1:
                                    tmp8 = subjects5.popleft()
                                    subst5 = Substitution(subst4)
                                    try:
                                        subst5.try_add_variable(
                                            'i2.2.1.2', tmp8)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 36474
                                        if len(subjects5) == 0:
                                            pass
                                            # State 36475
                                            if len(subjects) == 0:
                                                pass
                                                # 0: (x**j*f + e)**p
                                                yield 0, subst5
                                    subjects5.appendleft(tmp8)
                            subjects5.appendleft(tmp6)
                        subjects.appendleft(tmp4)
                if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                    tmp10 = subjects.popleft()
                    associative1 = tmp10
                    associative_type1 = type(tmp10)
                    subjects11 = deque(tmp10._args)
                    matcher = CommutativeMatcher36477.get()
                    tmp12 = subjects11
                    subjects11 = []
                    for s in tmp12:
                        matcher.add_subject(s)
                    for pattern_index, subst3 in matcher.match(tmp12, subst2):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 36482
                            if len(subjects) == 0:
                                pass
                                # 0: (x**j*f + e)**p
                                yield 0, subst3
                    subjects.appendleft(tmp10)
            if len(subjects) >= 1 and isinstance(subjects[0], Add):
                tmp13 = subjects.popleft()
                associative1 = tmp13
                associative_type1 = type(tmp13)
                subjects14 = deque(tmp13._args)
                matcher = CommutativeMatcher36484.get()
                tmp15 = subjects14
                subjects14 = []
                for s in tmp15:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp15, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 36497
                        if len(subjects) == 0:
                            pass
                            # 0: (x**j*f + e)**p
                            yield 0, subst2
                subjects.appendleft(tmp13)
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp16 = subjects.popleft()
            subjects17 = deque(tmp16._args)
            # State 36498
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.2.1.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 36499
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 36500
                    if len(subjects17) >= 1 and isinstance(subjects17[0], Pow):
                        tmp20 = subjects17.popleft()
                        subjects21 = deque(tmp20._args)
                        # State 36501
                        if len(subjects21) >= 1:
                            tmp22 = subjects21.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.1', tmp22)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 36502
                                if len(subjects21) >= 1:
                                    tmp24 = subjects21.popleft()
                                    subst4 = Substitution(subst3)
                                    try:
                                        subst4.try_add_variable(
                                            'i2.2.1.2', tmp24)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 36503
                                        if len(subjects21) == 0:
                                            pass
                                            # State 36504
                                            subst5 = Substitution(subst4)
                                            try:
                                                subst5.try_add_variable(
                                                    'i2.2.1.2.2.2', 1)
                                            except ValueError:
                                                pass
                                            else:
                                                pass
                                                # State 36505
                                                if len(subjects17) == 0:
                                                    pass
                                                    # State 36506
                                                    if len(subjects) == 0:
                                                        pass
                                                        # 0: (x**j*f + e)**p
                                                        yield 0, subst5
                                            if len(subjects17) >= 1:
                                                tmp27 = subjects17.popleft()
                                                subst5 = Substitution(subst4)
                                                try:
                                                    subst5.try_add_variable(
                                                        'i2.2.1.2.2.2', tmp27)
                                                except ValueError:
                                                    pass
                                                else:
                                                    pass
                                                    # State 36505
                                                    if len(subjects17) == 0:
                                                        pass
                                                        # State 36506
                                                        if len(subjects) == 0:
                                                            pass
                                                            # 0: (x**j*f + e)**p
                                                            yield 0, subst5
                                                subjects17.appendleft(tmp27)
                                    subjects21.appendleft(tmp24)
                            subjects21.appendleft(tmp22)
                        subjects17.appendleft(tmp20)
                if len(subjects17) >= 1 and isinstance(subjects17[0], Mul):
                    tmp29 = subjects17.popleft()
                    associative1 = tmp29
                    associative_type1 = type(tmp29)
                    subjects30 = deque(tmp29._args)
                    matcher = CommutativeMatcher36508.get()
                    tmp31 = subjects30
                    subjects30 = []
                    for s in tmp31:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp31, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 36513
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 36514
                                if len(subjects17) == 0:
                                    pass
                                    # State 36515
                                    if len(subjects) == 0:
                                        pass
                                        # 0: (x**j*f + e)**p
                                        yield 0, subst3
                            if len(subjects17) >= 1:
                                tmp33 = []
                                tmp33.append(subjects17.popleft())
                                while True:
                                    if len(tmp33) > 1:
                                        tmp34 = create_operation_expression(
                                            associative1, tmp33)
                                    elif len(tmp33) == 1:
                                        tmp34 = tmp33[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i2.2.1.2.2.2', tmp34)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 36514
                                        if len(subjects17) == 0:
                                            pass
                                            # State 36515
                                            if len(subjects) == 0:
                                                pass
                                                # 0: (x**j*f + e)**p
                                                yield 0, subst3
                                    if len(subjects17) == 0:
                                        break
                                    tmp33.append(subjects17.popleft())
                                subjects17.extendleft(reversed(tmp33))
                    subjects17.appendleft(tmp29)
            if len(subjects17) >= 1 and isinstance(subjects17[0], Add):
                tmp36 = subjects17.popleft()
                associative1 = tmp36
                associative_type1 = type(tmp36)
                subjects37 = deque(tmp36._args)
                matcher = CommutativeMatcher36517.get()
                tmp38 = subjects37
                subjects37 = []
                for s in tmp38:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp38, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 36530
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 36531
                            if len(subjects17) == 0:
                                pass
                                # State 36532
                                if len(subjects) == 0:
                                    pass
                                    # 0: (x**j*f + e)**p
                                    yield 0, subst2
                        if len(subjects17) >= 1:
                            tmp40 = []
                            tmp40.append(subjects17.popleft())
                            while True:
                                if len(tmp40) > 1:
                                    tmp41 = create_operation_expression(
                                        associative1, tmp40)
                                elif len(tmp40) == 1:
                                    tmp41 = tmp40[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable(
                                        'i2.2.1.2.2.2', tmp41)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 36531
                                    if len(subjects17) == 0:
                                        pass
                                        # State 36532
                                        if len(subjects) == 0:
                                            pass
                                            # 0: (x**j*f + e)**p
                                            yield 0, subst2
                                if len(subjects17) == 0:
                                    break
                                tmp40.append(subjects17.popleft())
                            subjects17.extendleft(reversed(tmp40))
                subjects17.appendleft(tmp36)
            subjects.appendleft(tmp16)
        return
        yield
Example #12
0
class CommutativeMatcher121782(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({}), [(VariableWithCount('i2.2.1.0', 1, 1, None), Mul),
                              (VariableWithCount('i2.3.1.0', 1, 1,
                                                 S(1)), Mul)]),
        1: (1, Multiset({0: 1}), [(VariableWithCount('i2.3.1.0', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({1: 1}), [(VariableWithCount('i2.3.1.0', 1, 1,
                                                     S(1)), Mul)]),
        3: (3, Multiset({}), [(VariableWithCount('i2.3.1.0', 1, 1, None), Mul),
                              (VariableWithCount('i2.3.1.0_1', 1, 1,
                                                 S(1)), Mul)]),
        4: (4, Multiset({2: 1}), [(VariableWithCount('i2.3.1.0', 1, 1,
                                                     S(1)), Mul)]),
        5: (5, Multiset({3: 1}), [(VariableWithCount('i2.3.1.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher121782._instance is None:
            CommutativeMatcher121782._instance = CommutativeMatcher121782()
        return CommutativeMatcher121782._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 121781
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 124561
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.3.1.1', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 124562
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.3.1.2', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 124563
                            if len(subjects2) == 0:
                                pass
                                # State 124564
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**n
                                    yield 0, subst2
                        subjects2.appendleft(tmp5)
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.3.1.2', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 125493
                        if len(subjects2) == 0:
                            pass
                            # State 125494
                            if len(subjects) == 0:
                                pass
                                # 1: x**n
                                yield 1, subst2
                    if len(subjects2) >= 1:
                        tmp8 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.3.1.2', tmp8)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 125493
                            if len(subjects2) == 0:
                                pass
                                # State 125494
                                if len(subjects) == 0:
                                    pass
                                    # 1: x**n
                                    yield 1, subst2
                        subjects2.appendleft(tmp8)
                subjects2.appendleft(tmp3)
            if len(subjects2) >= 1 and isinstance(subjects2[0], Add):
                tmp10 = subjects2.popleft()
                associative1 = tmp10
                associative_type1 = type(tmp10)
                subjects11 = deque(tmp10._args)
                matcher = CommutativeMatcher137084.get()
                tmp12 = subjects11
                subjects11 = []
                for s in tmp12:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp12, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 137090
                        if len(subjects2) >= 1:
                            tmp13 = []
                            tmp13.append(subjects2.popleft())
                            while True:
                                if len(tmp13) > 1:
                                    tmp14 = create_operation_expression(
                                        associative1, tmp13)
                                elif len(tmp13) == 1:
                                    tmp14 = tmp13[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i2.3.1.2', tmp14)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 137091
                                    if len(subjects2) == 0:
                                        pass
                                        # State 137092
                                        if len(subjects) == 0:
                                            pass
                                            # 3: (x*d + c)**n
                                            yield 3, subst2
                                if len(subjects2) == 0:
                                    break
                                tmp13.append(subjects2.popleft())
                            subjects2.extendleft(reversed(tmp13))
                subjects2.appendleft(tmp10)
            subjects.appendleft(tmp1)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 125491
            if len(subjects) >= 1:
                tmp17 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.1', tmp17)
                except ValueError:
                    pass
                else:
                    pass
                    # State 125492
                    if len(subjects) == 0:
                        pass
                        # 1: x**n
                        yield 1, subst2
                subjects.appendleft(tmp17)
        if len(subjects) >= 1 and isinstance(subjects[0], log):
            tmp19 = subjects.popleft()
            subjects20 = deque(tmp19._args)
            # State 134195
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.3.1.2.0', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 134196
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.2.2', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 134197
                    if len(subjects20) >= 1:
                        tmp23 = subjects20.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.3.1.2.1', tmp23)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 134198
                            if len(subjects20) == 0:
                                pass
                                # State 134199
                                if len(subjects) == 0:
                                    pass
                                    # 2: log(c*x**n)
                                    yield 2, subst3
                        subjects20.appendleft(tmp23)
                if len(subjects20) >= 1 and isinstance(subjects20[0], Pow):
                    tmp25 = subjects20.popleft()
                    subjects26 = deque(tmp25._args)
                    # State 134200
                    if len(subjects26) >= 1:
                        tmp27 = subjects26.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.3.1.2.1', tmp27)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 134201
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.1.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 134202
                                if len(subjects26) == 0:
                                    pass
                                    # State 134203
                                    if len(subjects20) == 0:
                                        pass
                                        # State 134204
                                        if len(subjects) == 0:
                                            pass
                                            # 2: log(c*x**n)
                                            yield 2, subst3
                            if len(subjects26) >= 1:
                                tmp30 = subjects26.popleft()
                                subst3 = Substitution(subst2)
                                try:
                                    subst3.try_add_variable(
                                        'i2.3.1.2.2', tmp30)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 134202
                                    if len(subjects26) == 0:
                                        pass
                                        # State 134203
                                        if len(subjects20) == 0:
                                            pass
                                            # State 134204
                                            if len(subjects) == 0:
                                                pass
                                                # 2: log(c*x**n)
                                                yield 2, subst3
                                subjects26.appendleft(tmp30)
                        subjects26.appendleft(tmp27)
                    subjects20.appendleft(tmp25)
            if len(subjects20) >= 1 and isinstance(subjects20[0], Mul):
                tmp32 = subjects20.popleft()
                associative1 = tmp32
                associative_type1 = type(tmp32)
                subjects33 = deque(tmp32._args)
                matcher = CommutativeMatcher134206.get()
                tmp34 = subjects33
                subjects33 = []
                for s in tmp34:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp34, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 134213
                        if len(subjects20) == 0:
                            pass
                            # State 134214
                            if len(subjects) == 0:
                                pass
                                # 2: log(c*x**n)
                                yield 2, subst1
                subjects20.appendleft(tmp32)
            subjects.appendleft(tmp19)
        return
        yield
class CommutativeMatcher57205(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(0)), Add)]),
        3: (3, Multiset({3: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(0)), Add)]),
        4: (4, Multiset({4: 1}), [(VariableWithCount('i2.2.1.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        5: (5, Multiset({5: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(0)), Add)]),
        6: (6, Multiset({6: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(0)), Add)]),
        7: (7, Multiset({7: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(0)), Add)]),
        8: (8, Multiset({
            8: 1,
            9: 1
        }), [(VariableWithCount('i2.3.0', 1, 1, S(0)), Add)]),
        9: (9, Multiset({10: 1}), [(VariableWithCount('i2.4.0', 1, 1,
                                                      S(0)), Add)]),
        10: (10, Multiset({11:
                           1}), [(VariableWithCount('i2.2.3.0', 1, 1,
                                                    S(0)), Add)]),
        11: (11, Multiset({12:
                           1}), [(VariableWithCount('i2.2.1.2.3.0', 1, 1,
                                                    S(0)), Add)]),
        12: (12, Multiset({13:
                           1}), [(VariableWithCount('i2.2.1.4.0', 1, 1,
                                                    S(0)), Add)]),
        13: (13, Multiset({14: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                        S(0)), Add)]),
        14: (14, Multiset({15:
                           1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                    S(0)), Add)]),
        15: (15, Multiset({9: 1}), [(VariableWithCount('i2.3.0_1', 1, 1,
                                                       S(0)), Add)]),
        16: (16, Multiset({16: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                        S(0)), Add)]),
        17: (17, Multiset({17: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                        S(0)), Add)]),
        18: (18, Multiset({18:
                           1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                    S(0)), Add)]),
        19: (19, Multiset({19:
                           1}), [(VariableWithCount('i2.3.0_1', 1, 1,
                                                    S(0)), Add)]),
        20: (20, Multiset({19:
                           1}), [(VariableWithCount('i2.3.0_1', 1, 1,
                                                    None), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher57205._instance is None:
            CommutativeMatcher57205._instance = CommutativeMatcher57205()
        return CommutativeMatcher57205._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 57204
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 57206
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 57207
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 58406
            if len(subjects) >= 1:
                tmp5 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.1.0', tmp5)
                except ValueError:
                    pass
                else:
                    pass
                    # State 58407
                    if len(subjects) == 0:
                        pass
                        # 1: x*d
                        yield 1, subst2
                subjects.appendleft(tmp5)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 64367
            if len(subjects) >= 1:
                tmp8 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.3.1.0', tmp8)
                except ValueError:
                    pass
                else:
                    pass
                    # State 64368
                    if len(subjects) == 0:
                        pass
                        # 2: x*f
                        yield 2, subst2
                subjects.appendleft(tmp8)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 65747
            if len(subjects) >= 1:
                tmp11 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.0', tmp11)
                except ValueError:
                    pass
                else:
                    pass
                    # State 65748
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst2
                subjects.appendleft(tmp11)
            if len(subjects) >= 1:
                tmp13 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp13)
                except ValueError:
                    pass
                else:
                    pass
                    # State 75825
                    if len(subjects) == 0:
                        pass
                        # 9: x*b
                        yield 9, subst2
                subjects.appendleft(tmp13)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 68200
            if len(subjects) >= 1:
                tmp16 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.1.0', tmp16)
                except ValueError:
                    pass
                else:
                    pass
                    # State 68201
                    if len(subjects) == 0:
                        pass
                        # 4: x*d
                        yield 4, subst2
                subjects.appendleft(tmp16)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 72101
            if len(subjects) >= 1:
                tmp19 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp19)
                except ValueError:
                    pass
                else:
                    pass
                    # State 72102
                    if len(subjects) == 0:
                        pass
                        # 5: x*f
                        yield 5, subst2
                subjects.appendleft(tmp19)
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.3.1.2', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 75573
                if len(subjects) >= 1:
                    tmp22 = subjects.popleft()
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.3.1.1', tmp22)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 75574
                        if len(subjects) == 0:
                            pass
                            # 7: b*x**n
                            yield 7, subst3
                    subjects.appendleft(tmp22)
            if len(subjects) >= 1:
                tmp24 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.1.0', tmp24)
                except ValueError:
                    pass
                else:
                    pass
                    # State 100887
                    if len(subjects) == 0:
                        pass
                        # 14: x*b
                        yield 14, subst2
                subjects.appendleft(tmp24)
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp26 = subjects.popleft()
                subjects27 = deque(tmp26._args)
                # State 74655
                if len(subjects27) >= 1:
                    tmp28 = subjects27.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.3.1.1', tmp28)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 74656
                        if len(subjects27) >= 1:
                            tmp30 = subjects27.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.1.2', tmp30)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 74657
                                if len(subjects27) == 0:
                                    pass
                                    # State 74658
                                    if len(subjects) == 0:
                                        pass
                                        # 6: b*x**n
                                        yield 6, subst3
                            subjects27.appendleft(tmp30)
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.3.1.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 75575
                            if len(subjects27) == 0:
                                pass
                                # State 75576
                                if len(subjects) == 0:
                                    pass
                                    # 7: b*x**n
                                    yield 7, subst3
                        if len(subjects27) >= 1:
                            tmp33 = subjects27.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.1.2', tmp33)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 75575
                                if len(subjects27) == 0:
                                    pass
                                    # State 75576
                                    if len(subjects) == 0:
                                        pass
                                        # 7: b*x**n
                                        yield 7, subst3
                            subjects27.appendleft(tmp33)
                    subjects27.appendleft(tmp28)
                if len(subjects27) >= 1:
                    tmp35 = subjects27.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.0', tmp35)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 75818
                        if len(subjects27) >= 1 and subjects27[0] == Integer(
                                2):
                            tmp37 = subjects27.popleft()
                            # State 75819
                            if len(subjects27) == 0:
                                pass
                                # State 75820
                                if len(subjects) == 0:
                                    pass
                                    # 8: v**2*c
                                    yield 8, subst2
                            subjects27.appendleft(tmp37)
                    subjects27.appendleft(tmp35)
                if len(subjects27) >= 1 and isinstance(subjects27[0], Add):
                    tmp38 = subjects27.popleft()
                    associative1 = tmp38
                    associative_type1 = type(tmp38)
                    subjects39 = deque(tmp38._args)
                    matcher = CommutativeMatcher107464.get()
                    tmp40 = subjects39
                    subjects39 = []
                    for s in tmp40:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp40, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 107470
                            if len(subjects27) >= 1:
                                tmp41 = []
                                tmp41.append(subjects27.popleft())
                                while True:
                                    if len(tmp41) > 1:
                                        tmp42 = create_operation_expression(
                                            associative1, tmp41)
                                    elif len(tmp41) == 1:
                                        tmp42 = tmp41[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i2.3.1.2', tmp42)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 107471
                                        if len(subjects27) == 0:
                                            pass
                                            # State 107472
                                            if len(subjects) == 0:
                                                pass
                                                # 17: b*(x*d + c)**n
                                                yield 17, subst3
                                    if len(subjects27) == 0:
                                        break
                                    tmp41.append(subjects27.popleft())
                                subjects27.extendleft(reversed(tmp41))
                    subjects27.appendleft(tmp38)
                subjects.appendleft(tmp26)
            if len(subjects) >= 1 and isinstance(subjects[0], log):
                tmp44 = subjects.popleft()
                subjects45 = deque(tmp44._args)
                # State 105092
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.2.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 105093
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.3.1.2.2', S(1))
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 105094
                        if len(subjects45) >= 1:
                            tmp48 = subjects45.popleft()
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.3.1.2.1', tmp48)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 105095
                                if len(subjects45) == 0:
                                    pass
                                    # State 105096
                                    if len(subjects) == 0:
                                        pass
                                        # 16: b*log(c*x**n)
                                        yield 16, subst4
                            subjects45.appendleft(tmp48)
                    if len(subjects45) >= 1 and isinstance(subjects45[0], Pow):
                        tmp50 = subjects45.popleft()
                        subjects51 = deque(tmp50._args)
                        # State 105097
                        if len(subjects51) >= 1:
                            tmp52 = subjects51.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.1.2.1', tmp52)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 105098
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.3.1.2.2', 1)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 105099
                                    if len(subjects51) == 0:
                                        pass
                                        # State 105100
                                        if len(subjects45) == 0:
                                            pass
                                            # State 105101
                                            if len(subjects) == 0:
                                                pass
                                                # 16: b*log(c*x**n)
                                                yield 16, subst4
                                if len(subjects51) >= 1:
                                    tmp55 = subjects51.popleft()
                                    subst4 = Substitution(subst3)
                                    try:
                                        subst4.try_add_variable(
                                            'i2.3.1.2.2', tmp55)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 105099
                                        if len(subjects51) == 0:
                                            pass
                                            # State 105100
                                            if len(subjects45) == 0:
                                                pass
                                                # State 105101
                                                if len(subjects) == 0:
                                                    pass
                                                    # 16: b*log(c*x**n)
                                                    yield 16, subst4
                                    subjects51.appendleft(tmp55)
                            subjects51.appendleft(tmp52)
                        subjects45.appendleft(tmp50)
                if len(subjects45) >= 1 and isinstance(subjects45[0], Mul):
                    tmp57 = subjects45.popleft()
                    associative1 = tmp57
                    associative_type1 = type(tmp57)
                    subjects58 = deque(tmp57._args)
                    matcher = CommutativeMatcher105103.get()
                    tmp59 = subjects58
                    subjects58 = []
                    for s in tmp59:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp59, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 105110
                            if len(subjects45) == 0:
                                pass
                                # State 105111
                                if len(subjects) == 0:
                                    pass
                                    # 16: b*log(c*x**n)
                                    yield 16, subst2
                    subjects45.appendleft(tmp57)
                subjects.appendleft(tmp44)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.4.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 75950
            if len(subjects) >= 1:
                tmp61 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.4.1.0', tmp61)
                except ValueError:
                    pass
                else:
                    pass
                    # State 75951
                    if len(subjects) == 0:
                        pass
                        # 10: x*f
                        yield 10, subst2
                subjects.appendleft(tmp61)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 75988
            if len(subjects) >= 1:
                tmp64 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.3.1.0', tmp64)
                except ValueError:
                    pass
                else:
                    pass
                    # State 75989
                    if len(subjects) == 0:
                        pass
                        # 11: x*f
                        yield 11, subst2
                subjects.appendleft(tmp64)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 82600
            if len(subjects) >= 1:
                tmp67 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.3.1.0', tmp67)
                except ValueError:
                    pass
                else:
                    pass
                    # State 82601
                    if len(subjects) == 0:
                        pass
                        # 12: x*d
                        yield 12, subst2
                subjects.appendleft(tmp67)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.4.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 82794
            if len(subjects) >= 1:
                tmp70 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.4.1.0', tmp70)
                except ValueError:
                    pass
                else:
                    pass
                    # State 82795
                    if len(subjects) == 0:
                        pass
                        # 13: x*d
                        yield 13, subst2
                subjects.appendleft(tmp70)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 103699
            if len(subjects) >= 1:
                tmp73 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp73)
                except ValueError:
                    pass
                else:
                    pass
                    # State 103700
                    if len(subjects) == 0:
                        pass
                        # 15: x*d
                        yield 15, subst2
                subjects.appendleft(tmp73)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 107637
            if len(subjects) >= 1:
                tmp76 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp76)
                except ValueError:
                    pass
                else:
                    pass
                    # State 107638
                    if len(subjects) == 0:
                        pass
                        # 18: x*e
                        yield 18, subst2
                subjects.appendleft(tmp76)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.1.0_2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 107851
            if len(subjects) >= 1:
                tmp79 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.0', tmp79)
                except ValueError:
                    pass
                else:
                    pass
                    # State 107852
                    if len(subjects) == 0:
                        pass
                        # 19: x*d
                        yield 19, subst2
                subjects.appendleft(tmp79)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp81 = subjects.popleft()
            associative1 = tmp81
            associative_type1 = type(tmp81)
            subjects82 = deque(tmp81._args)
            matcher = CommutativeMatcher57209.get()
            tmp83 = subjects82
            subjects82 = []
            for s in tmp83:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp83, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 57210
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 58408
                    if len(subjects) == 0:
                        pass
                        # 1: x*d
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 64369
                    if len(subjects) == 0:
                        pass
                        # 2: x*f
                        yield 2, subst1
                if pattern_index == 3:
                    pass
                    # State 65749
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst1
                if pattern_index == 4:
                    pass
                    # State 68202
                    if len(subjects) == 0:
                        pass
                        # 4: x*d
                        yield 4, subst1
                if pattern_index == 5:
                    pass
                    # State 72103
                    if len(subjects) == 0:
                        pass
                        # 5: x*f
                        yield 5, subst1
                if pattern_index == 6:
                    pass
                    # State 74663
                    if len(subjects) == 0:
                        pass
                        # 6: b*x**n
                        yield 6, subst1
                if pattern_index == 7:
                    pass
                    # State 75581
                    if len(subjects) == 0:
                        pass
                        # 7: b*x**n
                        yield 7, subst1
                if pattern_index == 8:
                    pass
                    # State 75824
                    if len(subjects) == 0:
                        pass
                        # 8: v**2*c
                        yield 8, subst1
                if pattern_index == 9:
                    pass
                    # State 75826
                    if len(subjects) == 0:
                        pass
                        # 9: x*b
                        yield 9, subst1
                if pattern_index == 10:
                    pass
                    # State 75952
                    if len(subjects) == 0:
                        pass
                        # 10: x*f
                        yield 10, subst1
                if pattern_index == 11:
                    pass
                    # State 75990
                    if len(subjects) == 0:
                        pass
                        # 11: x*f
                        yield 11, subst1
                if pattern_index == 12:
                    pass
                    # State 82602
                    if len(subjects) == 0:
                        pass
                        # 12: x*d
                        yield 12, subst1
                if pattern_index == 13:
                    pass
                    # State 82796
                    if len(subjects) == 0:
                        pass
                        # 13: x*d
                        yield 13, subst1
                if pattern_index == 14:
                    pass
                    # State 100888
                    if len(subjects) == 0:
                        pass
                        # 14: x*b
                        yield 14, subst1
                if pattern_index == 15:
                    pass
                    # State 103701
                    if len(subjects) == 0:
                        pass
                        # 15: x*d
                        yield 15, subst1
                if pattern_index == 16:
                    pass
                    # State 105132
                    if len(subjects) == 0:
                        pass
                        # 16: b*log(c*x**n)
                        yield 16, subst1
                if pattern_index == 17:
                    pass
                    # State 107483
                    if len(subjects) == 0:
                        pass
                        # 17: b*(x*d + c)**n
                        yield 17, subst1
                if pattern_index == 18:
                    pass
                    # State 107639
                    if len(subjects) == 0:
                        pass
                        # 18: x*e
                        yield 18, subst1
                if pattern_index == 19:
                    pass
                    # State 107853
                    if len(subjects) == 0:
                        pass
                        # 19: x*d
                        yield 19, subst1
            subjects.appendleft(tmp81)
        return
        yield
Example #14
0
class CommutativeMatcher49270(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i3.2.1.0', 1, 1,
                                                     S(1)), Mul)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i3.2.1.0', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i3.2.1.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher49270._instance is None:
            CommutativeMatcher49270._instance = CommutativeMatcher49270()
        return CommutativeMatcher49270._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 49269
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 49271
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i3.2.1.1', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 49272
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i3.2.1.2', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 49273
                            if len(subjects2) == 0:
                                pass
                                # State 49274
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**n
                                    yield 0, subst2
                        subjects2.appendleft(tmp5)
                subjects2.appendleft(tmp3)
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i3.2.1.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 51275
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i3.2.1.2.1.0_1', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 51276
                    if len(subjects2) >= 1:
                        tmp9 = subjects2.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i3.2.1.2.1.0', tmp9)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 51277
                            if len(subjects2) >= 1:
                                tmp11 = subjects2.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i3.2.1.2', tmp11)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 51278
                                    if len(subjects2) == 0:
                                        pass
                                        # State 51279
                                        if len(subjects) == 0:
                                            pass
                                            # 1: (d + x*e)**n
                                            yield 1, subst4
                                subjects2.appendleft(tmp11)
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i3.2.1.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 51479
                                if len(subjects2) == 0:
                                    pass
                                    # State 51480
                                    if len(subjects) == 0:
                                        pass
                                        # 2: (d + x*e)**n
                                        yield 2, subst4
                            if len(subjects2) >= 1:
                                tmp14 = subjects2.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i3.2.1.2', tmp14)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 51479
                                    if len(subjects2) == 0:
                                        pass
                                        # State 51480
                                        if len(subjects) == 0:
                                            pass
                                            # 2: (d + x*e)**n
                                            yield 2, subst4
                                subjects2.appendleft(tmp14)
                        subjects2.appendleft(tmp9)
                if len(subjects2) >= 1 and isinstance(subjects2[0], Mul):
                    tmp16 = subjects2.popleft()
                    associative1 = tmp16
                    associative_type1 = type(tmp16)
                    subjects17 = deque(tmp16._args)
                    matcher = CommutativeMatcher51281.get()
                    tmp18 = subjects17
                    subjects17 = []
                    for s in tmp18:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp18, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 51282
                            if len(subjects2) >= 1:
                                tmp19 = []
                                tmp19.append(subjects2.popleft())
                                while True:
                                    if len(tmp19) > 1:
                                        tmp20 = create_operation_expression(
                                            associative1, tmp19)
                                    elif len(tmp19) == 1:
                                        tmp20 = tmp19[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i3.2.1.2', tmp20)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 51283
                                        if len(subjects2) == 0:
                                            pass
                                            # State 51284
                                            if len(subjects) == 0:
                                                pass
                                                # 1: (d + x*e)**n
                                                yield 1, subst3
                                    if len(subjects2) == 0:
                                        break
                                    tmp19.append(subjects2.popleft())
                                subjects2.extendleft(reversed(tmp19))
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i3.2.1.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 51481
                                if len(subjects2) == 0:
                                    pass
                                    # State 51482
                                    if len(subjects) == 0:
                                        pass
                                        # 2: (d + x*e)**n
                                        yield 2, subst3
                            if len(subjects2) >= 1:
                                tmp23 = []
                                tmp23.append(subjects2.popleft())
                                while True:
                                    if len(tmp23) > 1:
                                        tmp24 = create_operation_expression(
                                            associative1, tmp23)
                                    elif len(tmp23) == 1:
                                        tmp24 = tmp23[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable(
                                            'i3.2.1.2', tmp24)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 51481
                                        if len(subjects2) == 0:
                                            pass
                                            # State 51482
                                            if len(subjects) == 0:
                                                pass
                                                # 2: (d + x*e)**n
                                                yield 2, subst3
                                    if len(subjects2) == 0:
                                        break
                                    tmp23.append(subjects2.popleft())
                                subjects2.extendleft(reversed(tmp23))
                    subjects2.appendleft(tmp16)
            if len(subjects2) >= 1 and isinstance(subjects2[0], Add):
                tmp26 = subjects2.popleft()
                associative1 = tmp26
                associative_type1 = type(tmp26)
                subjects27 = deque(tmp26._args)
                matcher = CommutativeMatcher51286.get()
                tmp28 = subjects27
                subjects27 = []
                for s in tmp28:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp28, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 51292
                        if len(subjects2) >= 1:
                            tmp29 = []
                            tmp29.append(subjects2.popleft())
                            while True:
                                if len(tmp29) > 1:
                                    tmp30 = create_operation_expression(
                                        associative1, tmp29)
                                elif len(tmp29) == 1:
                                    tmp30 = tmp29[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i3.2.1.2', tmp30)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 51293
                                    if len(subjects2) == 0:
                                        pass
                                        # State 51294
                                        if len(subjects) == 0:
                                            pass
                                            # 1: (d + x*e)**n
                                            yield 1, subst2
                                if len(subjects2) == 0:
                                    break
                                tmp29.append(subjects2.popleft())
                            subjects2.extendleft(reversed(tmp29))
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i3.2.1.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 51483
                            if len(subjects2) == 0:
                                pass
                                # State 51484
                                if len(subjects) == 0:
                                    pass
                                    # 2: (d + x*e)**n
                                    yield 2, subst2
                        if len(subjects2) >= 1:
                            tmp33 = []
                            tmp33.append(subjects2.popleft())
                            while True:
                                if len(tmp33) > 1:
                                    tmp34 = create_operation_expression(
                                        associative1, tmp33)
                                elif len(tmp33) == 1:
                                    tmp34 = tmp33[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i3.2.1.2', tmp34)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 51483
                                    if len(subjects2) == 0:
                                        pass
                                        # State 51484
                                        if len(subjects) == 0:
                                            pass
                                            # 2: (d + x*e)**n
                                            yield 2, subst2
                                if len(subjects2) == 0:
                                    break
                                tmp33.append(subjects2.popleft())
                            subjects2.extendleft(reversed(tmp33))
                subjects2.appendleft(tmp26)
            subjects.appendleft(tmp1)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i3.2.1.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 51464
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i3.2.1.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 51465
                subst3 = Substitution(subst2)
                try:
                    subst3.try_add_variable('i3.2.1.2.1.0_1', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 51466
                    if len(subjects) >= 1:
                        tmp39 = subjects.popleft()
                        subst4 = Substitution(subst3)
                        try:
                            subst4.try_add_variable('i3.2.1.2.1.0', tmp39)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 51467
                            if len(subjects) == 0:
                                pass
                                # 2: (d + x*e)**n
                                yield 2, subst4
                        subjects.appendleft(tmp39)
                if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                    tmp41 = subjects.popleft()
                    associative1 = tmp41
                    associative_type1 = type(tmp41)
                    subjects42 = deque(tmp41._args)
                    matcher = CommutativeMatcher51469.get()
                    tmp43 = subjects42
                    subjects42 = []
                    for s in tmp43:
                        matcher.add_subject(s)
                    for pattern_index, subst3 in matcher.match(tmp43, subst2):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 51470
                            if len(subjects) == 0:
                                pass
                                # 2: (d + x*e)**n
                                yield 2, subst3
                    subjects.appendleft(tmp41)
            if len(subjects) >= 1 and isinstance(subjects[0], Add):
                tmp44 = subjects.popleft()
                associative1 = tmp44
                associative_type1 = type(tmp44)
                subjects45 = deque(tmp44._args)
                matcher = CommutativeMatcher51472.get()
                tmp46 = subjects45
                subjects45 = []
                for s in tmp46:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp46, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 51478
                        if len(subjects) == 0:
                            pass
                            # 2: (d + x*e)**n
                            yield 2, subst2
                subjects.appendleft(tmp44)
        return
        yield
class CommutativeMatcher39134(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher39134._instance is None:
            CommutativeMatcher39134._instance = CommutativeMatcher39134()
        return CommutativeMatcher39134._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 39133
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 39135
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp2 = subjects.popleft()
                subjects3 = deque(tmp2._args)
                # State 39136
                if len(subjects3) >= 1:
                    tmp4 = subjects3.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.1', tmp4)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 39137
                        if len(subjects3) >= 1:
                            tmp6 = subjects3.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2', tmp6)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 39138
                                if len(subjects3) == 0:
                                    pass
                                    # State 39139
                                    if len(subjects) == 0:
                                        pass
                                        # 0: x**j*f
                                        yield 0, subst3
                            subjects3.appendleft(tmp6)
                    subjects3.appendleft(tmp4)
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp8 = subjects.popleft()
            associative1 = tmp8
            associative_type1 = type(tmp8)
            subjects9 = deque(tmp8._args)
            matcher = CommutativeMatcher39141.get()
            tmp10 = subjects9
            subjects9 = []
            for s in tmp10:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp10, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 39146
                    if len(subjects) == 0:
                        pass
                        # 0: x**j*f
                        yield 0, subst1
            subjects.appendleft(tmp8)
        return
        yield
Example #16
0
class CommutativeMatcher126490(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher126490._instance is None:
            CommutativeMatcher126490._instance = CommutativeMatcher126490()
        return CommutativeMatcher126490._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 126489
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 126491
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.3.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 126492
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 127824
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp5 = subjects.popleft()
                subjects6 = deque(tmp5._args)
                # State 127825
                if len(subjects6) >= 1:
                    tmp7 = subjects6.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.3.1.1', tmp7)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 127826
                        if len(subjects6) >= 1:
                            tmp9 = subjects6.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.3.1.2', tmp9)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 127827
                                if len(subjects6) == 0:
                                    pass
                                    # State 127828
                                    if len(subjects) == 0:
                                        pass
                                        # 1: d*x**n
                                        yield 1, subst3
                            subjects6.appendleft(tmp9)
                    subjects6.appendleft(tmp7)
                subjects.appendleft(tmp5)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp11 = subjects.popleft()
            associative1 = tmp11
            associative_type1 = type(tmp11)
            subjects12 = deque(tmp11._args)
            matcher = CommutativeMatcher126494.get()
            tmp13 = subjects12
            subjects12 = []
            for s in tmp13:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp13, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 126495
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 127833
                    if len(subjects) == 0:
                        pass
                        # 1: d*x**n
                        yield 1, subst1
            subjects.appendleft(tmp11)
        return
        yield
Example #17
0
class CommutativeMatcher18284(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i4.1.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher18284._instance is None:
            CommutativeMatcher18284._instance = CommutativeMatcher18284()
        return CommutativeMatcher18284._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 18283
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i4.1.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 18285
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp2 = subjects.popleft()
                subjects3 = deque(tmp2._args)
                # State 18286
                if len(subjects3) >= 1:
                    tmp4 = subjects3.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i4.1', tmp4)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 18287
                        if len(subjects3) >= 1 and subjects3[0] == Integer(4):
                            tmp6 = subjects3.popleft()
                            # State 18288
                            if len(subjects3) == 0:
                                pass
                                # State 18289
                                if len(subjects) == 0:
                                    pass
                                    # 0: b*x**4
                                    yield 0, subst2
                            subjects3.appendleft(tmp6)
                    subjects3.appendleft(tmp4)
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp7 = subjects.popleft()
            associative1 = tmp7
            associative_type1 = type(tmp7)
            subjects8 = deque(tmp7._args)
            matcher = CommutativeMatcher18291.get()
            tmp9 = subjects8
            subjects8 = []
            for s in tmp9:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp9, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 18296
                    if len(subjects) == 0:
                        pass
                        # 0: b*x**4
                        yield 0, subst1
            subjects.appendleft(tmp7)
        return
        yield
Example #18
0
class CommutativeMatcher111271(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.3.2.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher111271._instance is None:
            CommutativeMatcher111271._instance = CommutativeMatcher111271()
        return CommutativeMatcher111271._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 111270
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 111272
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.3.2.1.2', S(1))
            except ValueError:
                pass
            else:
                pass
                # State 111273
                if len(subjects) >= 1:
                    tmp3 = subjects.popleft()
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.3.2.1.1', tmp3)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 111274
                        if len(subjects) == 0:
                            pass
                            # 0: b*x**n
                            yield 0, subst3
                    subjects.appendleft(tmp3)
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp5 = subjects.popleft()
                subjects6 = deque(tmp5._args)
                # State 111275
                if len(subjects6) >= 1:
                    tmp7 = subjects6.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.3.2.1.1', tmp7)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 111276
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.3.2.1.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 111277
                            if len(subjects6) == 0:
                                pass
                                # State 111278
                                if len(subjects) == 0:
                                    pass
                                    # 0: b*x**n
                                    yield 0, subst3
                        if len(subjects6) >= 1:
                            tmp10 = subjects6.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.2.1.2', tmp10)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 111277
                                if len(subjects6) == 0:
                                    pass
                                    # State 111278
                                    if len(subjects) == 0:
                                        pass
                                        # 0: b*x**n
                                        yield 0, subst3
                            subjects6.appendleft(tmp10)
                    subjects6.appendleft(tmp7)
                subjects.appendleft(tmp5)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp12 = subjects.popleft()
            associative1 = tmp12
            associative_type1 = type(tmp12)
            subjects13 = deque(tmp12._args)
            matcher = CommutativeMatcher111280.get()
            tmp14 = subjects13
            subjects13 = []
            for s in tmp14:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp14, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 111287
                    if len(subjects) == 0:
                        pass
                        # 0: b*x**n
                        yield 0, subst1
            subjects.appendleft(tmp12)
        return
        yield
Example #19
0
class CommutativeMatcher47935(CommutativeMatcher):
    _instance = None
    patterns = {
    0: (0, Multiset({0: 1, 1: 1}), [
      (VariableWithCount('i2.2.2.0', 1, 1, S(1)), Mul)
]),
    1: (1, Multiset({2: 1, 3: 1}), [
      (VariableWithCount('i2.2.2.0', 1, 1, S(1)), Mul)
])
}
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher47935._instance is None:
            CommutativeMatcher47935._instance = CommutativeMatcher47935()
        return CommutativeMatcher47935._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 47934
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 47936
            subst2 = Substitution(subst1)
            try:
                subst2.try_add_variable('i2.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 47937
                subst3 = Substitution(subst2)
                try:
                    subst3.try_add_variable('i2.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 47938
                    if len(subjects) >= 1:
                        tmp4 = subjects.popleft()
                        subst4 = Substitution(subst3)
                        try:
                            subst4.try_add_variable('i2.2.1.0', tmp4)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 47939
                            if len(subjects) == 0:
                                pass
                                # 0: (x*b + a)**n1
                                yield 0, subst4
                        subjects.appendleft(tmp4)
                    if len(subjects) >= 1:
                        tmp6 = subjects.popleft()
                        subst4 = Substitution(subst3)
                        try:
                            subst4.try_add_variable('i2.2.1.1', tmp6)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 48786
                            if len(subjects) == 0:
                                pass
                                # 2: (x*b + a)**n1
                                yield 2, subst4
                        subjects.appendleft(tmp6)
                if len(subjects) >= 1 and isinstance(subjects[0], Mul):
                    tmp8 = subjects.popleft()
                    associative1 = tmp8
                    associative_type1 = type(tmp8)
                    subjects9 = deque(tmp8._args)
                    matcher = CommutativeMatcher47941.get()
                    tmp10 = subjects9
                    subjects9 = []
                    for s in tmp10:
                        matcher.add_subject(s)
                    for pattern_index, subst3 in matcher.match(tmp10, subst2):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 47942
                            if len(subjects) == 0:
                                pass
                                # 0: (x*b + a)**n1
                                yield 0, subst3
                        if pattern_index == 1:
                            pass
                            # State 48787
                            if len(subjects) == 0:
                                pass
                                # 2: (x*b + a)**n1
                                yield 2, subst3
                    subjects.appendleft(tmp8)
            if len(subjects) >= 1 and isinstance(subjects[0], Add):
                tmp11 = subjects.popleft()
                associative1 = tmp11
                associative_type1 = type(tmp11)
                subjects12 = deque(tmp11._args)
                matcher = CommutativeMatcher47944.get()
                tmp13 = subjects12
                subjects12 = []
                for s in tmp13:
                    matcher.add_subject(s)
                for pattern_index, subst2 in matcher.match(tmp13, subst1):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 47950
                        if len(subjects) == 0:
                            pass
                            # 0: (x*b + a)**n1
                            yield 0, subst2
                    if pattern_index == 1:
                        pass
                        # State 48790
                        if len(subjects) == 0:
                            pass
                            # 2: (x*b + a)**n1
                            yield 2, subst2
                subjects.appendleft(tmp11)
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp14 = subjects.popleft()
            subjects15 = deque(tmp14._args)
            # State 47951
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.2.2.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 47952
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 47953
                    if len(subjects15) >= 1:
                        tmp18 = subjects15.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.2.1.0', tmp18)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 47954
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 47955
                                if len(subjects15) == 0:
                                    pass
                                    # State 47956
                                    if len(subjects) == 0:
                                        pass
                                        # 0: (x*b + a)**n1
                                        yield 0, subst4
                            if len(subjects15) >= 1:
                                tmp21 = subjects15.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.2.2.2', tmp21)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 47955
                                    if len(subjects15) == 0:
                                        pass
                                        # State 47956
                                        if len(subjects) == 0:
                                            pass
                                            # 0: (x*b + a)**n1
                                            yield 0, subst4
                                subjects15.appendleft(tmp21)
                        subjects15.appendleft(tmp18)
                    if len(subjects15) >= 1:
                        tmp23 = subjects15.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.2.1.1', tmp23)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 48791
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 48792
                                if len(subjects15) == 0:
                                    pass
                                    # State 48793
                                    if len(subjects) == 0:
                                        pass
                                        # 2: (x*b + a)**n1
                                        yield 2, subst4
                            if len(subjects15) >= 1:
                                tmp26 = subjects15.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.2.2.2', tmp26)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 48792
                                    if len(subjects15) == 0:
                                        pass
                                        # State 48793
                                        if len(subjects) == 0:
                                            pass
                                            # 2: (x*b + a)**n1
                                            yield 2, subst4
                                subjects15.appendleft(tmp26)
                        subjects15.appendleft(tmp23)
                if len(subjects15) >= 1 and isinstance(subjects15[0], Mul):
                    tmp28 = subjects15.popleft()
                    associative1 = tmp28
                    associative_type1 = type(tmp28)
                    subjects29 = deque(tmp28._args)
                    matcher = CommutativeMatcher47958.get()
                    tmp30 = subjects29
                    subjects29 = []
                    for s in tmp30:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp30, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 47959
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 47960
                                if len(subjects15) == 0:
                                    pass
                                    # State 47961
                                    if len(subjects) == 0:
                                        pass
                                        # 0: (x*b + a)**n1
                                        yield 0, subst3
                            if len(subjects15) >= 1:
                                tmp32 = []
                                tmp32.append(subjects15.popleft())
                                while True:
                                    if len(tmp32) > 1:
                                        tmp33 = create_operation_expression(associative1, tmp32)
                                    elif len(tmp32) == 1:
                                        tmp33 = tmp32[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable('i2.2.2.2', tmp33)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 47960
                                        if len(subjects15) == 0:
                                            pass
                                            # State 47961
                                            if len(subjects) == 0:
                                                pass
                                                # 0: (x*b + a)**n1
                                                yield 0, subst3
                                    if len(subjects15) == 0:
                                        break
                                    tmp32.append(subjects15.popleft())
                                subjects15.extendleft(reversed(tmp32))
                        if pattern_index == 1:
                            pass
                            # State 48794
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.2.2', 1)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 48795
                                if len(subjects15) == 0:
                                    pass
                                    # State 48796
                                    if len(subjects) == 0:
                                        pass
                                        # 2: (x*b + a)**n1
                                        yield 2, subst3
                            if len(subjects15) >= 1:
                                tmp36 = []
                                tmp36.append(subjects15.popleft())
                                while True:
                                    if len(tmp36) > 1:
                                        tmp37 = create_operation_expression(associative1, tmp36)
                                    elif len(tmp36) == 1:
                                        tmp37 = tmp36[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable('i2.2.2.2', tmp37)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 48795
                                        if len(subjects15) == 0:
                                            pass
                                            # State 48796
                                            if len(subjects) == 0:
                                                pass
                                                # 2: (x*b + a)**n1
                                                yield 2, subst3
                                    if len(subjects15) == 0:
                                        break
                                    tmp36.append(subjects15.popleft())
                                subjects15.extendleft(reversed(tmp36))
                    subjects15.appendleft(tmp28)
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.2.2.2.0_1', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 47972
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.2.1.0_1', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 47973
                    if len(subjects15) >= 1:
                        tmp41 = subjects15.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.2.1.0', tmp41)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 47974
                            if len(subjects15) >= 1:
                                tmp43 = subjects15.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.2.2.2_1', tmp43)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 47975
                                    if len(subjects15) == 0:
                                        pass
                                        # State 47976
                                        if len(subjects) == 0:
                                            pass
                                            # 1: (x*d + c)**n2
                                            yield 1, subst4
                                subjects15.appendleft(tmp43)
                        subjects15.appendleft(tmp41)
                    if len(subjects15) >= 1:
                        tmp45 = subjects15.popleft()
                        subst3 = Substitution(subst2)
                        try:
                            subst3.try_add_variable('i2.2.1.1', tmp45)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 48802
                            if len(subjects15) >= 1:
                                tmp47 = subjects15.popleft()
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.2.2.2_1', tmp47)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 48803
                                    if len(subjects15) == 0:
                                        pass
                                        # State 48804
                                        if len(subjects) == 0:
                                            pass
                                            # 3: (x*d + c)**n2
                                            yield 3, subst4
                                subjects15.appendleft(tmp47)
                        subjects15.appendleft(tmp45)
                if len(subjects15) >= 1 and isinstance(subjects15[0], Mul):
                    tmp49 = subjects15.popleft()
                    associative1 = tmp49
                    associative_type1 = type(tmp49)
                    subjects50 = deque(tmp49._args)
                    matcher = CommutativeMatcher47978.get()
                    tmp51 = subjects50
                    subjects50 = []
                    for s in tmp51:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp51, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 47979
                            if len(subjects15) >= 1:
                                tmp52 = []
                                tmp52.append(subjects15.popleft())
                                while True:
                                    if len(tmp52) > 1:
                                        tmp53 = create_operation_expression(associative1, tmp52)
                                    elif len(tmp52) == 1:
                                        tmp53 = tmp52[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable('i2.2.2.2_1', tmp53)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 47980
                                        if len(subjects15) == 0:
                                            pass
                                            # State 47981
                                            if len(subjects) == 0:
                                                pass
                                                # 1: (x*d + c)**n2
                                                yield 1, subst3
                                    if len(subjects15) == 0:
                                        break
                                    tmp52.append(subjects15.popleft())
                                subjects15.extendleft(reversed(tmp52))
                        if pattern_index == 1:
                            pass
                            # State 48805
                            if len(subjects15) >= 1:
                                tmp55 = []
                                tmp55.append(subjects15.popleft())
                                while True:
                                    if len(tmp55) > 1:
                                        tmp56 = create_operation_expression(associative1, tmp55)
                                    elif len(tmp55) == 1:
                                        tmp56 = tmp55[0]
                                    else:
                                        assert False, "Unreachable"
                                    subst3 = Substitution(subst2)
                                    try:
                                        subst3.try_add_variable('i2.2.2.2_1', tmp56)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 48806
                                        if len(subjects15) == 0:
                                            pass
                                            # State 48807
                                            if len(subjects) == 0:
                                                pass
                                                # 3: (x*d + c)**n2
                                                yield 3, subst3
                                    if len(subjects15) == 0:
                                        break
                                    tmp55.append(subjects15.popleft())
                                subjects15.extendleft(reversed(tmp55))
                    subjects15.appendleft(tmp49)
            if len(subjects15) >= 1 and isinstance(subjects15[0], Add):
                tmp58 = subjects15.popleft()
                associative1 = tmp58
                associative_type1 = type(tmp58)
                subjects59 = deque(tmp58._args)
                matcher = CommutativeMatcher47963.get()
                tmp60 = subjects59
                subjects59 = []
                for s in tmp60:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp60, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 47969
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 47970
                            if len(subjects15) == 0:
                                pass
                                # State 47971
                                if len(subjects) == 0:
                                    pass
                                    # 0: (x*b + a)**n1
                                    yield 0, subst2
                        if len(subjects15) >= 1:
                            tmp62 = []
                            tmp62.append(subjects15.popleft())
                            while True:
                                if len(tmp62) > 1:
                                    tmp63 = create_operation_expression(associative1, tmp62)
                                elif len(tmp62) == 1:
                                    tmp63 = tmp62[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i2.2.2.2', tmp63)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 47970
                                    if len(subjects15) == 0:
                                        pass
                                        # State 47971
                                        if len(subjects) == 0:
                                            pass
                                            # 0: (x*b + a)**n1
                                            yield 0, subst2
                                if len(subjects15) == 0:
                                    break
                                tmp62.append(subjects15.popleft())
                            subjects15.extendleft(reversed(tmp62))
                    if pattern_index == 1:
                        pass
                        # State 47985
                        if len(subjects15) >= 1:
                            tmp65 = []
                            tmp65.append(subjects15.popleft())
                            while True:
                                if len(tmp65) > 1:
                                    tmp66 = create_operation_expression(associative1, tmp65)
                                elif len(tmp65) == 1:
                                    tmp66 = tmp65[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i2.2.2.2_1', tmp66)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 47986
                                    if len(subjects15) == 0:
                                        pass
                                        # State 47987
                                        if len(subjects) == 0:
                                            pass
                                            # 1: (x*d + c)**n2
                                            yield 1, subst2
                                if len(subjects15) == 0:
                                    break
                                tmp65.append(subjects15.popleft())
                            subjects15.extendleft(reversed(tmp65))
                    if pattern_index == 2:
                        pass
                        # State 48799
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.2.2', 1)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 48800
                            if len(subjects15) == 0:
                                pass
                                # State 48801
                                if len(subjects) == 0:
                                    pass
                                    # 2: (x*b + a)**n1
                                    yield 2, subst2
                        if len(subjects15) >= 1:
                            tmp69 = []
                            tmp69.append(subjects15.popleft())
                            while True:
                                if len(tmp69) > 1:
                                    tmp70 = create_operation_expression(associative1, tmp69)
                                elif len(tmp69) == 1:
                                    tmp70 = tmp69[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i2.2.2.2', tmp70)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 48800
                                    if len(subjects15) == 0:
                                        pass
                                        # State 48801
                                        if len(subjects) == 0:
                                            pass
                                            # 2: (x*b + a)**n1
                                            yield 2, subst2
                                if len(subjects15) == 0:
                                    break
                                tmp69.append(subjects15.popleft())
                            subjects15.extendleft(reversed(tmp69))
                    if pattern_index == 3:
                        pass
                        # State 48810
                        if len(subjects15) >= 1:
                            tmp72 = []
                            tmp72.append(subjects15.popleft())
                            while True:
                                if len(tmp72) > 1:
                                    tmp73 = create_operation_expression(associative1, tmp72)
                                elif len(tmp72) == 1:
                                    tmp73 = tmp72[0]
                                else:
                                    assert False, "Unreachable"
                                subst2 = Substitution(subst1)
                                try:
                                    subst2.try_add_variable('i2.2.2.2_1', tmp73)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 48811
                                    if len(subjects15) == 0:
                                        pass
                                        # State 48812
                                        if len(subjects) == 0:
                                            pass
                                            # 3: (x*d + c)**n2
                                            yield 3, subst2
                                if len(subjects15) == 0:
                                    break
                                tmp72.append(subjects15.popleft())
                            subjects15.extendleft(reversed(tmp72))
                subjects15.appendleft(tmp58)
            subjects.appendleft(tmp14)
        return
        yield
class CommutativeMatcher123997(CommutativeMatcher):
    _instance = None
    patterns = {
    0: (0, Multiset({0: 1}), [
      (VariableWithCount('i2.2.1.2.1.0', 1, 1, S(1)), Mul)
]),
    1: (1, Multiset({1: 1}), [
      (VariableWithCount('i2.2.1.2.1.0', 1, 1, S(1)), Mul)
]),
    2: (2, Multiset({2: 1}), [
      (VariableWithCount('i2.2.1.2.1.0', 1, 1, S(1)), Mul)
])
}
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher123997._instance is None:
            CommutativeMatcher123997._instance = CommutativeMatcher123997()
        return CommutativeMatcher123997._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 123996
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 123998
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.0_1', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 123999
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.1.2', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 124000
                            if len(subjects2) == 0:
                                pass
                                # State 124001
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**n
                                    yield 0, subst2
                        subjects2.appendleft(tmp5)
                subjects2.appendleft(tmp3)
            if len(subjects2) >= 1:
                tmp7 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.0', tmp7)
                except ValueError:
                    pass
                else:
                    pass
                    # State 124615
                    if len(subjects2) >= 1:
                        tmp9 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.1.2', tmp9)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 124616
                            if len(subjects2) == 0:
                                pass
                                # State 124617
                                if len(subjects) == 0:
                                    pass
                                    # 1: x**n
                                    yield 1, subst2
                        subjects2.appendleft(tmp9)
                subjects2.appendleft(tmp7)
            if len(subjects2) >= 1:
                tmp11 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.2.1.1', tmp11)
                except ValueError:
                    pass
                else:
                    pass
                    # State 125039
                    if len(subjects2) >= 1:
                        tmp13 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.1.2', tmp13)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 125040
                            if len(subjects2) == 0:
                                pass
                                # State 125041
                                if len(subjects) == 0:
                                    pass
                                    # 2: x**n
                                    yield 2, subst2
                        subjects2.appendleft(tmp13)
                subjects2.appendleft(tmp11)
            subjects.appendleft(tmp1)
        return
        yield
Example #21
0
class CommutativeMatcher133344(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        3: (3, Multiset({3: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        4: (4, Multiset({4: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        5: (5, Multiset({5: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)]),
        6: (6, Multiset({6: 1}), [(VariableWithCount('i4.1.2.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher133344._instance is None:
            CommutativeMatcher133344._instance = CommutativeMatcher133344()
        return CommutativeMatcher133344._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 133343
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i4.1.2.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 133345
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i4.1.2.1', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 133346
                    if len(subjects) == 0:
                        pass
                        # 0: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1876)
                        yield 0, subst2
                        # 1: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1877)
                        yield 1, subst2
                        # 2: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1878)
                        yield 2, subst2
                        # 3: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1880)
                        yield 3, subst2
                        # 4: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1881)
                        yield 4, subst2
                        # 5: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1880)
                        yield 5, subst2
                        # 6: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1887)
                        yield 6, subst2
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp4 = subjects.popleft()
            subjects5 = deque(tmp4._args)
            # State 133347
            if len(subjects5) >= 1:
                tmp6 = subjects5.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i4.1.2.1', tmp6)
                except ValueError:
                    pass
                else:
                    pass
                    # State 133348
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i4.1.2.2', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 133349
                        if len(subjects5) == 0:
                            pass
                            # State 133350
                            if len(subjects) == 0:
                                pass
                                # 0: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1876)
                                yield 0, subst2
                                # 1: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1877)
                                yield 1, subst2
                                # 2: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1878)
                                yield 2, subst2
                                # 3: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1880)
                                yield 3, subst2
                                # 4: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1881)
                                yield 4, subst2
                                # 5: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1880)
                                yield 5, subst2
                                # 6: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1887)
                                yield 6, subst2
                    if len(subjects5) >= 1:
                        tmp9 = subjects5.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i4.1.2.2', tmp9)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 133349
                            if len(subjects5) == 0:
                                pass
                                # State 133350
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1876)
                                    yield 0, subst2
                                    # 1: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1877)
                                    yield 1, subst2
                                    # 2: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1878)
                                    yield 2, subst2
                                    # 3: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1880)
                                    yield 3, subst2
                                    # 4: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1881)
                                    yield 4, subst2
                                    # 5: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f5) and (cons_f1880)
                                    yield 5, subst2
                                    # 6: x**n /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f1887)
                                    yield 6, subst2
                        subjects5.appendleft(tmp9)
                subjects5.appendleft(tmp6)
            subjects.appendleft(tmp4)
        return
        yield
class CommutativeMatcher56993(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.4.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher56993._instance is None:
            CommutativeMatcher56993._instance = CommutativeMatcher56993()
        return CommutativeMatcher56993._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 56992
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 56994
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 56995
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.4.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 76153
            if len(subjects) >= 1:
                tmp5 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.4.1.0', tmp5)
                except ValueError:
                    pass
                else:
                    pass
                    # State 76154
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst2
                subjects.appendleft(tmp5)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp7 = subjects.popleft()
            associative1 = tmp7
            associative_type1 = type(tmp7)
            subjects8 = deque(tmp7._args)
            matcher = CommutativeMatcher56997.get()
            tmp9 = subjects8
            subjects8 = []
            for s in tmp9:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp9, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 56998
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 76155
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst1
            subjects.appendleft(tmp7)
        return
        yield
Example #23
0
class CommutativeMatcher3798(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({}), [(VariableWithCount('i2.2.1.0', 1, 1, None), Mul),
                              (VariableWithCount('i2.2.1.0_4', 1, 1,
                                                 S(1)), Mul)]),
        1: (1, Multiset({0: 1}), [(VariableWithCount('i2.2.1.0_4', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({}), [(VariableWithCount('i2.2.1.0', 1, 1, None), Mul),
                              (VariableWithCount('i2.2.1.0_5', 1, 1,
                                                 S(1)), Mul)]),
        3: (3, Multiset({1: 1}), [(VariableWithCount('i2.2.1.0_1', 1, 1,
                                                     S(1)), Mul)]),
        4: (4, Multiset({2: 1}), [(VariableWithCount('i2.2.1.0_2', 1, 1,
                                                     S(1)), Mul)]),
        5: (5, Multiset({3: 1}), [(VariableWithCount('i2.2.1.0_2', 1, 1,
                                                     S(1)), Mul)]),
        6: (6, Multiset({4: 1}), [(VariableWithCount('i2.2.1.0_2', 1, 1,
                                                     S(1)), Mul)]),
        7: (7, Multiset({5: 1}), [(VariableWithCount('i2.2.1.0_2', 1, 1,
                                                     S(1)), Mul)]),
        8: (8, Multiset({5: 1}), [(VariableWithCount('i2.2.1.0_3', 1, 1,
                                                     S(1)), Mul)]),
        9:
        (9, Multiset({}), [(VariableWithCount('i2.2.1.0_6', 1, 1, None), Mul),
                           (VariableWithCount('i2.2.1.0_7', 1, 1, S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher3798._instance is None:
            CommutativeMatcher3798._instance = CommutativeMatcher3798()
        return CommutativeMatcher3798._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 3797
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 5890
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.0', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 5891
                    if len(subjects2) >= 1 and subjects2[0] == Integer(2):
                        tmp5 = subjects2.popleft()
                        # State 5892
                        if len(subjects2) == 0:
                            pass
                            # State 5893
                            if len(subjects) == 0:
                                pass
                                # 0: v**2
                                yield 0, subst1
                        subjects2.appendleft(tmp5)
                subjects2.appendleft(tmp3)
            if len(subjects2) >= 1:
                tmp6 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1', tmp6)
                except ValueError:
                    pass
                else:
                    pass
                    # State 7913
                    if len(subjects2) >= 1:
                        tmp8 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.2', tmp8)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 7914
                            if len(subjects2) == 0:
                                pass
                                # State 7915
                                if len(subjects) == 0:
                                    pass
                                    # 1: x**n
                                    yield 1, subst2
                        subjects2.appendleft(tmp8)
                subjects2.appendleft(tmp6)
            if len(subjects2) >= 1:
                tmp10 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.0', tmp10)
                except ValueError:
                    pass
                else:
                    pass
                    # State 7939
                    if len(subjects2) >= 1:
                        tmp12 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2', tmp12)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 7940
                            if len(subjects2) == 0:
                                pass
                                # State 7941
                                if len(subjects) == 0:
                                    pass
                                    # 2: x**n
                                    yield 2, subst2
                        subjects2.appendleft(tmp12)
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2_1', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 8104
                        if len(subjects2) == 0:
                            pass
                            # State 8105
                            if len(subjects) == 0:
                                pass
                                # 5: x**n2
                                yield 5, subst2
                    if len(subjects2) >= 1:
                        tmp15 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2_1', tmp15)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 8104
                            if len(subjects2) == 0:
                                pass
                                # State 8105
                                if len(subjects) == 0:
                                    pass
                                    # 5: x**n2
                                    yield 5, subst2
                        subjects2.appendleft(tmp15)
                subjects2.appendleft(tmp10)
            if len(subjects2) >= 1:
                tmp17 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.0_1', tmp17)
                except ValueError:
                    pass
                else:
                    pass
                    # State 7969
                    if len(subjects2) >= 1:
                        tmp19 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2', tmp19)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 7970
                            if len(subjects2) == 0:
                                pass
                                # State 7971
                                if len(subjects) == 0:
                                    pass
                                    # 3: x**n
                                    yield 3, subst2
                        subjects2.appendleft(tmp19)
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2_1', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 8077
                        if len(subjects2) == 0:
                            pass
                            # State 8078
                            if len(subjects) == 0:
                                pass
                                # 4: x**n
                                yield 4, subst2
                    if len(subjects2) >= 1:
                        tmp22 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2_1', tmp22)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 8077
                            if len(subjects2) == 0:
                                pass
                                # State 8078
                                if len(subjects) == 0:
                                    pass
                                    # 4: x**n
                                    yield 4, subst2
                        subjects2.appendleft(tmp22)
                subjects2.appendleft(tmp17)
            subjects.appendleft(tmp1)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 8075
            if len(subjects) >= 1:
                tmp25 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.0_1', tmp25)
                except ValueError:
                    pass
                else:
                    pass
                    # State 8076
                    if len(subjects) == 0:
                        pass
                        # 4: x**n
                        yield 4, subst2
                subjects.appendleft(tmp25)
            if len(subjects) >= 1:
                tmp27 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.0', tmp27)
                except ValueError:
                    pass
                else:
                    pass
                    # State 8103
                    if len(subjects) == 0:
                        pass
                        # 5: x**n2
                        yield 5, subst2
                subjects.appendleft(tmp27)
        return
        yield
class CommutativeMatcher120321(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.3.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher120321._instance is None:
            CommutativeMatcher120321._instance = CommutativeMatcher120321()
        return CommutativeMatcher120321._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 120320
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 120322
            subst1 = Substitution(subst0)
            try:
                subst1.try_add_variable('i2.3.2.0', S(0))
            except ValueError:
                pass
            else:
                pass
                # State 120323
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.2.1.0', S(1))
                except ValueError:
                    pass
                else:
                    pass
                    # State 120324
                    subst3 = Substitution(subst2)
                    try:
                        subst3.try_add_variable('i2.3.2.1.2', S(1))
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 120325
                        if len(subjects2) >= 1:
                            tmp6 = subjects2.popleft()
                            subst4 = Substitution(subst3)
                            try:
                                subst4.try_add_variable('i2.3.2.1.1', tmp6)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 120326
                                if len(subjects2
                                       ) >= 1 and subjects2[0] == Integer(-1):
                                    tmp8 = subjects2.popleft()
                                    # State 120327
                                    if len(subjects2) == 0:
                                        pass
                                        # State 120328
                                        if len(subjects) == 0:
                                            pass
                                            # 0: 1/(a + b*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f19) and (cons_f1768)
                                            yield 0, subst4
                                    subjects2.appendleft(tmp8)
                            subjects2.appendleft(tmp6)
                    if len(subjects2) >= 1 and isinstance(subjects2[0], Pow):
                        tmp9 = subjects2.popleft()
                        subjects10 = deque(tmp9._args)
                        # State 120329
                        if len(subjects10) >= 1:
                            tmp11 = subjects10.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.3.2.1.1', tmp11)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 120330
                                subst4 = Substitution(subst3)
                                try:
                                    subst4.try_add_variable('i2.3.2.1.2', 1)
                                except ValueError:
                                    pass
                                else:
                                    pass
                                    # State 120331
                                    if len(subjects10) == 0:
                                        pass
                                        # State 120332
                                        if len(subjects2) >= 1 and subjects2[
                                                0] == Integer(-1):
                                            tmp14 = subjects2.popleft()
                                            # State 120333
                                            if len(subjects2) == 0:
                                                pass
                                                # State 120334
                                                if len(subjects) == 0:
                                                    pass
                                                    # 0: 1/(a + b*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f19) and (cons_f1768)
                                                    yield 0, subst4
                                            subjects2.appendleft(tmp14)
                                if len(subjects10) >= 1:
                                    tmp15 = subjects10.popleft()
                                    subst4 = Substitution(subst3)
                                    try:
                                        subst4.try_add_variable(
                                            'i2.3.2.1.2', tmp15)
                                    except ValueError:
                                        pass
                                    else:
                                        pass
                                        # State 120331
                                        if len(subjects10) == 0:
                                            pass
                                            # State 120332
                                            if len(subjects2
                                                   ) >= 1 and subjects2[
                                                       0] == Integer(-1):
                                                tmp17 = subjects2.popleft()
                                                # State 120333
                                                if len(subjects2) == 0:
                                                    pass
                                                    # State 120334
                                                    if len(subjects) == 0:
                                                        pass
                                                        # 0: 1/(a + b*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f19) and (cons_f1768)
                                                        yield 0, subst4
                                                subjects2.appendleft(tmp17)
                                    subjects10.appendleft(tmp15)
                            subjects10.appendleft(tmp11)
                        subjects2.appendleft(tmp9)
                if len(subjects2) >= 1 and isinstance(subjects2[0], Mul):
                    tmp18 = subjects2.popleft()
                    associative1 = tmp18
                    associative_type1 = type(tmp18)
                    subjects19 = deque(tmp18._args)
                    matcher = CommutativeMatcher120336.get()
                    tmp20 = subjects19
                    subjects19 = []
                    for s in tmp20:
                        matcher.add_subject(s)
                    for pattern_index, subst2 in matcher.match(tmp20, subst1):
                        pass
                        if pattern_index == 0:
                            pass
                            # State 120343
                            if len(subjects2) >= 1 and subjects2[0] == Integer(
                                    -1):
                                tmp21 = subjects2.popleft()
                                # State 120344
                                if len(subjects2) == 0:
                                    pass
                                    # State 120345
                                    if len(subjects) == 0:
                                        pass
                                        # 0: 1/(a + b*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f19) and (cons_f1768)
                                        yield 0, subst2
                                subjects2.appendleft(tmp21)
                    subjects2.appendleft(tmp18)
            if len(subjects2) >= 1 and isinstance(subjects2[0], Add):
                tmp22 = subjects2.popleft()
                associative1 = tmp22
                associative_type1 = type(tmp22)
                subjects23 = deque(tmp22._args)
                matcher = CommutativeMatcher120347.get()
                tmp24 = subjects23
                subjects23 = []
                for s in tmp24:
                    matcher.add_subject(s)
                for pattern_index, subst1 in matcher.match(tmp24, subst0):
                    pass
                    if pattern_index == 0:
                        pass
                        # State 120364
                        if len(subjects2) >= 1 and subjects2[0] == Integer(-1):
                            tmp25 = subjects2.popleft()
                            # State 120365
                            if len(subjects2) == 0:
                                pass
                                # State 120366
                                if len(subjects) == 0:
                                    pass
                                    # 0: 1/(a + b*x**n) /; (cons_f2) and (cons_f3) and (cons_f8) and (cons_f4) and (cons_f19) and (cons_f1768)
                                    yield 0, subst1
                            subjects2.appendleft(tmp25)
                subjects2.appendleft(tmp22)
            subjects.appendleft(tmp1)
        return
        yield
Example #25
0
class CommutativeMatcher116916(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.3.2.1.0', 1, 1,
                                                     S(1)), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher116916._instance is None:
            CommutativeMatcher116916._instance = CommutativeMatcher116916()
        return CommutativeMatcher116916._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 116915
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.3.2.1.2', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 116917
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.2.1.1', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 116918
                    if len(subjects) == 0:
                        pass
                        # 0: x**n
                        yield 0, subst2
                subjects.appendleft(tmp2)
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp4 = subjects.popleft()
            subjects5 = deque(tmp4._args)
            # State 116919
            if len(subjects5) >= 1:
                tmp6 = subjects5.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.3.2.1.1', tmp6)
                except ValueError:
                    pass
                else:
                    pass
                    # State 116920
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.3.2.1.2', 1)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 116921
                        if len(subjects5) == 0:
                            pass
                            # State 116922
                            if len(subjects) == 0:
                                pass
                                # 0: x**n
                                yield 0, subst2
                    if len(subjects5) >= 1:
                        tmp9 = subjects5.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.3.2.1.2', tmp9)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 116921
                            if len(subjects5) == 0:
                                pass
                                # State 116922
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**n
                                    yield 0, subst2
                        subjects5.appendleft(tmp9)
                subjects5.appendleft(tmp6)
            subjects.appendleft(tmp4)
        return
        yield
Example #26
0
class CommutativeMatcher24792(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.1.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.1.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        2: (2, Multiset({1: 1}), [(VariableWithCount('i2.1.1.2.2.2.0', 1, 1,
                                                     None), Add)]),
        3: (3, Multiset({2: 1}), [(VariableWithCount('i2.1.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher24792._instance is None:
            CommutativeMatcher24792._instance = CommutativeMatcher24792()
        return CommutativeMatcher24792._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 24791
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.1.1.2.2.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 24793
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 24794
                    if len(subjects) == 0:
                        pass
                        # 0: f*x
                        yield 0, subst2
                subjects.appendleft(tmp2)
            if len(subjects) >= 1:
                tmp4 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.1', tmp4)
                except ValueError:
                    pass
                else:
                    pass
                    # State 26892
                    if len(subjects) == 0:
                        pass
                        # 1: f*x
                        yield 1, subst2
                subjects.appendleft(tmp4)
            if len(subjects) >= 1:
                tmp6 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.3.1.0', tmp6)
                except ValueError:
                    pass
                else:
                    pass
                    # State 27959
                    if len(subjects) == 0:
                        pass
                        # 2: f*x
                        yield 2, subst2
                subjects.appendleft(tmp6)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp8 = subjects.popleft()
            associative1 = tmp8
            associative_type1 = type(tmp8)
            subjects9 = deque(tmp8._args)
            matcher = CommutativeMatcher24796.get()
            tmp10 = subjects9
            subjects9 = []
            for s in tmp10:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp10, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 24797
                    if len(subjects) == 0:
                        pass
                        # 0: f*x
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 26893
                    if len(subjects) == 0:
                        pass
                        # 1: f*x
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 27960
                    if len(subjects) == 0:
                        pass
                        # 2: f*x
                        yield 2, subst1
            subjects.appendleft(tmp8)
        return
        yield
Example #27
0
class CommutativeMatcher21709(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.1.2.2.2.0', 1, 1,
                                                     None), Add)]),
        2: (2, Multiset({1: 1}), [(VariableWithCount('i2.2.1.2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        3: (3, Multiset({
            2: 1,
            3: 1
        }), [(VariableWithCount('i2.2.1.2.2.2.0', 1, 1, S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher21709._instance is None:
            CommutativeMatcher21709._instance = CommutativeMatcher21709()
        return CommutativeMatcher21709._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 21708
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 21710
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 21711
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
            if len(subjects) >= 1:
                tmp4 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.2.2.1.1', tmp4)
                except ValueError:
                    pass
                else:
                    pass
                    # State 44660
                    if len(subjects) == 0:
                        pass
                        # 3: f*x
                        yield 3, subst2
                subjects.appendleft(tmp4)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.2.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 29761
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp7 = subjects.popleft()
                subjects8 = deque(tmp7._args)
                # State 29762
                if len(subjects8) >= 1:
                    tmp9 = subjects8.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2.2.2.1.1', tmp9)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 29763
                        if len(subjects8) >= 1:
                            tmp11 = subjects8.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable(
                                    'i2.2.1.2.2.2.1.2', tmp11)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 29764
                                if len(subjects8) == 0:
                                    pass
                                    # State 29765
                                    if len(subjects) == 0:
                                        pass
                                        # 1: f*x**m
                                        yield 1, subst3
                            subjects8.appendleft(tmp11)
                        if len(subjects8) >= 1 and subjects8[0] == Integer(2):
                            tmp13 = subjects8.popleft()
                            # State 44655
                            if len(subjects8) == 0:
                                pass
                                # State 44656
                                if len(subjects) == 0:
                                    pass
                                    # 2: g*x**2
                                    yield 2, subst2
                            subjects8.appendleft(tmp13)
                    subjects8.appendleft(tmp9)
                subjects.appendleft(tmp7)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp14 = subjects.popleft()
            associative1 = tmp14
            associative_type1 = type(tmp14)
            subjects15 = deque(tmp14._args)
            matcher = CommutativeMatcher21713.get()
            tmp16 = subjects15
            subjects15 = []
            for s in tmp16:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp16, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 21714
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 29770
                    if len(subjects) == 0:
                        pass
                        # 1: f*x**m
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 44659
                    if len(subjects) == 0:
                        pass
                        # 2: g*x**2
                        yield 2, subst1
                if pattern_index == 3:
                    pass
                    # State 44661
                    if len(subjects) == 0:
                        pass
                        # 3: f*x
                        yield 3, subst1
            subjects.appendleft(tmp14)
        return
        yield
Example #28
0
class CommutativeMatcher58908(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({0: 1}), [(VariableWithCount('i2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        1: (1, Multiset({1: 1}), [(VariableWithCount('i2.2.3.0', 1, 1,
                                                     S(0)), Add)]),
        2: (2, Multiset({2: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        3: (3, Multiset({3: 1}), [(VariableWithCount('i2.2.2.2.0', 1, 1,
                                                     S(0)), Add)]),
        4: (4, Multiset({4: 1}), [(VariableWithCount('i2.2.1.3.0', 1, 1,
                                                     S(0)), Add)]),
        5: (5, Multiset({5: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        6: (6, Multiset({6: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        7: (7, Multiset({7: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)]),
        8: (8, Multiset({8: 1}), [(VariableWithCount('i2.2.1.2.0', 1, 1,
                                                     S(0)), Add)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher58908._instance is None:
            CommutativeMatcher58908._instance = CommutativeMatcher58908()
        return CommutativeMatcher58908._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 58907
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 58909
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 58910
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 59101
            if len(subjects) >= 1:
                tmp5 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.3.1.0', tmp5)
                except ValueError:
                    pass
                else:
                    pass
                    # State 59102
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst2
                subjects.appendleft(tmp5)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 60241
            if len(subjects) >= 1:
                tmp8 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.1.0', tmp8)
                except ValueError:
                    pass
                else:
                    pass
                    # State 60242
                    if len(subjects) == 0:
                        pass
                        # 2: x*d
                        yield 2, subst2
                subjects.appendleft(tmp8)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.2.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 61740
            if len(subjects) >= 1:
                tmp11 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.2.2.1.0', tmp11)
                except ValueError:
                    pass
                else:
                    pass
                    # State 61741
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst2
                subjects.appendleft(tmp11)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.3.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 62101
            if len(subjects) >= 1:
                tmp14 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.3.1.0', tmp14)
                except ValueError:
                    pass
                else:
                    pass
                    # State 62102
                    if len(subjects) == 0:
                        pass
                        # 4: x*f
                        yield 4, subst2
                subjects.appendleft(tmp14)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 74386
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp17 = subjects.popleft()
                subjects18 = deque(tmp17._args)
                # State 74387
                if len(subjects18) >= 1:
                    tmp19 = subjects18.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.0_1', tmp19)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 74388
                        if len(subjects18) >= 1:
                            tmp21 = subjects18.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.1.2', tmp21)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 74389
                                if len(subjects18) == 0:
                                    pass
                                    # State 74390
                                    if len(subjects) == 0:
                                        pass
                                        # 5: x**n*d
                                        yield 5, subst3
                            subjects18.appendleft(tmp21)
                    subjects18.appendleft(tmp19)
                if len(subjects18) >= 1:
                    tmp23 = subjects18.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.0', tmp23)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 74920
                        if len(subjects18) >= 1:
                            tmp25 = subjects18.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.1.2', tmp25)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 74921
                                if len(subjects18) == 0:
                                    pass
                                    # State 74922
                                    if len(subjects) == 0:
                                        pass
                                        # 6: x**n*d
                                        yield 6, subst3
                            subjects18.appendleft(tmp25)
                    subjects18.appendleft(tmp23)
                if len(subjects18) >= 1:
                    tmp27 = subjects18.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2.1.1', tmp27)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 75307
                        if len(subjects18) >= 1:
                            tmp29 = subjects18.popleft()
                            subst3 = Substitution(subst2)
                            try:
                                subst3.try_add_variable('i2.2.1.2.1.2', tmp29)
                            except ValueError:
                                pass
                            else:
                                pass
                                # State 75308
                                if len(subjects18) == 0:
                                    pass
                                    # State 75309
                                    if len(subjects) == 0:
                                        pass
                                        # 7: d*x**n
                                        yield 7, subst3
                            subjects18.appendleft(tmp29)
                    subjects18.appendleft(tmp27)
                subjects.appendleft(tmp17)
            if len(subjects) >= 1:
                tmp31 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.0', tmp31)
                except ValueError:
                    pass
                else:
                    pass
                    # State 107259
                    if len(subjects) == 0:
                        pass
                        # 8: x*d
                        yield 8, subst2
                subjects.appendleft(tmp31)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp33 = subjects.popleft()
            associative1 = tmp33
            associative_type1 = type(tmp33)
            subjects34 = deque(tmp33._args)
            matcher = CommutativeMatcher58912.get()
            tmp35 = subjects34
            subjects34 = []
            for s in tmp35:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp35, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 58913
                    if len(subjects) == 0:
                        pass
                        # 0: x*f
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 59103
                    if len(subjects) == 0:
                        pass
                        # 1: x*f
                        yield 1, subst1
                if pattern_index == 2:
                    pass
                    # State 60243
                    if len(subjects) == 0:
                        pass
                        # 2: x*d
                        yield 2, subst1
                if pattern_index == 3:
                    pass
                    # State 61742
                    if len(subjects) == 0:
                        pass
                        # 3: x*f
                        yield 3, subst1
                if pattern_index == 4:
                    pass
                    # State 62103
                    if len(subjects) == 0:
                        pass
                        # 4: x*f
                        yield 4, subst1
                if pattern_index == 5:
                    pass
                    # State 74395
                    if len(subjects) == 0:
                        pass
                        # 5: x**n*d
                        yield 5, subst1
                if pattern_index == 6:
                    pass
                    # State 74926
                    if len(subjects) == 0:
                        pass
                        # 6: x**n*d
                        yield 6, subst1
                if pattern_index == 7:
                    pass
                    # State 75313
                    if len(subjects) == 0:
                        pass
                        # 7: d*x**n
                        yield 7, subst1
                if pattern_index == 8:
                    pass
                    # State 107260
                    if len(subjects) == 0:
                        pass
                        # 8: x*d
                        yield 8, subst1
            subjects.appendleft(tmp33)
        return
        yield
class CommutativeMatcher54112(CommutativeMatcher):
    _instance = None
    patterns = {
    0: (0, Multiset({0: 1}), [
      (VariableWithCount('i2.2.1.2.0', 1, 1, S(0)), Add)
]),
    1: (1, Multiset({1: 1}), [
      (VariableWithCount('i2.1.1.2.0', 1, 1, None), Add)
])
}
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Add
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher54112._instance is None:
            CommutativeMatcher54112._instance = CommutativeMatcher54112()
        return CommutativeMatcher54112._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 54111
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.2.1.2.1.0_1', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 54113
            if len(subjects) >= 1:
                tmp2 = subjects.popleft()
                subst2 = Substitution(subst1)
                try:
                    subst2.try_add_variable('i2.2.1.2.1.0', tmp2)
                except ValueError:
                    pass
                else:
                    pass
                    # State 54114
                    if len(subjects) == 0:
                        pass
                        # 0: x*d
                        yield 0, subst2
                subjects.appendleft(tmp2)
        subst1 = Substitution(subst0)
        try:
            subst1.try_add_variable('i2.1.1.2.1.0', S(1))
        except ValueError:
            pass
        else:
            pass
            # State 114246
            if len(subjects) >= 1 and isinstance(subjects[0], Pow):
                tmp5 = subjects.popleft()
                subjects6 = deque(tmp5._args)
                # State 114247
                if len(subjects6) >= 1:
                    tmp7 = subjects6.popleft()
                    subst2 = Substitution(subst1)
                    try:
                        subst2.try_add_variable('i2.2.1.2.0', tmp7)
                    except ValueError:
                        pass
                    else:
                        pass
                        # State 114248
                        if len(subjects6) >= 1 and subjects6[0] == Integer(2):
                            tmp9 = subjects6.popleft()
                            # State 114249
                            if len(subjects6) == 0:
                                pass
                                # State 114250
                                if len(subjects) == 0:
                                    pass
                                    # 1: g*x**2
                                    yield 1, subst2
                            subjects6.appendleft(tmp9)
                    subjects6.appendleft(tmp7)
                subjects.appendleft(tmp5)
        if len(subjects) >= 1 and isinstance(subjects[0], Mul):
            tmp10 = subjects.popleft()
            associative1 = tmp10
            associative_type1 = type(tmp10)
            subjects11 = deque(tmp10._args)
            matcher = CommutativeMatcher54116.get()
            tmp12 = subjects11
            subjects11 = []
            for s in tmp12:
                matcher.add_subject(s)
            for pattern_index, subst1 in matcher.match(tmp12, subst0):
                pass
                if pattern_index == 0:
                    pass
                    # State 54117
                    if len(subjects) == 0:
                        pass
                        # 0: x*d
                        yield 0, subst1
                if pattern_index == 1:
                    pass
                    # State 114255
                    if len(subjects) == 0:
                        pass
                        # 1: g*x**2
                        yield 1, subst1
            subjects.appendleft(tmp10)
        return
        yield
class CommutativeMatcher21852(CommutativeMatcher):
    _instance = None
    patterns = {
        0: (0, Multiset({}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                 None), Mul),
                              (VariableWithCount('i2.2.1.2.2.2.1.0_1', 1, 1,
                                                 S(1)), Mul)]),
        1: (1, Multiset({0: 1}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                     S(1)), Mul)]),
        2: (2, Multiset({1: 1}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                     S(1)), Mul)]),
        3: (3, Multiset({2: 1}), [(VariableWithCount('i2.2.1.2.2.2.1.0', 1, 1,
                                                     S(1)), Mul)]),
        4: (4, Multiset({}), [(VariableWithCount('i2.2.1.2.2.2.1.0_1', 1, 1,
                                                 S(1)), Mul),
                              (VariableWithCount('i2.2.1.2.2.2.1.1', 1, 1,
                                                 None), Mul)])
    }
    subjects = {}
    subjects_by_id = {}
    bipartite = BipartiteGraph()
    associative = Mul
    max_optional_count = 1
    anonymous_patterns = set()

    def __init__(self):
        self.add_subject(None)

    @staticmethod
    def get():
        if CommutativeMatcher21852._instance is None:
            CommutativeMatcher21852._instance = CommutativeMatcher21852()
        return CommutativeMatcher21852._instance

    @staticmethod
    def get_match_iter(subject):
        subjects = deque([subject]) if subject is not None else deque()
        subst0 = Substitution()
        # State 21851
        if len(subjects) >= 1 and isinstance(subjects[0], Pow):
            tmp1 = subjects.popleft()
            subjects2 = deque(tmp1._args)
            # State 29849
            if len(subjects2) >= 1:
                tmp3 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.2.2.2.1.1', tmp3)
                except ValueError:
                    pass
                else:
                    pass
                    # State 29850
                    if len(subjects2) >= 1:
                        tmp5 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2.2.2.1.2', tmp5)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 29851
                            if len(subjects2) == 0:
                                pass
                                # State 29852
                                if len(subjects) == 0:
                                    pass
                                    # 0: x**m
                                    yield 0, subst2
                        subjects2.appendleft(tmp5)
                    if len(subjects2) >= 1 and subjects2[0] == Integer(2):
                        tmp7 = subjects2.popleft()
                        # State 44722
                        if len(subjects2) == 0:
                            pass
                            # State 44723
                            if len(subjects) == 0:
                                pass
                                # 2: x**2
                                yield 2, subst1
                        subjects2.appendleft(tmp7)
                subjects2.appendleft(tmp3)
            if len(subjects2) >= 1:
                tmp8 = subjects2.popleft()
                subst1 = Substitution(subst0)
                try:
                    subst1.try_add_variable('i2.2.1.1', tmp8)
                except ValueError:
                    pass
                else:
                    pass
                    # State 40088
                    if len(subjects2) >= 1:
                        tmp10 = subjects2.popleft()
                        subst2 = Substitution(subst1)
                        try:
                            subst2.try_add_variable('i2.2.1.2', tmp10)
                        except ValueError:
                            pass
                        else:
                            pass
                            # State 40089
                            if len(subjects2) == 0:
                                pass
                                # State 40090
                                if len(subjects) == 0:
                                    pass
                                    # 1: x**j
                                    yield 1, subst2
                        subjects2.appendleft(tmp10)
                subjects2.appendleft(tmp8)
            subjects.appendleft(tmp1)
        return
        yield