Fix 3d plots in examples
[linpy.git] / examples / nsad2010.py
index 8194618..3de2ebd 100755 (executable)
@@ -1,6 +1,14 @@
 #!/usr/bin/env python3
 
 #!/usr/bin/env python3
 
-from pypol import *
+# This is an implementation of the algorithm described in
+#
+# [ACI10] C. Ancourt, F. Coelho and F. Irigoin, A modular static analysis
+# approach to affine loop invariants detection (2010), pp. 3 - 16, NSAD 2010.
+#
+# to compute the transitive closure of an affine transformer. A refined version
+# of this algorithm is implemented in PIPS.
+
+from linpy import Dummy, Eq, Ge, Polyhedron, symbols
 
 
 class Transformer:
 
 
 class Transformer:
@@ -20,9 +28,10 @@ class Transformer:
         delta_symbols = [symbol.asdummy() for symbol in self.range_symbols]
         k = Dummy('k')
         polyhedron = self.polyhedron
         delta_symbols = [symbol.asdummy() for symbol in self.range_symbols]
         k = Dummy('k')
         polyhedron = self.polyhedron
-        for x, xprime, dx in zip(self.range_symbols, self.domain_symbols, delta_symbols):
+        for x, xprime, dx in zip(
+                self.range_symbols, self.domain_symbols, delta_symbols):
             polyhedron &= Eq(dx, xprime - x)
             polyhedron &= Eq(dx, xprime - x)
-        polyhedron = polyhedron.project_out(self.symbols)
+        polyhedron = polyhedron.project(self.symbols)
         equalities, inequalities = [], []
         for equality in polyhedron.equalities:
             equality += (k-1) * equality.constant
         equalities, inequalities = [], []
         for equality in polyhedron.equalities:
             equality += (k-1) * equality.constant
@@ -31,16 +40,17 @@ class Transformer:
             inequality += (k-1) * inequality.constant
             inequalities.append(inequality)
         polyhedron = Polyhedron(equalities, inequalities) & Ge(k, 0)
             inequality += (k-1) * inequality.constant
             inequalities.append(inequality)
         polyhedron = Polyhedron(equalities, inequalities) & Ge(k, 0)
-        polyhedron = polyhedron.project_out([k])
-        for x, xprime, dx in zip(self.range_symbols, self.domain_symbols, delta_symbols):
+        polyhedron = polyhedron.project([k])
+        for x, xprime, dx in zip(
+                self.range_symbols, self.domain_symbols, delta_symbols):
             polyhedron &= Eq(dx, xprime - x)
             polyhedron &= Eq(dx, xprime - x)
-        polyhedron = polyhedron.project_out(delta_symbols)
+        polyhedron = polyhedron.project(delta_symbols)
         return Transformer(polyhedron, self.range_symbols, self.domain_symbols)
 
 
 if __name__ == '__main__':
         return Transformer(polyhedron, self.range_symbols, self.domain_symbols)
 
 
 if __name__ == '__main__':
-    i, iprime, j, jprime = symbols("i i' j j'")
-    transformer = Transformer(Eq(iprime, i + 2) & Eq(jprime, j + 1),
-        [i, j], [iprime, jprime])
+    i0, i, j0, j = symbols('i0 i j0 j')
+    transformer = Transformer(Eq(i, i0 + 2) & Eq(j, j0 + 1),
+                              [i0, j0], [i, j])
     print('T  =', transformer.polyhedron)
     print('T* =', transformer.star().polyhedron)
     print('T  =', transformer.polyhedron)
     print('T* =', transformer.star().polyhedron)