ersatz-0.4.2: A monad for expressing SAT or QSAT problems using observable sharing.

Copyright© Edward Kmett 2010-2014 Johan Kiviniemi 2013
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Ersatz.Internal.Formula

Contents

Description

 

Synopsis

Clauses

newtype Clause Source #

A disjunction of possibly negated atoms. Negated atoms are represented by negating the identifier.

Constructors

Clause 

Fields

clauseLiterals :: Clause -> [Literal] Source #

Extract the (possibly negated) atoms referenced by a Clause.

Formulas

formulaEmpty :: Formula Source #

A formula with no clauses

formulaLiteral :: Literal -> Formula Source #

Assert a literal

formulaNot Source #

Arguments

:: Literal

Output

-> Literal

Input

-> Formula 

The boolean not operation

Derivation of the Tseitin transformation:

O ≡ ¬A
(O → ¬A) & (¬O → A)
(¬O | ¬A) & (O | A)

formulaAnd Source #

Arguments

:: Literal

Output

-> [Literal]

Inputs

-> Formula 

The boolean and operation

Derivation of the Tseitin transformation:

O ≡ (A & B & C)
(O → (A & B & C)) & (¬O → ¬(A & B & C))
(¬O | (A & B & C)) & (O | ¬(A & B & C))
(¬O | A) & (¬O | B) & (¬O | C) & (O | ¬A | ¬B | ¬C)

formulaOr Source #

Arguments

:: Literal

Output

-> [Literal]

Inputs

-> Formula 

The boolean or operation

Derivation of the Tseitin transformation:

O ≡ (A | B | C)
(O → (A | B | C)) & (¬O → ¬(A | B | C))
(¬O | (A | B | C)) & (O | ¬(A | B | C))
(¬O | A | B | C) & (O | (¬A & ¬B & ¬C))
(¬O | A | B | C) & (O | ¬A) & (O | ¬B) & (O | ¬C)

formulaXor Source #

Arguments

:: Literal

Output

-> Literal

Input

-> Literal

Input

-> Formula 

The boolean xor operation

Derivation of the Tseitin transformation:

O ≡ A ⊕ B
O ≡ ((¬A & B) | (A & ¬B))
(O → ((¬A & B) | (A & ¬B))) & (¬O → ¬((¬A & B) | (A & ¬B)))

Left hand side:

O → ((¬A & B) | (A & ¬B))
¬O | ((¬A & B) | (A & ¬B))
¬O | ((¬A | A) & (¬A | ¬B) & (A | B) & (¬B | B))
¬O | ((¬A | ¬B) & (A | B))
(¬O | ¬A | ¬B) & (¬O | A | B)

Right hand side:

¬O → ¬((¬A & B) | (A & ¬B))
O | ¬((¬A & B) | (A & ¬B))
O | (¬(¬A & B) & ¬(A & ¬B))
O | ((A | ¬B) & (¬A | B))
(O | ¬A | B) & (O | A | ¬B)

Result:

(¬O | ¬A | ¬B) & (¬O | A | B) & (O | ¬A | B) & (O | A | ¬B)

formulaMux Source #

Arguments

:: Literal

Output

-> Literal

False branch

-> Literal

True branch

-> Literal

Predicate/selector

-> Formula 

with redundant clauses, cf. discussion in Een and Sorensen, Translating Pseudo Boolean Constraints ..., p. 7 http://minisat.se/Papers.html

The boolean else-then-if or mux operation

Derivation of the Tseitin transformation:

O ≡ (F & ¬P) | (T & P)
(O → ((F & ¬P) | (T & P))) & (¬O → ¬((F & ¬P) | (T & P)))

Left hand side:

O → ((F & ¬P) | (T & P))
¬O | ((F & ¬P) | (T & P))
¬O | ((F | T) & (F | P) & (T | ¬P) & (¬P | P))
¬O | ((F | T) & (F | P) & (T | ¬P))
(¬O | F | T) & (¬O | F | P) & (¬O | T | ¬P)

Right hand side:

¬O → ¬((F & ¬P) | (T & P))
O | ¬((F & ¬P) | (T & P))
O | (¬(F & ¬P) & ¬(T & P))
O | ((¬F | P) & (¬T | ¬P))
(O | ¬F | P) & (O | ¬T | ¬P)

Result:

(¬O | F | T) & (¬O | F | P) & (¬O | T | ¬P) & (O | ¬F | P) & (O | ¬T | ¬P)