LoginSignup
0
0

真理値表から論理式を求める。 その2

Last updated at Posted at 2020-12-03

概要

sympyで真理値表から論理式を求める。
and,or,not,nand,nor,xorやってみた。

サンプルコード

import sympy as sym



print(">and")
print(sym.POSform(['a', 'b'], [[1, 1]]))
print(sym.SOPform(['a', 'b'], [[1, 1]]))
print(">or")
print(sym.POSform(['a', 'b'], [[1, 1], [0, 1], [1, 0]]))
print(sym.SOPform(['a', 'b'], [[1, 1], [0, 1], [1, 0]]))
print(">not")
print(sym.POSform(['c'], [[0]]))
print(sym.SOPform(['c'], [[0]]))
print(">nand")
print(sym.POSform(['a', 'b'], [[0, 0], [0, 1], [1, 0]]))
print(sym.SOPform(['a', 'b'], [[0, 0], [0, 1], [1, 0]]))
print(">nor")
print(sym.POSform(['a', 'b'], [[0, 0]]))
print(sym.SOPform(['a', 'b'], [[0, 0]]))
print(">xor")
print(sym.POSform(['a', 'b'], [[1, 0], [0, 1]]))
print(sym.SOPform(['a', 'b'], [[1, 0], [0, 1]]))

実行結果



>and
And(a, b)
And(a, b)
>or
Or(a, b)
Or(a, b)
>not
Not(c)
Not(c)
>nand
Or(Not(a), Not(b))
Or(Not(a), Not(b))
>nor
And(Not(a), Not(b))
And(Not(a), Not(b))
>xor
And(Or(Not(a), Not(b)), Or(a, b))
Or(And(Not(a), b), And(Not(b), a))


成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0