Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Print lovely formatted truth tables from any boolean logic expression!

License

NotificationsYou must be signed in to change notification settings

salt-die/truth_tables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create pretty-printed truth tables and abstract syntax trees from boolean expressions! Installation is as easy aspip install truth_tables.

Example usage:

>>>fromtruth_tablesimportTruthTable>>>my_table=TruthTable('p or q','~p -> q','T and ~T')>>>print(my_table)┌───┬───┬────────┬─────────┬──────────┐│pqporq~p->qTand~T │├───┼───┼────────┼─────────┼──────────┤│FFFFF     ││FTTTF     ││TFTTF     ││TTTTF     │└───┴───┴────────┴─────────┴──────────┘>>>print(my_table.ast)Or├─Variable('p')╰─Variable('q')Implies├─Negate│ ╰─Variable('p')╰─Variable('q')And├─LiteralTrue╰─Negate  ╰─LiteralTrue>>>my_table=TruthTable('~((p xor (q and ~r) or q) and ~(p <-> r))')>>>print(my_table)┌───┬───┬───┬───────────────────────────────────────────┐│p|q|r|~((pxor (qand~r)orq)and~(p<->r)) │├───┼───┼───┼───────────────────────────────────────────┤│F|F|F|T                     ││F|F|T|T                     ││F|T|F|T                     ││F|T|T|F                     ││T|F|F|F                     ││T|F|T|T                     ││T|T|F|F                     ││T|T|T|T                     │└───┴───┴───┴───────────────────────────────────────────┘

Two truth tables are equal if they have the same variables and the same truth values (not necessarily the same propositions).

>>>TruthTable('p -> q')==TruthTable('~p or q')True

Notes on the Parser

  • The parser will accept symbolic or english names for boolean operators:

    operatorsymbolicenglish
    Not~not
    And&and
    Or|or
    Implies->implies
    Iff<->iff
    Xor^xor
  • Not has greater precendence thanAnd andAnd has greater precedence thanOr,Implies,Iff, andXor.

  • T andF are parsed as boolean literals.

  • Other than the english operator names and boolean literals, variable names may be any sequence of word characters that don't start with a digit.

About

Print lovely formatted truth tables from any boolean logic expression!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp