Use OrderedDict to store Expression coefficients
[linpy.git] / examples / squares.py
1 #!/usr/bin/env python3
2
3 from pypol import *
4
5 x, y = symbols('x y')
6
7 sq1 = Le(0, x) & Le(x, 2) & Le(0, y) & Le(y, 2)
8 sq2 = Le(1, x) & Le(x, 3) & Le(1, y) & Le(y, 3)
9
10 sq3 = Le(0, x) & Le(x, 3) & Le(0, y) & Le(y, 3)
11 sq4 = Le(1, x) & Le(x, 2) & Le(1, y) & Le(y, 2)
12 sq5 = Le(1, x) & Le(x, 2) & Le(1, y)
13 u = Polyhedron([])
14
15 print('sq1 =', sq1) #print correct square
16 print('sq2 =', sq2) #print correct square
17 print('sq3 =', sq3) #print correct square
18 print('sq4 =', sq4) #print correct square
19 print('u =', u) #print correct square
20 print()
21 print('¬sq1 =', ~sq1) #test compliment
22 print()
23 print('sq1 + sq1 =', sq1 + sq2) #test addition
24 print('sq1 + sq2 =', Polyhedron(sq1 + sq2))
25 print('sq1 - sq1 =', u - u)
26 print('sq2 - sq1 =', sq2 - sq1) #test subtraction
27 print('sq2 - sq1 =', Polyhedron(sq2 - sq1))
28 print('sq1 - sq1 =', Polyhedron(sq1 - sq1)) #test polyhedreon
29 print()
30 print('sq1 ∩ sq2 =', sq1 & sq2) #test intersection
31 print('sq1 ∪ sq2 =', sq1 | sq2) #test union
32 print()
33 print('sq1 ⊔ sq2 =', Polyhedron(sq1 | sq2)) #test convex union
34 print()
35 print('check if sq1 and sq2 disjoint:', sq1.isdisjoint(sq2)) #should return false
36 print()
37 print('sq1 disjoint:', sq1.disjoint()) #make disjoint
38 print('sq2 disjoint:', sq2.disjoint()) #make disjoint
39 print()
40 print('is square 1 universe?:', sq1.isuniverse()) #test if square is universe
41 print('is u universe?:', u.isuniverse()) #test if square is universe
42 print()
43 print('is sq1 a subset of sq2?:', sq1.issubset(sq2)) #test issubset()
44 print('is sq4 less than sq3?:', sq4.__lt__(sq3)) # test lt(), must be a strict subset
45 print()
46 print('lexographic min of sq1:', sq1.lexmin()) #test lexmin()
47 print('lexographic max of sq1:', sq1.lexmax()) #test lexmin()
48 print('lexographic min of sq2:', sq2.lexmin()) #test lexmax()
49 print('lexographic max of sq2:', sq2.lexmax()) #test lexmax()
50 print()
51 print('Polyhedral hull of sq1 is:', sq1.polyhedral_hull())
52 print()
53 print('is sq1 bounded?', sq1.isbounded())
54 print('is sq5 bounded?', sq5.isbounded())