2017年9月19日火曜日

学習環境

集合論入門(基礎数学シリーズ)(松村 英之(著)、朝倉書店)の1.(集合算)、1.3(和集合と共通部分)の練習問題1、2.を取り組んでみる。


  1. ( AB )( CD ) =( ( AB )C )( ( AB )D ) =( ( AC )( BC ) )( ( AD )( BD ) ) =( AC )( BC )( AD )( BD ) =( AC )( AD )( BC )( BD )

  2. ( AB )( BC )( CA ) =( ( ( AB )B )( ( AB )C ) )( CA ) =( B( ( AC )( BC ) ) )( CA ) =( B( AC )( BC ) )( CA ) =( B( AC ) )( CA ) =( B( CA ) )( ( AC )( CA ) ) =( ( BC )( BA ) )( AC ) =( AB )( BC )( CA )

コード(Emacs)

Python 3

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from matplotlib_venn import venn3_unweighted
import matplotlib.pyplot as plt

from sympy import pprint, FiniteSet

A = FiniteSet(*range(10))
B = FiniteSet(*range(2, 11))
C = FiniteSet(*range(3, 12))
D = FiniteSet(*range(4, 14))

for X in [A, B, C, D]:
    pprint(X)

print('1.')
X1 = (A | B) & (C | D)
X2 = (A & C) | (A & D) | (B & C) | (B & D)
for X in [X1, X2]:
    pprint(X)
print(X1 == X2)

print('2.')
X1 = (A & B) | (B & C) | (C & A)
X2 = (A | B) & (B | C) & (C | A)
for X in [X1, X2]:
    pprint(X)
print(X1 == X2)

venn3_unweighted(subsets=(A, B, C))
plt.savefig('sample2.svg')

入出力結果(Terminal, Jupyter(IPython))

$ ./sample1.py
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
{2, 3, 4, 5, 6, 7, 8, 9, 10}
{3, 4, 5, 6, 7, 8, 9, 10, 11}
{4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
1.
{3, 4, 5, 6, 7, 8, 9, 10}
{3, 4, 5, 6, 7, 8, 9, 10}
True
2.
{2, 3, 4, 5, 6, 7, 8, 9, 10}
{2, 3, 4, 5, 6, 7, 8, 9, 10}
True
$

0 コメント:

コメントを投稿