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

Portabilitynon-portable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

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

clauseSet :: IntSet
 

clauseLiterals :: Clause -> [Literal]Source

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

Formulas

newtype Formula Source

A conjunction of clauses

Constructors

Formula 

Fields

formulaSet :: Set Clause
 

formulaEmpty :: FormulaSource

A formula with no clauses

formulaLiteral :: Literal -> FormulaSource

Assert a literal

formulaNotSource

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)

formulaAndSource

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)

formulaOrSource

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)

formulaXorSource

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)

formulaMuxSource

Arguments

:: Literal

Output

-> Literal

False branch

-> Literal

True branch

-> Literal

Predicate/selector

-> Formula 

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)