First graphical steps to polyhedra

A tutorial from Tobias Grosser http://www.grosser.es This tutorial uses: - ipython: http://www.ipython.org - islpy: http://documen.tician.de/islpy/ - islplot: https://github.com/tobig/islplot

Load all necessary libraries

In [1]:
%pylab inline

# Load islpy without prefix
from islpy import *

# Load isl with prefix (either this or the previous definition is optional)
import islpy

# Load islplot
from islplot.plotter import *

# Adjust figure size
pylab.rcParams['figure.figsize'] = (8.0, 6.0)
Populating the interactive namespace from numpy and matplotlib

Sets

In [2]:
# Background
s = Set("{[i,j]: 0 < i,j < 7}")
plot_set_points(s, marker='+', size=20, color="gray")

# Define a set
s2 = Set("{[i,j]: 1 < i,j and i + j < 8}")

# The elements of a set
s2.foreach_point(lambda p: print(p))

# Plot a set
plot_set_points(s2, color="red")
plot_set_shapes(s2, color="red", alpha=0.5)
[2, 2]
[2, 3]
[2, 4]
[2, 5]
[3, 2]
[3, 3]
[3, 4]
[4, 2]
[4, 3]
[5, 2]

Maps

In [3]:
# Background
s = Set("{[i,j]: 0 < i,j < 10}")
plot_set_points(s, marker='+', size=20, color="gray")

# Plot previous shape
plot_set_points(s2, color="red")
plot_set_shapes(s2, color="red", alpha=0.5)

# Translate a shape
m = Map("{[i,j] -> [i + 2, j + 3]}")
s3 = s2.apply(m)
plot_set_points(s3, color="blue")
plot_set_shapes(s3, color="blue", alpha=0.5)

# Illustrate translation map
plot_map(m.intersect_domain(s2).intersect_range(s3))

A simple rectangular tiling

In [4]:
# Background
s = Set("{[i,j]: -2 < i,j < 12}")
plot_set_points(s, marker='+', size=15, color="gray")

domain = Set("{[i,j]: 0 < i,j < 10}")
tiling_map = Map("{[i,j] -> [floor(i/4), floor(j/4)]}")

plot_map_as_groups(tiling_map.intersect_domain(domain), color='red', alpha=0.5)

AST Generation

In [5]:
build = AstBuild.from_context(Set("{:}"))
tiling_map = Map("{[i,j] -> [4 * floor(i/4), 4 * floor(j/4)]}")
schedule = tiling_map
ast = build.ast_from_schedule(schedule.intersect_domain(domain))

p = Printer.to_str(Context())
p = p.set_output_format(format.C)
p = p.print_ast_node(ast)
print(p.get_str())
for (int c0 = 0; c0 <= 9; c0 += 4)
  for (int c1 = 0; c1 <= 8; c1 += 4)
    for (int c2 = max(1, c0); c2 <= min(9, c0 + 3); c2 += 1)
      for (int c3 = max(1, c1); c3 <= min(9, c1 + 3); c3 += 1)
        (c2, c3);

Plotting in 3D

In [6]:
from islpy import Set
from islplot.plotter3d import plot_set_3d
from IPython.display import HTML
In [7]:
s = Set("{ [i, j, k] : 0 <= i,k,j and i + j, k < 8 } ")
d = plot_set_3d(s, show_points=True)
HTML(d)
Out[7]: