#
# GetDualNefId(nef) returns the id of the mirror dual nef partition, given an element of the list obtained
# by polytope.nef_partitions().
# This function is quite a hack since nef_partitions() does only return nef partitions up to equivalence due to symmetries.
# nef.x offers an option to return all nef partitions without taking equivalences into account but then it seems to be
# non-trivial to identify identical nefs. This implementation works but its not pretty.
#
def GetDualNefId(nef, recursion = false):
polyId = nef.Delta_polar().index()
dualPolyId = nef.nabla_polar().index()
dualNefId = -1
dualPartitions = ReflexivePolytope(3, dualPolyId).nef_partitions()
if len(dualPartitions) == 1:
dualNefId = 0
if dualNefId == -1:
dualIds = [dualNef.nabla_polar().index() for dualNef in dualPartitions]
if len([id for id in dualIds if id == polyId]) == 1:
dualNefId = dualIds.index(polyId)
if dualNefId == -1:
permutation = nef.nabla_polar().normal_form(permutation = true)[1]
mapping = tuple(vector(permutation.tuple()) - vector([1] * len(permutation.domain())))
inverseMapping = tuple(vector(permutation.inverse().tuple()) - vector([1] * len(permutation.domain())))
permutationDual = ReflexivePolytope(3, nef.nabla_polar().index()).normal_form(permutation = true)[1]
inverseMappingDual = tuple(vector(permutationDual.inverse().tuple()) - vector([1] * len(permutationDual.domain())))
dualPolyId = nef.nabla_polar().index()
part1 = [inverseMapping[i] for i in nef.dual().part(0)]
part1.sort()
part2 = [inverseMapping[i] for i in nef.dual().part(1)]
part2.sort()
for nefDual in enumerate(dualPartitions):
if nefDual[1].nabla_polar().index() == polyId and tuple(part1) == nefDual[1].part(0) or tuple(part1) == nefDual[1].part(1):
dualNefId = nefDual[0]
break
if dualNefId == -1 and not recursion:
for dualNef in enumerate(dualPartitions):
if dualNef[1].nabla_polar().index() == polyId:
doubleDualId = GetDualNefId(dualNef[1], recursion = true)
if ReflexivePolytope(3, polyId).nef_partitions()[doubleDualId[1]].part(0) == nef.part(0):
dualNefId = dualNef[0]
break
if dualNefId == -1:
hash1 = hash(nef.dual().Delta(0).normal_form()) if nef.dual().Delta(0).dim() == 3 else 0
hash2 = hash(nef.dual().Delta(1).normal_form()) if nef.dual().Delta(1).dim() == 3 else 0
if (not hash1 == 0) or (not hash2 == 0):
for nefDual in enumerate(dualPartitions):
if nefDual[1].nabla_polar().index() == polyId:
if nefDual[1].Delta(0).dim() == 3:
dualHash = hash(nefDual[1].Delta(0).normal_form())
elif nefDual[1].Delta(1).dim() == 3:
dualHash = hash(nefDual[1].Delta(1).normal_form())
else:
continue
if dualHash == hash1 or dualHash == hash2:
dualNefId = nefDual[0]
break
return (dualPolyId, dualNefId)
#
# The following cell calculates the mirror dual nef ids for all complete intersection fibers
# in three dimensional toric ambient spaces. The data is saved in a dictionary "dualDict" and saved
# in the file "intersection.txt". The dual ids can be accessed via dualDict[(polyid, nefid)]
#
# if you work in a jupyter notebook with widgets, set the following flag to "True"
jupyter = True
npoly = 4319
if jupyter:
from IPython.html.widgets import FloatProgress
from IPython.display import display
from IPython.html.widgets import HTML
boxPolyId = HTML("")
boxNefId = HTML("")
display(boxPolyId)
display(boxNefId)
f = FloatProgress(min=0, max=npoly)
display(f)
dualDict = {}
for polyId in xrange(npoly):
if jupyter:
f.values = polyId
boxPolyId.value = "polytope id: " + str(polyId)
for nef in enumerate(ReflexivePolytope(3, polyId).nef_partitions()):
if jupyter:
boxNefId.value = "nef id: " + str(nef[0])
dualid = GetDualNefId(nef[1])
dualDict[(polyId, nef[0])] = dualid
with open("dualids.txt", "w") as f:
f.write("{\n")
for item in sorted(sorted(dualDict.items(), key=lambda a: a[0][1]), key=lambda a: a[0][0]):
f.write(str(item[0]) + ": " + str(item[1]) + ",\n")
f.write("}")