Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lamg/predicate
Parsing, evaluating and textually representing predicates
https://github.com/lamg/predicate
boolean-expression evaluation parsing predicates
Last synced: 4 days ago
JSON representation
Parsing, evaluating and textually representing predicates
- Host: GitHub
- URL: https://github.com/lamg/predicate
- Owner: lamg
- License: lgpl-3.0
- Created: 2019-03-12T04:36:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-11T19:41:36.000Z (about 5 years ago)
- Last Synced: 2024-11-17T12:40:40.579Z (about 1 month ago)
- Topics: boolean-expression, evaluation, parsing, predicates
- Language: Go
- Homepage:
- Size: 90.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Predicate
[![Build Status][1]][2] [![Coverage Status][3]][4] [![Go Report Card][5]][6]
Predicate is a simple library for parsing, evaluating and textually representing predicates (boolean functions).
## Install
```sh
git clone [email protected]:lamg/predicate.git
cd predicate/cmd/reduce && go install
```## Example
The following table shows some examples of how `reduce` works. Using standard input and output makes easier typing the boolean operators, since you can use Vim's multibyte input method (ex: C-k OR writes ∨), and then pipe the selected text using the visual mode to the `reduce` command, or just store the predicates in a file and then use it as standard input to `reduce` (`reduce < file_with_predicates`).
| Standard input | Standard output |
|-----------------|-----------------|
| true | true |
| ¬false | true |
| ¬true | false |
| true ∧ false | false |
| false ∧ false | false |
| false ∨ false | false |
| false ∨ true | true |
| ¬(true ∧ true) | false |
| ¬(true ∧ ¬A) | ¬(¬A) |
| A ∧ A | A |
| true ⇒ false | false |
| A ≡ true | A |
| A ≡ false | ¬A |
| A ≡ A | true |
| A ≡ ¬A | false |
| A ≢ A | false |
| A ⇐ true | A |
| A ≢ false | A |## Syntax
The syntax is based on [EWD1300][0] which I have formalized in the following grammar:
```ebnf
predicate = term {('≡'|'≢') term}.
term = junction ({'⇒' junction} | {'⇐' junction}).
junction = factor ({'∨' factor} | {'∧' factor}).
factor = [unaryOp] (identifier | '(' predicate ')').
unaryOp = '¬'.
```## Reduction rules
The procedure `Reduce` applies the following rules while reducing the predicate.
```
¬true ≡ false
¬false ≡ true
A ∨ false ≡ A
A ∧ true ≡ A
A ∨ true ≡ true
A ∧ false ≡ false
A ∨ B ≡ B ∨ A
A ∧ B ≡ B ∧ A
A ≡ true ≡ A
A ≡ false ≡ ¬A
true ⇒ A ≡ A
false ⇒ A ≡ true
A ⇒ true ≡ true
A ⇒ false ≡ ¬A
A ⇐ B ≡ B ⇒ A
A ≢ B ≡ A ≡ ¬B
```[0]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/EWD1300.html
[1]: https://travis-ci.com/lamg/predicate.svg?branch=master
[2]: https://travis-ci.com/lamg/predicate
[3]: https://coveralls.io/repos/github/lamg/predicate/badge.svg?branch=master
[4]: https://coveralls.io/github/lamg/predicate?branch=master
[5]: https://goreportcard.com/badge/github.com/lamg/predicate
[6]: https://goreportcard.com/report/github.com/lamg/predicate