Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion dev/extended_ptolemy/complexVolumesClosed.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ def compute_representative_ptolemys_and_full_var_dict(M, precision = 53):
I, full_var_dict = extended.ptolemy_ideal_for_filled(
M, return_full_var_dict = 'data', notation = 'full')

rur = giac_rur.rational_univariate_representation(I)
try:
rur = giac_rur.rational_univariate_representation(I)
except giac_rur.GiacRURTooManyVariablesError as error:
raise ValueError(
"The extended Ptolemy ideal for this %d-tetrahedron "
"triangulation has %d variables. Giac %s's RUR "
"implementation crashes for more than %d variables, so this "
"Giac version limits this computation to triangulations with at "
"most 5 tetrahedra."
% (M.num_tetrahedra(), error.number_of_variables,
error.version_string,
giac_rur.GIAC_PRE_2_RUR_MAX_VARIABLES)) from None

return [
evaluate_at_roots(numberField, exact_values, precision)
Expand Down
35 changes: 35 additions & 0 deletions dev/extended_ptolemy/giac_rur.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@
functionality.
"""

import re

from sage.all import QQ, PolynomialRing, NumberField
from .giac_helper import giac

# Giac before 2.0 corrupts memory in its RUR code above this variable count.
GIAC_PRE_2_RUR_MAX_VARIABLES = 15


class GiacRURTooManyVariablesError(ValueError):
def __init__(self, number_of_variables, version):
self.number_of_variables = number_of_variables
self.version = version
self.version_string = '.'.join(str(part) for part in version)
super().__init__(
"Giac %s's RUR implementation crashes for more than %d "
"variables, and this ideal has %d variables."
% (self.version_string, GIAC_PRE_2_RUR_MAX_VARIABLES,
number_of_variables))


def _giac_version():
description = repr(giac('version()'))
match = re.search(
r'\bgiac\s+(\d+(?:\.\d+)+)', description, re.IGNORECASE)
if match is None:
raise RuntimeError('Could not determine Giac version from %s.'
% description)
return tuple(int(part) for part in match.group(1).split('.'))


# The main function of this file is:

def rational_univariate_representation(ideal):
Expand Down Expand Up @@ -61,6 +89,13 @@ def rational_univariate_representation(ideal):
"""
R = ideal.ring()

number_of_variables = len(R.gens())
if number_of_variables > GIAC_PRE_2_RUR_MAX_VARIABLES:
version = _giac_version()
if version < (2, 0):
raise GiacRURTooManyVariablesError(
number_of_variables, version)

# A "feature" introduced in Sage-9.4 is that
# ideal.gens() vs R.gens()
# returns
Expand Down