Giter VIP home page Giter VIP logo

truths's Introduction

truths - auto generate truth tables

truths is a simple tool that allows you to quickly generate a truth table from python variable names and phrases

install

pip install truths or git clone and pip install -e to play with the code

use is simple:

start by creating some base variables

import truths
print truths.Truths(['a', 'b', 'x'])
+---+---+---+
| a | b | x |
+---+---+---+
| 0 | 0 | 0 |
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| 1 | 1 | 1 |
+---+---+---+

add some phrases

now let's use those base variables and pass in some phrases! your base variables can be anything you want but must be valid python variable names. the phrases also have to be valid python

from truths import Truths
print Truths(['a', 'b', 'cat', 'has_address'], ['(a and b)', 'a and b or cat', 'a and (b or cat) or has_address'])
+---+---+-----+-------------+-----------+----------------+---------------------------------+
| a | b | cat | has_address | (a and b) | a and b or cat | a and (b or cat) or has_address |
+---+---+-----+-------------+-----------+----------------+---------------------------------+
| 0 | 0 |  0  |      0      |     0     |       0        |                0                |
| 0 | 0 |  0  |      1      |     0     |       0        |                1                |
| 0 | 0 |  1  |      0      |     0     |       1        |                0                |
| 0 | 0 |  1  |      1      |     0     |       1        |                1                |
| 0 | 1 |  0  |      0      |     0     |       0        |                0                |
| 0 | 1 |  0  |      1      |     0     |       0        |                1                |
| 0 | 1 |  1  |      0      |     0     |       1        |                0                |
| 0 | 1 |  1  |      1      |     0     |       1        |                1                |
| 1 | 0 |  0  |      0      |     0     |       0        |                0                |
| 1 | 0 |  0  |      1      |     0     |       0        |                1                |
| 1 | 0 |  1  |      0      |     0     |       1        |                1                |
| 1 | 0 |  1  |      1      |     0     |       1        |                1                |
| 1 | 1 |  0  |      0      |     1     |       1        |                1                |
| 1 | 1 |  0  |      1      |     1     |       1        |                1                |
| 1 | 1 |  1  |      0      |     1     |       1        |                1                |
| 1 | 1 |  1  |      1      |     1     |       1        |                1                |
+---+---+-----+-------------+-----------+----------------+---------------------------------+

prefer boolean words?

neat eh? if you prefer True/False over the numbers pass ints=False:

from truths import Truths
print Truths(['a', 'b', 'x', 'd'], ['(a and b)', 'a and b or x', 'a and (b or x) or d'], ints=False)
+-------+-------+-------+-------+-----------+--------------+---------------------+
|   a   |   b   |   x   |   d   | (a and b) | a and b or x | a and (b or x) or d |
+-------+-------+-------+-------+-----------+--------------+---------------------+
| False | False | False | False |   False   |    False     |        False        |
| False | False | False |  True |   False   |    False     |         True        |
| False | False |  True | False |   False   |     True     |        False        |
| False | False |  True |  True |   False   |     True     |         True        |
| False |  True | False | False |   False   |    False     |        False        |
| False |  True | False |  True |   False   |    False     |         True        |
| False |  True |  True | False |   False   |     True     |        False        |
| False |  True |  True |  True |   False   |     True     |         True        |
|  True | False | False | False |   False   |    False     |        False        |
|  True | False | False |  True |   False   |    False     |         True        |
|  True | False |  True | False |   False   |     True     |         True        |
|  True | False |  True |  True |   False   |     True     |         True        |
|  True |  True | False | False |    True   |     True     |         True        |
|  True |  True | False |  True |    True   |     True     |         True        |
|  True |  True |  True | False |    True   |     True     |         True        |
|  True |  True |  True |  True |    True   |     True     |         True        |
+-------+-------+-------+-------+-----------+--------------+---------------------+

how it works

check out the code! behind the scenes it's putting the bases in an object context and generating a grid of values for them. then, the phrases are evaluated in the object's context against each row in that grid of values

truths's People

Contributors

tr3buchet avatar

Watchers

 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.