vicramgon/logicus/8.0.0

NOTE: the latest version is 10.1.0

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/vicramgon/logicus is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 8.0.0 found (12 same-name repos checked); no cached copy. Use another version.

Details

LogicUS.PL.Clauses

The module provides the tools for express formulas in their Clausal Form.

Types

type alias ClausePLLiteral =
( PSymb, Bool )

It represent a literal of a clause as a tuple with the symbol of the literal (string) and the sign of the literal (False:negative literal, True:positive literal).

type alias ClausePL =
List ClausePLLiteral

It represent a set of clause literals.

c1 : ClausePL
c1 =
    [ ( "p", False ), ( "q", False ), ( "r", True ) ]


c2 : ClausePL
c2 =
    [ ( "p", False ), ( "r", True ) ]


c3 : ClausePL
c3 =
    [ ( "r", True ) ]
type alias ClausePLSet =
List ClausePL

It represent a set of ClausePL

cs : ClausePLSet
cs =
    [ c1, c2, c3 ]

Work with clauses

cplSort : ClausePL -> ClausePL

It sorts the literals of the clause by alphabetical order.

cplIsPositive : ClausePL -> Bool

Indicates if the clause is enterly positive, this is with all its literals positive

cplIsPositive c1 == False


cplIsPositive c3 == True
cplIsNegative : ClausePL -> Bool

Indicates if the clause is enterly negative, this is with all its literals negative

cplIsNegative c1 == False


cplIsNegative (List.take 2 c1) == True
cplSubsumes : ClausePL -> ClausePL -> Bool

Indicates if the first clause subsumes the second, that is, if the first is entirely contained in the second.

cplSubsumes c1 c2 == False


cplSubsumes c2 c1 == True
cplIsTautology : ClausePL -> Bool

Indicates if the clause is a tautology, that is if it contains a literal and its complement.

cplIsTautology c1 == False


(cplIsTautology <| c1 ++ [ ( "p", True ) ]) == True
csplRemoveEqClauses : ClausePLSet -> ClausePLSet

It removes clauses that are equal from a list of clauses

cs1 = [c1, c2, c3]


csplRemoveEqClauses cs1 == cs1


csplRemoveEqClauses (cs1 ++ (List.map (List.reverse) cs1)) == cs1
csplRemoveTautClauses : ClausePLSet -> ClausePLSet

It removes clauses that are tautological clauses

csplRemoveTautClauses <| List.map (\\x -> x ++ [("q", True)]) cs1 ==
    [[("p",False),("r",True),("q",True)],[("r",True),("q",True)]]
csplRemoveSubsumedClauses : ClausePLSet -> ClausePLSet

It removes clauses that are subsumed by other from the list

csplRemoveSubsumedClauses cs1 == [ [ Atom "r" ] ]
cplSymbols : ClausePL -> List PSymb

It gives the propositional symbols that take place in the clause

cplSymbols c1 =
    [ "p", "q", "r" ]
cplSymbols c2 =
    [ "p", "r" ]
cplSymbols c3 =
    [ "r" ]
csplSymbols : ClausePLSet -> List PSymb

It gives the propositional symbols that take place in the clause

csplSymbols cs1 =
    [ "p", "q", "r" ]
cplInterpretations : ClausePL -> List Interpretation

It gives all possible interpretations for a clause

cplInterpretations c1 == [ [], [ "p" ], [ "p", "q" ], [ "p", "q", "r" ], [ "p", "r" ], [ "q" ], [ "q", "r" ], [ "r" ] ]


cplInterpretation c2 == [ [], [ "p" ], [ "p", "r" ], [ "r" ] ]
csplInterpretations : ClausePLSet -> List Interpretation

It gives all possible interpretations for a set of clauses

csplInterpretations cs1 == [ [], [ "p" ], [ "p", "q" ], [ "p", "q", "r" ], [ "p", "r" ], [ "q" ], [ "q", "r" ], [ "r" ] ]


csplInterpretations [ [ Atom "p" ], [ Atom "q" ] ] == [ [], [ "p" ], [ "p", "q" ], [ "q" ] ]
cplValuation : ClausePL -> Interpretation -> Bool

It evaluates the truth value of the clause regarding to a interpretation

cplValuation c2 [ "p", "r" ] == True


cplValuation c2 [] == True


cplValuation c2 [ "p" ] == False
csplValuation : ClausePLSet -> Interpretation -> Bool

It evaluates the truth value of a set of clauses regarding to a interpretation

csplValuation cs1 [ "r" ] == True


csplValuation cs1 [] == False
cplModels : ClausePL -> List Interpretation

It generates all models of a clause by bruteforce, valuating the truth value for each interpretation

plModels c1 == [ [], [ "p" ], [ "p", "q", "r" ], [ "p", "r" ], [ "q" ], [ "q", "r" ], [ "r" ] ]


cplModels c2 == [ [], [ "p", "r" ], [ "r" ] ]


cplModels c3 == [ [ ( "r", True ) ] ]
csplModels : ClausePLSet -> List Interpretation

It generates all models of a set of clauses by bruteforce, valuating the truth value for each interpretation

csplModels cs1 == [ [ "p", "q", "r" ], [ "p", "r" ], [ "q", "r" ], [ "r" ] ]
cplIsInsat : ClausePL -> Bool

It checks if a clause is unsatisfible, that is if it is empty.

cplIsInsat c1 == False


cplIsInsat c2 == False


cplIsInsat [] == True
csplIsTaut : ClausePLSet -> Bool

It checks if a set of clauses is a tautology, that is if all clauses are tautologies.

csplIsTaut cs1 == False


csplIsTaut (List.map (\x -> x ++ [ ( "r", False ) ]) cs1) == True
csplIsSat : ClausePLSet -> Bool

It checks if a set of clauses is satisfiable by bruteforce, calculating its models and checking any exists

csplIsSat cs1 == True


csplIsSat (cs1 ++ [ ( "r", False ) ]) == False
csplIsInsat : ClausePLSet -> Bool

It checks if a set of clauses are satisfiable by brute force, calculates its models and verifies that none exist.

Formulas and Clauses

clauseLitToLiteral : ClausePLLiteral -> Literal

It converts a ClausePLLiteral to a Literal (FormulaPL)

cplFromCNF : FormulaPL -> Maybe ClausePLSet

It pass a CNF formula to a Set of clausses

fplToClauses : FormulaPL -> ClausePLSet

Express a formula as a Set of clauses.

f1 = (fplReadExtraction << fplReadFromString) "¬p & q <-> r"
fplToClauses f1 == [[("p",True),("q",False),("r",True)],[("p",False),("r",False)],[("q",True),("r",False)]]
splToClauses : SetPL -> ClausePLSet

Express a set of formulas as a Set of clauses.

fs = List.map (fplReadExtraction << fplReadFromString) ["p->q", "p | q -> r", "¬p | q"]


cs = splToClauses fs
cs == [[("p",False),("q",True)],[("p",False),("r",True)],[("q",False),("r",True)]]

Clauses Parser

cplReadFromString : String -> ( Maybe ClausePL, String, String )

It reads the formula from a string. It returns a tuple with may be a formula (if it can be read it) and a message of error it it cannot.

cplReadFromString "p_{1}, p_{2}, ¬q_{1}, q_{2}" == (Just [("p_{1}",True),("p_{2}",True),("q_{1}",False),("q_{2}",True)],"","")


cplReadFromString "{p_{1}, p_{2}, ¬q_{1}, q_{2}}" == (Just [("p_{1}",True),("p_{2}",True),("q_{1}",False),("q_{2}",True)],"",""


cplReadFromString "{p_{1}, p_{2}, ¬q_{1}, q_{2}" == (Nothing,"{p_{1},p_{2},¬q_{1},q_{2}","Error: [{ col = 26, problem = Expecting ',', row = 1 },{ col = 26, problem = Expecting '}', row = 1 }]")


cplReadFromString "{}" == ( Just [], "", "" )


cplReadFromString "" == ( Nothing, "", "Argument is empty" )
cplReadExtraction : ( Maybe ClausePL, String, String ) -> ClausePL

It extracts the clause readed. If it is Nothing then it returns an empty clause

(cplReadExtraction << cplReadFromString) "p_{1}, p_{2}, ¬q_{1}, q_{2}" == [ ( "p_{1}", True ), ( "p_{2}", True ), ( "q_{1}", False ), ( "q_{2}", True ) ]


(cplReadExtraction << cplReadFromString) "{p_{1}, p_{2}, ¬q_{1}, q_{2}" == []


(cplReadExtraction << cplReadFromString) "{}" == []
cplToInputString : ClausePL -> String

It gives the corresponding input syntax of a clause

cplToInputString c1 = "{¬p,¬q,r}"


cplToInputString c3 == "{r}"

Clauses Representation

cplToString : ClausePL -> String

It generates the String representation of a ClausePL using unicode symbols.

cplToString c1 == "{¬ p, ¬ q, r}"
cplToMathString : ClausePL -> String

It generates the Latex string of a ClausePL. The result requires a math enviroment to be displayed.

cplToMathString c1 == "\\left\\lbrace \\neg p, \\neg q, r\\right\\rbrace"
csplToString : ClausePLSet -> String

It generates the String representation of a Set of Clauses using unicode symbols.

csplToString cs == "{{¬ p, q},{¬ p, r},{¬ q, r}}"
csplToMathString : ClausePLSet -> String

It generates the Latex string of a Set of Clauses. The result requires a math enviroment to be displayed.

csplToMathString cs == "\\left\\lbrace\\left\\lbrace \\neg p, q\\right\\rbrace, \\, \\left\\lbrace \\neg p, r\\right\\rbrace, \\, \\left\\lbrace \\neg q, r\\right\\rbrace\\right\\rbrace"