• Advertisement
Sign in to follow this  

Cartesian Product of Polytopes

This topic is 462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose I have a general n-polytope, whose faces are a list of (n-1)-polytopes. For example:
A 1-dimensional 1-simplex (line segment) would be represented as two 1-dimensional 0-simplexes (points):

A 2-dimensional 2-simplex (triangle) would be represented as three 2-dimensional 1-simplexes (line segments):


And so on...

I would like to compute the Cartesian product of two arbitrary polytopes. I came up with the following algorithm, and I am wondering whether it is correct:
def product(xs, ys):
    if isinstance(xs, list) and isinstance(ys, list):
        return [product(xs, y) for y in ys] + [product(x, ys) for x in xs]
    elif isinstance(ys, list):
        return [product(xs, y) for y in ys]
    elif isinstance(xs, list):
        return [product(x, ys) for x in xs]
        return xs + ys

You can make things a bit nicer by wrapping things in a class:
class Polytope(object):
    def __init__(self, data):
        self.data = data
    def __mul__(self, other):
        return Polytope(product(self.data, other.data))
    def __str__(self):
        import pprint
        return pprint.pformat(self.data)

With this, you can do things like:
cube = Polytope([(0,),(1,)])

print("1-cube:", cube, sep="\n")
print("2-cube:", cube*cube, sep="\n")
print("3-cube:", cube*cube*cube, sep="\n")

The results seem correct, but I still need to convince myself that it works in all cases. Since I couldn't find much material online, I was curious if anybody has done this kind of thing or knows any further resources. Edited by kloffy

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement