tortis / elm-sat / Sat.Utils

This sub-module offers some utilities related to SAT solving. It also contains a few general purpose functions primarily for internal use.

SAT Problems

fromDimacs : String -> Sat.Model.Problem

Create a Sat.Problem from DIMACS formatted string. Only cnf representation is supported. The problem line and comment lines will be ignored.

fromDimacs """
c  simple_v3_c2.cnf
c
p cnf 3 2
1 -3 0
2 3 -1 0
""" -- [ [ 1, -3 ], [ 2, 3, -1 ] ]

verify : Sat.Model.Problem -> Sat.Model.Solution -> Basics.Bool

Check if a given solution satifies a problem. This useful for sanity checks and unit testing.

verify [ [ 1, 2 ], [ -2, 3 ], [ 1 ] ] [ 1, -2, 3 ] -- True
verify [ [ 1, 2 ], [ -2, 3 ], [ 1 ] ] [ 1, -2, -3 ] -- True
verify [ [ 1, 2 ], [ -2, 3 ], [ 1 ] ] [ -1, -2, -3 ] -- False

DPLL Helpers

find : (a -> Basics.Bool) -> List a -> Maybe a

Find the first occurence of a list item that matches the filter.

find (\v -> v % 2 == 0) [ 1, 2, 3, 4 ] -- Just 2

kernelFilter1 : (Maybe a -> a -> Maybe a -> Basics.Bool) -> List a -> List a

Filter list items based on each items nearest neighbors.

touchesOne prev _ next =
    let
        isOne neighbor =
            Maybe.map (\v -> v == 1) neighbor |> Maybe.withDefault False

    in
    isOne prev || isOne next

kernelFilter1 touchesOne [ 1, 2, 3, 4, 1, 5, 6 ] -- [ 2, 4, 5 ]