GithubHelp home page GithubHelp logo

properst's Introduction

Properst - Propositional logic REPL

Properst is a command-line utility for manipulating propositions.

Motivation

I created this program to aid me and (hopefully) other students in the Logic for Informatics course I’m following at Utrecht University.

The value I get out of writing this program:

  • I gained a somewhat better understanding of propositional logic
  • I practiced the use / creation of parser combinators

Usage

When running the program (by e.g. cabal new-run or cd src && runhaskell Main.hs), a primitive help system is available to you by typing help, h, ?, or any other text that cannot be parsed into a proposition expression ;-)

I recommend that you run this program via rlwrap, a wrapper for GNU Readline (consult your package manager). This will give you line-editing and command history tools.

For example: rlwrap cabal new-run

Commands

Available commands are:

(replace PROP with your proposition expression)

PROPprints proposition in canonical syntax
t PROPshows for what variable values the proposition holds
t! PROPprints a complete truth table for the given proposition
c PROP(WIP) prints the proposition’s conjunctive normal form
c! PROP(WIP) II, also prints truth table showing logical equivalence
d PROP(WIP) prints the proposition’s disjunctive normal form
d! PROP(WIP) II, also prints truth table showing logical equivalence

example: t !(P & Q) <=> (!P | !Q)

Note: The normalizer commands are not yet completely functional.

Proposition syntax and grammar

This overview is also made available by typing syntax in the prompt.

Syntax elements are:

variablesany single letter excluding T and F (e.g. P, Q, ζ, x)
booleansT and F, as capital letters
negation¬p, !p, or not p
disjunctionp ∨ q, p | q, or p \/ q
conjunctionp ∧ q, p & q, or p /\ q
exclusive disjunction (XOR)p ⊻ q, p ⊕ q, or p x| q
implicationp ⇒ q, p → q, p => q, or p ==> q
converse implicationp ⇐ q, p ← q, p <= q, or p <== q
logical equivalencep ⇔ q, p <=> q, or p iff q

Any proposition may be grouped with parentheses () to indicate precedence.

Built-in precedence is as follows, from highest to lowest:

  1. negation
  2. conjunction, disjunction and exclusive disjunction
  3. implication, converse implication and logical equivalence

NB: Except for chains of conjunctions and chains of disjunctions, any two binary operators with the same precedence may not occur next to eachother without the use of parens to denote precedence.

Example: Solving a logic puzzle

The Kalotan puzzle can be solved as follows:

We assign our variables to the following proposition atoms:

PGender of parent 1 (T = male, F = female)
QGender of parent 2
CGender of child
DGender of child (as reported by child)
ETruthfulness of child’s gender statement

We translate the puzzle rules into the following proposition:

(P x| Q) & (E <=> (C <=> D)) & (C => E) & (P => D) & (Q => !C & !E) & (!Q => !C x| !E)

Now, we solve for P, Q and C by typing a t command:

** t (P x| Q) & (E <=> (C <=> D)) & (C => E) & (P => D) & (Q => !C & !E) & (!Q => C x| E)

 C D E P Q | (P ⊕ Q) ∧ (E <=> (C <=> D)) ∧ (C ==> E) ∧ (P ==> D) ∧ (Q ==> ¬C ∧ ¬E) ∧ (¬Q ==> C ⊕ E) 
----------------------------------------------------------------------------------------------------
 F T F F T |                                            T

As shown, the only solution is:

  • Parent 1 (P) is the mother
  • Parent 2 (Q) is the father
  • The child (C) is a girl

License

GPLv3, see LICENSE.

Author

properst's People

Contributors

cjsmeele avatar

Stargazers

 avatar  avatar

Watchers

 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.