# Cartesian Product of Polytopes

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

## 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):

[(0,),(1,)]

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

[
[(0,0),(1,0)],
[(1,0),(0,1)],
[(0,1),(0,0)]
]

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]
else:
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

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5
JoeJ
12

• 12
• 21
• 9
• 31
• 16
• ### Forum Statistics

• Total Topics
632618
• Total Posts
3007466
• ### Who's Online (See full list)

There are no registered users currently online

×