2017年9月20日水曜日

学習環境

集合・位相入門 (松坂 和夫(著)、岩波書店)の第1章(集合と写像)、2(集合間の演算)、練習問題3を取り組んでみる。


    1. AB=A B c ( AB )B =AB =A B c A( AB ) =AB =A B c

    2. AB =A B c =A AB=ϕ

    3. AB=ϕ A B c =ϕ AB

コード(Emacs)

Python 3

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

from matplotlib_venn import venn2
import matplotlib.pyplot as plt

from sympy import pprint, FiniteSet, Interval

print('3.')
print('(a)')
X = FiniteSet(*range(10))
A = FiniteSet(*range(5))
B = FiniteSet(*range(5, 10))
X1 = A - B
X2 = (A | B) - B
X3 = A - (A & B)
X4 = A & B.complement(X)
for X in [A, B, X1, X2, X3, X4]:
    pprint(X)

print(X1 == X2 == X3 == X4)
venn2(subsets=(A, B))
plt.savefig('sample3_a.svg')

print('(b)')
A = Interval.open(0, 1)
B = Interval.open(1, 2)

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

print(A - B == A)
print(A & B == FiniteSet())

print('(c)')
A = FiniteSet(*range(5))
B = FiniteSet(*range(10))
pprint(A - B)
print(A.is_subset(B))
print(B.is_superset(A))

venn2(subsets=(A, B))
plt.savefig('sample3_c.svg')

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

$ ./sample3.py
3.
(a)
{0, 1, 2, 3, 4}
{5, 6, 7, 8, 9}
{0, 1, 2, 3, 4}
{0, 1, 2, 3, 4}
{0, 1, 2, 3, 4}
{0, 1, 2, 3, 4}
True
(b)
(0, 1)
(1, 2)
True
True
(c)
∅
True
True
$

0 コメント:

コメントを投稿