Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This scripts was used to find the edges in the following Hasse diagram:
- # https://commons.wikimedia.org/wiki/File:Predicate_logic;_3_variables;_implications.png
- import numpy as np
- # The "octal" representation is the base of the calculation.
- # The octal notation is motivated by the similarity of the following Hasse diagram with the cube:
- # https://commons.wikimedia.org/wiki/File:Predicate_logic;_2_variables;_implications;_pairs.svg
- octal = [
- '777',
- '733', '376', '667',
- '731', '713', '374', '176', '647', '467',
- '711', '174', '447',
- '330', '603', '066',
- '310', '130', '601', '403', '064', '046',
- '110', '401', '044',
- '000',
- '577', '533', '266', '511', '244', '200',
- '757', '356', '623', '154', '421', '020',
- '775', '665', '332', '445', '112', '002',
- '555', '222'
- ]
- # The abbreviations are just used in the output.
- abbr = [
- 'e123',
- 'a3e12', 'a2e13', 'a1e23',
- 'e2a3e1', 'e1a3e2', 'e3a2e1', 'e1a2e3', 'e3a1e2', 'e2a1e3',
- 'e12a3', 'e13a2', 'e23a1',
- 'a23e1', 'a13e2', 'a12e3',
- 'a2e1a3', 'a3e1a2', 'a1e2a3', 'a3e2a1', 'a1e3a2', 'a2e3a1',
- 'e1a23', 'e2a13', 'e3a12',
- 'a123',
- 'e(12)3', 'a3e(12)', 'a(12)e3', 'e(12)a3', 'e3a(12)', 'a(12)3',
- 'e(13)2', 'a2e(13)', 'a(13)e2', 'e(13)a2', 'e2a(13)', 'a(13)2',
- 'e1(23)', 'a1e(23)', 'a(23)e1', 'e(23)a1', 'e1a(23)', 'a1(23)',
- 'e(123)', 'a(123)'
- ]
- length = len(octal)
- # This function checks if v1 implies v2.
- def follows(v1, v2):
- def digit(d1, d2):
- d1 = int(d1)
- d2 = int(d2)
- if (d1 & d2 == d1) or (d1 == 2 and d2 == 5): # bitwise smaller or central arrow
- return True
- else:
- return False
- result = True
- for i in range(3):
- if not digit(v1[i], v2[i]):
- result = False
- return result
- hasse = np.zeros((length, length), np.int8)
- for (i, v1) in enumerate(octal):
- for (j, v2) in enumerate(octal):
- hasse[i, j] = follows(v1, v2)
- for i in range(length):
- hasse[i, i] = 0
- # A Hasse diagram is supposed to contain no redundant edges,
- # so if i implies k and k implies j, there shall be no edge from i to j.
- def clean(mat):
- for i in range(length):
- for j in range(length):
- if mat[i, j] == 1:
- for k in range(length):
- if hasse[i, k] == 1 and hasse[k, j] == 1:
- mat[i, j] = 0
- return mat
- hasse = clean(hasse)
- if np.array_equal(hasse, clean(hasse)):
- print 'cleaning successful'
- # Print the number of edges in the Hasse diagram (139).
- print hasse.sum()
- # Print all edges of the Hasse diagram.
- for i in range(length):
- for j in range(length):
- if hasse[i, j] == 1:
- print abbr[i] + ' --> ' + abbr[j]
- # The output can the found here: http://pastebin.com/ADwKEkgx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement