sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 469 forks source link

Improve propositional logic #13120

Open nthiery opened 12 years ago

nthiery commented 12 years ago

I discussed yesterday with Shalom Eliahou and some other persons that could be interested in using Sage to have a natural syntax for constructing complicated propositional logic formulas (boolean formulas), in order to model and treat some of their hard NP problems using SAT solvers. They currently write directly files in ``sat format'' which is not necessarily so convenient.

Looking around sage.logic, it feels like this old module could use some love. Like being more consistent with SymbolicRing in the syntax for constructing formulas, using Parents/Elements, having interfaces with the common open source SAT solvers, ... Here are some story suggestions:

Building formulas::

    sage: F = BooleanFormulas();
    Boolean formulas
    sage: a,b,c = F.var("a,b,c")
    sage: ~( (a & b & c) | c )
    sage: f = (~(a & b)).equivalent(a|b)    # Note: this is backward incompatible
    sage: f.is_tautology()
    True
    sage: f.parent()
    Boolean formulas

    sage: f = (a & (a.implies(c))).implies(c)
    sage: f.is_tautology()
    True

Indexed boolean variables::

    sage: x = F.var("x")
    sage: (x[1] & x[2]).implies(x[1,3]
    (x[1] & x[2]).implies(x[1,3]

Equivalence test::

    sage: (~(a & b)).is_equivalent(a|b)
    True

Expanding in Conjonctive Normal Form::

    sage: f.cnf()
    ...

Computing an equivalent 3-SAT formula::

    sage: f.sat_3()
    ...

Using SAT solvers::

    sage: f.is_satisfiable(solver="mark")

Returning the solutions of f, as an iterable::

    sage: S = f.solve(); S
    The solutions of ...

    sage: for s in S: print s
    ...

Automatic simplifications
=========================

Associativity::

    sage: (a & b) & c
    a & b & c
    sage: a & (b & c)
    a & b & c

    sage: a | (b | c)
    a | b | c
    sage: a | (b | c)
    a | b | c

Of course, a related question is whether one could use one of the preexisting external libraries for boolean functions.

CC: eliahou@lmpa.univ-littoral.fr @kini

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/13120

b03034c9-f2cf-4d37-9a1e-419dd712df02 commented 12 years ago
comment:2

You might want to make this building upon #418 (needing review)