Пример #1
0
def test_rule():
    rule = wm.rule(inputs=[[1, 2]], outputs=[[1, 3]])
    assert rule.inputs[0][
        1] == 2, "Rule is populated with non-default constructor, using lists"

    rule = wm.rule(inputs=np.array([[1, 2]]), outputs=np.array([[1, 3]]))
    assert rule.outputs[0][
        1] == 3, "Rule is populated with non-default constructor, using np.arrays"
    print(rule)
Пример #2
0
def wm0():
    # Rule: {{x, y}, {x, z}} -> {{x, y}, {x, w}, {y, w}, {z, w}}
    rule = wm.rule(inputs=[[-1, -2], [-1, -3]],
                   outputs=[[-1, -2], [-1, -4], [-2, -4], [-3, -4]])
    initial_expressions = [[1, 2], [1, 3]]
    order_function = wm.matcher.ordering_function.RuleID
    order_direction = wm.matcher.ordering_direction.Normal
    ordering = [[order_function, order_direction]]
    random_seed = 0

    step_spec = wm.set.step_spec()
    step_spec.max_events = 100
    step_spec.max_generations_local = 100
    step_spec.max_final_atoms = 100000
    step_spec.max_final_atom_degree = 100000
    step_spec.max_final_expressions = 100000

    rules = [rule]
    wms = wm.set(rules=rules,
                 initial_expressions=initial_expressions,
                 ordering=ordering,
                 random_seed=random_seed)
    substitutions_made = wms.replace(step_spec)

    return [
        wms, rules, step_spec, [initial_expressions, ordering, random_seed]
    ]
Пример #3
0
def set_inputs_0():
    rule = wm.rule(inputs=[[-1, -2], [-2, -3]],
                   outputs=[[-1, -3], [-4, -2], [-1, -4]])
    initial_expressions = [[1, 2], [2, 3]]
    order_function = wm.matcher.ordering_function.RuleIndex
    order_direction = wm.matcher.ordering_direction.Normal
    ordering = [[order_function, order_direction]]
    random_seed = 0
    return [rule, initial_expressions, ordering, random_seed]
Пример #4
0
def test_matcher_constructor():
    rule = wm.rule(inputs=[[-1, -2], [-2, -3]],
                   outputs=[[-1, -3], [-4, -2], [-1, -4]])
    atoms_index = wm.atoms_index(a_dummy_get_atoms_vector_func)
    ordering_spec = [[
        wm.matcher.ordering_function.RuleIndex,
        wm.matcher.ordering_direction.Normal
    ]]
    matcher = wm.matcher(rules=[rule],
                         atoms_index=atoms_index,
                         get_atoms_vector=a_dummy_get_atoms_vector_func,
                         ordering=ordering_spec)
    print(matcher.all_matches())