diff --git a/spot/twaalgos/aiger.cc b/spot/twaalgos/aiger.cc index e3c3bb6c5..af255a167 100644 --- a/spot/twaalgos/aiger.cc +++ b/spot/twaalgos/aiger.cc @@ -637,19 +637,44 @@ namespace spot // De-morgan // !(!v&low | v&high) = !(!v&low) & !(v&high) // !v&low | v&high = !(!(!v&low) & !(v&high)) + // note that if low or high are T + // we can simplify the formula + // given that low / high is T + // then !(!v&low) & !(v&high) can be simplified to + // !v&low | v&high = !v | high / low | v + // = !(v & !high) / !(!low & !v) + // The case when low / high is ⊥ is automatically treated auto b_it = bdd2var_.find(b.id()); if (b_it != bdd2var_.end()) return b_it->second; - // todo -// unsigned v_var = bdd2var_.at(bdd_var(b)); unsigned v_var = bdd2var_.at(bdd_ithvar(bdd_var(b)).id()); unsigned b_branch_var[2] = {bdd2INFvar(bdd_low(b)), bdd2INFvar(bdd_high(b))}; - unsigned r = aig_not(aig_and(v_var, b_branch_var[1])); - unsigned l = aig_not(aig_and(aig_not(v_var), b_branch_var[0])); + unsigned l; + unsigned r; + + if (b_branch_var[0] == aig_true()) + { + // low == T + l = v_var; + r = aig_not(b_branch_var[1]); + } + else if (b_branch_var[1] == aig_true()) + { + // high == T + l = aig_not(b_branch_var[0]); + r = aig_not(v_var); + } + else + { + // General case + r = aig_not(aig_and(v_var, b_branch_var[1])); + l = aig_not(aig_and(aig_not(v_var), b_branch_var[0])); + } + return aig_not(aig_and(l, r)); } diff --git a/tests/python/_synthesis.ipynb b/tests/python/_synthesis.ipynb index 6952eadd3..4c203a86e 100644 --- a/tests/python/_synthesis.ipynb +++ b/tests/python/_synthesis.ipynb @@ -738,7 +738,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc883a7720> >" + " *' at 0x7fbccc33a0f0> >" ] }, "execution_count": 8, @@ -821,7 +821,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc883a7720> >" + " *' at 0x7fbccc33a0f0> >" ] }, "execution_count": 9, @@ -945,7 +945,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc8833aa80> >" + " *' at 0x7fbccc345660> >" ] }, "execution_count": 10, @@ -1043,7 +1043,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c2ab0> >" + " *' at 0x7fbccc3486c0> >" ] }, "execution_count": 11, @@ -1211,7 +1211,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc8833ae70> >" + " *' at 0x7fbccc345ae0> >" ] }, "execution_count": 12, @@ -1420,7 +1420,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c2240> >" + " *' at 0x7fbccc345e40> >" ] }, "execution_count": 13, @@ -1578,7 +1578,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880bdc30> >" + " *' at 0x7fbccc364a20> >" ] }, "execution_count": 14, @@ -1722,7 +1722,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880bdc30> >" + " *' at 0x7fbccc364a20> >" ] }, "execution_count": 15, @@ -1869,7 +1869,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5210> >" + " *' at 0x7fbccc35a2d0> >" ] }, "execution_count": 16, @@ -2014,7 +2014,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5210> >" + " *' at 0x7fbccc35a2d0> >" ] }, "execution_count": 17, @@ -2561,7 +2561,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5d50> >" + " *' at 0x7fbccc35af00> >" ] }, "execution_count": 18, @@ -2715,7 +2715,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5d50> >" + " *' at 0x7fbccc35af00> >" ] }, "execution_count": 19, @@ -2873,7 +2873,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880cd090> >" + " *' at 0x7fbccc36d240> >" ] }, "metadata": {}, @@ -4215,7 +4215,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880bdc00> >" + " *' at 0x7fbccc3910f0> >" ] }, "execution_count": 20, @@ -4698,7 +4698,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880bdc00> >" + " *' at 0x7fbccc3910f0> >" ] }, "execution_count": 21, @@ -4831,7 +4831,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880cd2a0> >" + " *' at 0x7fbccc364570> >" ] }, "metadata": {}, @@ -5509,7 +5509,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c55a0> >" + " *' at 0x7fbccc35a9c0> >" ] }, "execution_count": 22, @@ -5748,7 +5748,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c55a0> >" + " *' at 0x7fbccc35a9c0> >" ] }, "execution_count": 23, @@ -5838,7 +5838,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5a50> >" + " *' at 0x7fbccc3646c0> >" ] }, "metadata": {}, @@ -5932,7 +5932,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fcc880c5a50> >" + " *' at 0x7fbccc3646c0> >" ] }, "metadata": {}, @@ -5955,10 +5955,414 @@ "display(aut)" ] }, + { + "cell_type": "markdown", + "id": "7efe7450", + "metadata": {}, + "source": [ + "# Test improved aiger INF encoding" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "31872ccc", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "t\n", + "[all]\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "I->1\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "!a & !b & !c & !d\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "1->3\n", + "\n", + "\n", + "a | b | c | d\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "0->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->0\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->0\n", + "\n", + "\n", + "x\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + " *' at 0x7fbccc3911e0> >" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "si = spot.synthesis_info()\n", + "\n", + "aut = spot.ltl_to_game(\"(a|b|c|d)->x\", [\"x\"], si)\n", + "aut" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "9064bc60", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(spot.solve_game(aut))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "303ada1e", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "t\n", + "[all]\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "I->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "0->2\n", + "\n", + "\n", + "!a & !b & !c & !d\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "0->3\n", + "\n", + "\n", + "a | b | c | d\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->1\n", + "\n", + "\n", + "x\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + " *' at 0x7fbcd407ca20> >" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ctrl = spot.solved_game_to_split_mealy(aut)\n", + "ctrl" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "9874a530", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "10\n", + "\n", + "L0_out\n", + "\n", + "\n", + "\n", + "18\n", + "\n", + "18\n", + "\n", + "\n", + "\n", + "10->18\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "12\n", + "\n", + "12\n", + "\n", + "\n", + "\n", + "14\n", + "\n", + "14\n", + "\n", + "\n", + "\n", + "12->14\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "16\n", + "\n", + "16\n", + "\n", + "\n", + "\n", + "14->16\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "16->18\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "o0\n", + "\n", + "x\n", + "\n", + "\n", + "\n", + "18->o0:s\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "L0\n", + "\n", + "L0_in\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "2->16\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "b\n", + "\n", + "\n", + "\n", + "4->14\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "6\n", + "\n", + "c\n", + "\n", + "\n", + "\n", + "6->12\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "8\n", + "\n", + "d\n", + "\n", + "\n", + "\n", + "8->12\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "False\n", + "\n", + "\n", + "\n", + "0->L0\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + " >" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "aig = spot.mealy_machine_to_aig(ctrl, \"ite\")\n", + "aig" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "f3b2d981", + "id": "eb81b7d3", "metadata": {}, "outputs": [], "source": []