/*
 * logic.mac--Logic algebra package for Maxima CAS.
 * Copyright (c) 2008--2009 Alexey Beshenov <al@beshenov.ru>.
 *
 * Version 2.1. Last modified 2009-01-07
 *
 * logic.mac is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * logic.mac is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the logic.mac; see the file COPYING. If not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */


load ("logic.mac")$

logic_simp (a or (b or false or (a or b)));
logic_simp (b eq a eq false eq true);
logic_simp ((a xor true) xor b xor true);
logic_simp ((a implies q) or (not (a implies q)) or b);

characteristic_vector (true);
characteristic_vector (a xor b);
characteristic_vector (a implies b);
characteristic_vector (a implies b, a, b);
characteristic_vector (a implies b, b, a);

zhegalkin_form (a or b or c);
zhegalkin_form ((a implies b) or c);

e : ((a or b) xor c) and d$
ezh : zhegalkin_form (e);
logic_equiv (ezh, e);
is (characteristic_vector(ezh) = characteristic_vector(e));
logic_equiv (x and y eq x, x implies y);

dual_function (x or y);
zhegalkin_form (%);

self_dual (a);
self_dual (not a);
self_dual (a eq b);

closed_under_f (x and y);
closed_under_f (x or y);
closed_under_t (x and y);
closed_under_t (x or y);

monotonic (a or b);
monotonic (a and b);
monotonic (a implies b);
monotonic (a xor b);

linear (a or b);
linear (a eq b);

functionally_complete (x and y, x xor y);
functionally_complete (x and y, x xor y, true);
functionally_complete (x and y, x or y, not x);

logic_basis (x and y, x or y, not x);
logic_basis (x and y, not x);
logic_basis (x or y, not x);

logic_functions : { not x, x nand y, x nor y,
                    x implies y, x and y, x or y,
                    x eq y, x xor y, true, false }$
logic_bases : subset (powerset(logic_functions), lambda ([s], apply ('logic_basis, listify(s))));

logic_diff (a or b or c, a);
logic_diff (a and b and c, a);
logic_diff (true, a);

boolean_form (a implies b implies c);
demorgan (%);
logic_equiv (boolean_form (a implies b implies c), zhegalkin_form (a implies b implies c));

demorgan (boolean_form (a nor b nor c));

pdnf (x implies y);
pcnf (x implies y);
logic_equiv (pdnf (x implies y), pcnf (x implies y));
