Fix typo in README.rst
[linpy.git] / examples / tutorial.py
1 #!/usr/bin/env python3
2
3 # This is the code example used in the tutorial. It shows how to define and
4 # manipulate polyhedra.
5
6 import code
7
8
9 class InteractiveConsole(code.InteractiveConsole):
10 def push(self, line=''):
11 if line:
12 print('>>>', line)
13 return super().push(line)
14 else:
15 print()
16
17
18 if __name__ == '__main__':
19
20 shell = InteractiveConsole()
21
22 shell.push('from linpy import *')
23 shell.push("x, y = symbols('x y')")
24 shell.push()
25
26 shell.push('square1 = Le(0, x, 2) & Le(0, y, 2)')
27 shell.push('square1')
28 shell.push()
29
30 shell.push("square2 = Polyhedron('1 <= x <= 3, 1 <= y <= 3')")
31 shell.push('square2')
32 shell.push()
33
34 shell.push('inter = square1.intersection(square2) # or square1 & square2')
35 shell.push('inter')
36 shell.push()
37
38 shell.push('hull = square1.convex_union(square2)')
39 shell.push('hull')
40 shell.push()
41
42 shell.push('proj = square1.project([y])')
43 shell.push('proj')
44 shell.push()
45
46 shell.push('inter <= square1')
47 shell.push('inter == Empty')
48 shell.push()
49
50 shell.push('union = square1.union(square2) # or square1 | square2')
51 shell.push('union')
52 shell.push('union <= hull')
53 shell.push()
54
55 shell.push('diff = square1.difference(square2) # or square1 - square2')
56 shell.push('diff')
57 shell.push('~square1')