Beispiel #1
0
 def test_circuits(self):
     f1 = read_truth_table(["00 00", "01 10", "10 01", "11 10"])
     lcs1 = {
         (0, 0): [([1, 2], +1)],
         (0, 1): [],
         (1, 0): [([1, 2], +1), ([2], -1)],
         (1, 1): [([2], -1)]
     }
     lcs1n = {
         (0, 0): [],
         (0, 1): [],
         (1, 0): [([2], -1)],
         (1, 1): [([2], -1)]
     }
     lcs1p = {
         (0, 0): [([1, 2], +1)],
         (0, 1): [],
         (1, 0): [([1, 2], +1)],
         (1, 1): []
     }
     self.assertEqual(lcs1, local_circuits(f1))
     self.assertEqual(lcs1n, local_circuits(f1, sign=-1))
     self.assertEqual(lcs1p, local_circuits(f1, sign=+1))
     gcs1 = [([1, 2], +1), ([2], -1)]
     gcs1n = [([2], -1)]
     gcs1p = [([1, 2], +1)]
     self.assertEqual(gcs1, global_circuits(f1))
     self.assertEqual(gcs1n, global_circuits(f1, sign=-1))
     self.assertEqual(gcs1p, global_circuits(f1, sign=+1))
     f2 = read_truth_table(["00 11", "01 01", "10 00", "11 00"])
     lcs2 = {
         (0, 0): [([1, 2], +1), ([1], -1)],
         (0, 1): [([1, 2], +1)],
         (1, 0): [([1], -1)],
         (1, 1): []
     }
     lcs2n = {
         (0, 0): [([1], -1)],
         (0, 1): [],
         (1, 0): [([1], -1)],
         (1, 1): []
     }
     lcs2p = {
         (0, 0): [([1, 2], +1)],
         (0, 1): [([1, 2], +1)],
         (1, 0): [],
         (1, 1): []
     }
     self.assertEqual(lcs2, local_circuits(f2))
     self.assertEqual(lcs2n, local_circuits(f2, sign=-1))
     self.assertEqual(lcs2p, local_circuits(f2, sign=+1))
     gcs2 = [([1], -1), ([1, 2], +1)]
     gcs2n = [([1], -1)]
     gcs2p = [([1, 2], +1)]
     self.assertEqual(gcs2, global_circuits(f2))
     self.assertEqual(gcs2n, global_circuits(f2, sign=-1))
     self.assertEqual(gcs2p, global_circuits(f2, sign=+1))
Beispiel #2
0
 def test_stepwise_asymptotic(self):
     f1 = read_truth_table(["0 1", "1 2", "2 0"])
     f2 = read_truth_table([
         "00 12", "01 01", "02 00", "10 20", "11 12", "12 12", "20 02",
         "21 01", "22 11"
     ])
     for f in [f1, f2]:
         self.assertFalse(is_stepwise(f))
         self.assertTrue(is_stepwise(to_stepwise(f)))
         self.assertFalse(is_asymptotic(f))
         self.assertTrue(is_asymptotic(to_asymptotic(f)))
Beispiel #3
0
 def test_poly(self):
     f = read_truth_table(["00 01", "01 01", "10 10", "11 00"])
     p, xs = polys(f)
     x1, x2 = xs
     self.assertEqual((p[0] - x1 * (1 - x2)).simplify(), 0)
     self.assertEqual((p[1] - (1 - x1)).simplify(), 0)
     self.assertEqual(polys_to_sd(p, xs), f)
Beispiel #4
0
 def test_int_graph(self):
     f1 = read_truth_table(["00 01", "01 00", "11 01", "10 00"])
     f2 = read_truth_table(["00 11", "01 10", "11 11", "10 10"])
     lig1 = local_int_graph(f1)
     lig2 = local_int_graph(f2)
     lg = {
         (0, 0): [(1, 2, -1), (2, 2, -1)],
         (0, 1): [(1, 2, 1), (2, 2, -1)],
         (1, 0): [(1, 2, -1), (2, 2, +1)],
         (1, 1): [(1, 2, 1), (2, 2, +1)]
     }
     self.assertEqual(lig1, lig2)
     self.assertEqual(lig1, lg)
     grg1 = global_int_graph(f1)
     grg2 = global_int_graph(f2)
     gg = [(1, 2, -1), (1, 2, 1), (2, 2, -1), (2, 2, 1)]
     self.assertEqual(grg1, grg2)
     self.assertEqual(grg1, gg)
Beispiel #5
0
 def test_attractor(self):
     f = {x: (0, 0) for x in boolean_states(2)}
     self.assertEqual(list(attractors(f)), [set([(0, 0)])])
     self.assertEqual(list(attractors(f, synch=True)), [set([(0, 0)])])
     f = read_truth_table(["00 11", "01 01", "10 11", "11 10"])
     self.assertEqual(list(attractors(f)),
                      [set([(0, 1)]), set([(1, 0), (1, 1)])])
     self.assertEqual(list(cyclic_attractors(f)), [set([(1, 0), (1, 1)])])
     self.assertEqual(list(attractive_cycles(f)), [[(1, 0), (1, 1)]])
Beispiel #6
0
 def test_non_usual(self):
     f = read_truth_table([
         "00 21", "01 02", "02 20", "10 20", "11 00", "12 02", "20 20",
         "21 10", "22 01"
     ])
     nug = nu_int_graph(f)
     self.assertEqual(nug[(1, 2), (0, 1)], [(1, 1, -1), (1, 2, 1),
                                            (2, 2, 1)])
     self.assertEqual(nug[(1, 2), (1, 0)], [(2, 2, 1)])
     self.assertEqual(nug[(0, 1), (1, 0)], [(1, 2, -1), (2, 1, -1)])
     gnug = [(1, 1, -1), (1, 2, -1), (1, 2, 1), (2, 1, -1), (2, 1, 1),
             (2, 2, -1), (2, 2, 1)]
     self.assertEqual(global_int_graph(f, graph=nu_int_graph), gnug)
     lcnu = local_circuits(f, graph=nu_int_graph)
     self.assertEqual(lcnu[(1, 2), (0, 1)], [([1], -1), ([2], +1)])
     self.assertEqual(lcnu[(0, 1), (1, 0)], [([1, 2], 1)])
     gcnu = global_circuits(f, graph=nu_int_graph)
     self.assertEqual(gcnu, [([1], -1), ([1, 2], -1), ([1, 2], +1),
                             ([2], -1), ([2], +1)])
Beispiel #7
0
    def test_non_usual_conversion(self):
        ms = [2, 1, 3]
        n = sum(ms)
        f = random_map(ms)
        fb = multi_to_boolean_adm(f)
        Fb = multi_to_boolean(f)
        nug = nu_int_graph(f)
        mltb, btml = multi_level_to_bool(ms), bool_vars_to_multi(ms)

        for x, y in nug:
            if len(nug[(x, y)]) > 0:
                bx, by = to_boolean_vect(x, ms), to_boolean_vect(y, ms)
                I = [
                    i for i in diff_inds(bx, by)
                    if is_admissible(neigh(bx, i), ms)
                ]
                gxfb = local_int_graph_state(fb, bx, ms=[1] * n, I=I)
                gxFb = local_int_graph_state(Fb, bx, ms=[1] * n, I=I)
                self.assertEqual(gxfb, gxFb)
                self.assertTrue([e in gxFb for e in gxfb])

                # edge in non-usual -> edge in Gfb(x)
                for j, i, s in nug[(x, y)]:
                    ei, ej = sign(y[i - 1] - x[i - 1]), sign(y[j - 1] -
                                                             x[j - 1])
                    self.assertTrue((mltb[(j, int(x[j - 1] + (ej + 1) / 2))],
                                     mltb[(i, int(x[i - 1] + (ei + 1) / 2))],
                                     s) in gxfb)

                # circuit in Gf(x,y) -> circuit in Gfb(x)
                lcxy = local_circuits(f, graph=nu_int_graph, at=(x, y))
                lcbxby = local_circuits(fb,
                                        graph=local_int_graph_state,
                                        I=I,
                                        at=bx)
                if len(lcxy) > 0:
                    slcxy, slcbxby = [s for _, s in lcxy
                                      ], [s for _, s in lcbxby]
                    self.assertTrue(all(s in slcbxby for s in slcxy))

        for x in f:
            bx = to_boolean_vect(x, ms)
            lcbxby = local_circuits(fb, graph=local_int_graph_state, at=bx)
            # circuit in Gfb(x) -> circuit in non=-usual
            if len(lcbxby) > 0:
                for c, s in lcbxby:
                    inds = [btml[ci] for ci in c]
                    inds0 = [i for i, _ in inds]
                    if len(list(set(inds0))) == len(inds0):
                        by = bx
                        for i in c:
                            by = neigh(by, i - 1)
                        y = to_multi(by, ms)
                        lcxy = local_circuits(f, graph=nu_int_graph, at=(x, y))
                        slcxy = [s for _, s in lcxy]
                        self.assertTrue(s in slcxy)

        f = read_truth_table([
            "00 10", "01 10", "02 01", "10 21", "11 11", "12 01", "20 21",
            "21 12", "22 12"
        ])
        fb = multi_to_boolean_adm(f)
        lc = local_circuits(f, graph=nu_int_graph)
        lcb = local_circuits(fb, graph=local_int_graph_state)
        self.assertTrue(len(lc[x]) == 0 for x in lc)
        self.assertTrue(any(len(lcb[x]) > 0 for x in lcb))
Beispiel #8
0
 def test_trap_domain(self):
     f = read_truth_table(["00 11", "01 11", "10 11", "11 10"])
     self.assertTrue(is_trap_domain(f, [(1, 0), (1, 1)]))
     self.assertFalse(is_trap_domain(f, [(1, 0), (0, 0)]))
Beispiel #9
0
 def test_update(self):
     f = read_truth_table(["00 11", "01 01", "10 11", "11 00"])
     self.assertEqual(update(f, 1, (1, 1)), (0, 1))
     self.assertEqual(update(f, 2, (0, 1)), (0, 1))
     g = read_truth_table(["00 01", "01 01", "10 01", "11 10"])
     self.assertEqual(sequential(f, (2, 1)), g)
Beispiel #10
0
 def test_asynchronous(self):
     f = read_truth_table(["00 11", "10 11"])
     adf = {(0, 0): set([(0, 1), (1, 0)]), (1, 0): set([(1, 1)])}
     self.assertEqual(sd_to_ad(f), adf)
     self.assertEqual(ad_to_sd(adf), f)
Beispiel #11
0
 def test_expansive(self):
     f = read_truth_table(["00 00", "10 11"])
     self.assertTrue(is_expansive(f))
     f = read_truth_table(["00 00", "10 01"])
     self.assertFalse(is_expansive(f))
Beispiel #12
0
 def test_save_tt_file(self):
     f = read_truth_table(["0 1", "1 2", "2 0"])
     f = save_truth_table(f, "data/test_save.tt")
Beispiel #13
0
 def test_empty_din(self):
     f = read_truth_table([])
Beispiel #14
0
 def test_fixed_points(self):
     f = {x: (0, 0) for x in boolean_states(2)}
     self.assertTrue(has_fixed_points(f))
     self.assertEqual(fixed_points(f), [(0, 0)])
     f = read_truth_table(["00 11", "01 11", "10 11", "11 10"])
     self.assertFalse(has_fixed_points(f))