From 4294ec0ed06ee34920c9edaeebaeb8b65c720791 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 19 Jul 2024 01:29:42 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libnormalform_xor2.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 libnormalform_xor2.c (limited to 'libnormalform_xor2.c') diff --git a/libnormalform_xor2.c b/libnormalform_xor2.c new file mode 100644 index 0000000..a00c575 --- /dev/null +++ b/libnormalform_xor2.c @@ -0,0 +1,63 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef TEST +#include "common.h" + + +LIBNORMALFORM_SENTENCE * +(libnormalform_xor2)(LIBNORMALFORM_SENTENCE *l, LIBNORMALFORM_SENTENCE *r) +{ + int inv; + + if (!l || !r) { + libnormalform_free(l); + libnormalform_free(r); + return NULL; + } + + if (l->equals(l, r, &inv)) { + libnormalform_free(l); + libnormalform_free(r); + + if (!inv) { + /* x ⊕ x = 0 */ + return libnormalform_false(); + + } else { + /* x ⊕ ¬x = 1 */ + return libnormalform_true(); + } + + } else if (l->type == TYPE_TRUE) { + /* 1 ⊕ x = (1 ∨ x) ∧ ¬(1 ∧ x) = 1 ∧ ¬x = ¬x */ + r = libnormalform_not(r); + return_r: + libnormalform_free(l); + return r; + + } else if (l->type == TYPE_FALSE) { + /* 0 ⊕ x = (0 ∨ x) ∧ ¬(0 ∧ x) = x ∧ ¬0 = x ∧ 1 = x */ + goto return_r; + + } else if (r->type == TYPE_TRUE) { + /* x ⊕ 1 = 1 ⊕ x = ¬x */ + l = libnormalform_not(l); + return_l: + libnormalform_free(r); + return l; + + } else if (r->type == TYPE_FALSE) { + /* x ⊕ 0 = 0 ⊕ x = x */ + goto return_l; + + } else { + return libnormalform_xor2__(l, r); + } +} + + +#else + +#define USE_TWO +#include "libnormalform_xor.c" + +#endif -- cgit v1.3.1