0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

論理式の簡単化、Quine-McCluskey法のgithubからのインストール [python3]

Last updated at Posted at 2025-03-25

Quine-McCluskey法で、論理式を簡単化する優秀なプログラムがありましたが、python2で書かれていたため、色々と不具合が生じて、python3では実行できなかったため、改造点を書いておきます。

元記事

まず、logic.pyにpatchを当てます。diffをあげておきます。

qm.patch
2a3,5
> from functools import reduce
> from functools import cmp_to_key
> import locale
232a236,241
> 
> # cmp_to_keyを使用する例(locale.strcollを使用)
> def compare_names(x, y):
>     return locale.strcoll(x.name, y.name)
> 
> 
242c251,252
<         variables.sort(lambda x,y: cmp(x.name, y.name))
---
>         variables.sort(key=cmp_to_key(compare_names))
>         #variables.sort(lambda x,y: cmp_to_key(x.name, y.name))

そして、

pip install --break-system-packages /home/user/makurasan

としてインストールします。

動きました。僕は未だアルゴリズムを理解していないので、機械的に動かしただけですが。すごい人がいるなあ。

>>> import makurasan as qm
>>> a,b,c,d=qm.Bool.create('abcd')
>>> z=~a&~b&c&d|b&c&d|a&b&~c|a&~b&c&d
>>> obj = qm.QuineMcCluskey(z)
>>> obj.compute()
c & d | (a & b) & ~c
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?