Giter Club home page Giter Club logo

picologic's Introduction

Picologic

Build Status

Picologic is a lightweight library for working with symbolic logic expressions. It is built against the picosat Haskell library which bundles the SAT solver with the Haskell package so no external solver or dependencies are necessary.

Picologic provides the logic expressions, parser and normal form conversion, and Tseytin transformations to express the logic expressions in equational form and generate constraint sets for use in SAT/SMT solvers.

Installing

To use the library using Stack use:

$ git clone [email protected]:sdiehl/picologic.git
$ cd picologic
$ stack build
$ stack test

Or using Cabal:

$ cabal install picologic

To build the interactive shell compile with the -fshell flag:

$ cabal get picologic
$ cd picologic-0.2.0
$ cabal configure -fshell
$ cabal install

Usage

To use the API import the Picologic module.

import Picologic

p, q, r :: Expr
p = readExpr "~(A | B)"
q = readExpr "(A | ~B | C) & (B | D | E) & (D | F)"
r = readExpr "(φ <-> ψ)"
s = readExpr "(0 | A) -> (A & 1)"

ps = ppExprU p
-- ¬(A ∨ B)
qs = ppExprU q
-- ((((A ∨ ¬B) ∨ C) ∧ ((B ∨ D) ∨ E)) ∧ (D ∨ F))
rs = ppExprU (cnf r)
-- ((φ ∧ (φ ∨ ¬ψ)) ∧ ((ψ ∨ ¬φ) ∧ ψ))
ss = ppExprU s
-- ((⊥ ∨ A) → (A ∧ ⊤))
ss1 = ppExprU (cnf s)
--

main :: IO ()
main = solveProp p >>= putStrLn . ppSolutions
-- ¬A ¬B
-- ¬A B
-- A ¬B

The expression AST consists just of the logical connectives or constants.

newtype Ident = Ident String
  deriving (Eq, Ord, Show, Data, Typeable)

data Expr
  = Var       Ident      -- ^ Variable
  | Neg       Expr       -- ^ Logical negation
  | Conj      Expr Expr  -- ^ Logical conjunction
  | Disj      Expr Expr  -- ^ Logical disjunction
  | Iff       Expr Expr  -- ^ Logical biconditional
  | Implies   Expr Expr  -- ^ Material implication
  | Top                  -- ^ Constant true
  | Bottom               -- ^ Constant false
  deriving (Eq, Ord, Show, Data, Typeable)

To use the interactive shell when compiled with with -fshell invoke picologic at the shell.

$ picologic
Picologic 0.1
Type :help for help

Logic> p | q
(p ∨ q)
Solutions:
p q
¬p q
p ¬q

Logic> ~(a -> (b <-> c))
(a ∧ ((b ∨ c) ∧ (¬b ∨ ¬c)))
Solutions:
¬a ¬b c
a b ¬c
¬a b ¬c
a ¬b c

Logic> :clauses
[[2,3],[-2,-3],[2,3,-2,-3],[1,2,3,-2,-3]]

License

Released under the MIT License. Copyright (c) 2014-2020, Stephen Diehl

picologic's People

Contributors

aleator avatar cdepillabout avatar gibiansky avatar jansamohyl avatar malie avatar sdiehl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.