sage import

This commit is contained in:
Maria Marchwicka 2021-01-13 21:21:05 +01:00
parent b2feb908e1
commit 85478f7e1a
5 changed files with 39 additions and 81 deletions

View File

@ -8,20 +8,18 @@ from typing import Iterable
from collections import Counter
from sage.arith.functions import LCM_list
import importlib
from .utility import import_sage
from .utility import import_sage, mod_one
from . import signature as sig
SIGMA = 0
SIGNATURE = 1
package = __name__.split('.')[0]
path = os.path.dirname(__file__)
sig = import_sage('signature', package=package, path=path)
# #############################################################################
# 9.11 (9.8)
# 9.15 (9.9)
PLOTS_DIR = "plots"
PLOTS_DIR = "../plots"
class CableSummand:
@ -343,8 +341,8 @@ class CableSum:
else:
save_path = None
for theta, knot in zip(thetas, self.knot_summands):
knot.plot_summand_for_theta(thetas, save_path=save_path)
# for theta, knot in zip(thetas, self.knot_summands):
# knot.plot_summand_for_theta(thetas, save_path=save_path)
# pp, sp, sf = self.signature_as_function_of_theta(*thetas)
# title = self.knot_description + ", thetas = " + str(thetas)
@ -670,8 +668,6 @@ class CableTemplate:
return CableTemplate(knot_formula)
def mod_one(n):
return n - floor(n)
CableSum.get_signature_as_function_of_theta.__doc__ = \

View File

@ -13,11 +13,11 @@ import re
import numpy as np
import importlib
from .utility import import_sage
from . import signature as sig
from . import cable_signature as cs
package = __name__.split('.')[0]
path = os.path.dirname(__file__)
sig = import_sage('signature', package=package, path=path)
cs = import_sage('cable_signature', package=package, path=path)
class Config:
@ -266,45 +266,3 @@ if __name__ == '__main__':
# "[-k[0], -k[5], -k[7]]]"
#
#
"""
This script calculates signature functions for knots (cable sums).
The script can be run as a sage script from the terminal
or used in interactive mode.
A knot (cable sum) is encoded as a list where each element (also a list)
corresponds to a cable knot, e.g. a list
[[1, 3], [2], [-1, -2], [-3]] encodes
T(2, 3; 2, 7) # T(2, 5) # -T(2, 3; 2, 5) # -T(2, 7).
To calculate the number of characters for which signature function vanish use
the function eval_cable_for_null_signature as shown below.
sage: eval_cable_for_null_signature([[1, 3], [2], [-1, -2], [-3]])
T(2, 3; 2, 7) # T(2, 5) # -T(2, 3; 2, 5) # -T(2, 7)
Zero cases: 1
All cases: 1225
Zero theta combinations:
(0, 0, 0, 0)
sage:
The numbers given to the function eval_cable_for_null_signature are k-values
for each component/cable in a direct sum.
To calculate signature function for a knot and a theta value, use function
get_signature_as_function_of_theta (see help/docstring for details).
About notation:
Cables that we work with follow a schema:
T(2, q_1; 2, q_2; 2, q_4) # -T(2, q_2; 2, q_4) #
# T(2, q_3; 2, q_4) # -T(2, q_1; 2, q_3; 2, q_4)
In knot_formula each k[i] is related with some q_i value, where
q_i = 2*k[i] + 1.
So we can work in the following steps:
1) choose a schema/formula by changing the value of knot_formula
2) set each q_i all or choose range in which q_i should varry
3) choose vector v / theata vector.
"""

View File

@ -6,6 +6,7 @@ import inspect
from PIL import Image
from pathlib import Path
import warnings
from .utility import mod_one
# 9.11 (9.8)
# 9.15 (9.9)
@ -13,8 +14,6 @@ import sys
import os
JUPYTER = 'ipykernel'
IPy_TERMINAL = 'IPython'
@ -366,8 +365,6 @@ class SignaturePloter:
"""
f.write(tail)
def mod_one(n):
return n - floor(n)
SignatureFunction.__doc__ = \
"""
@ -380,19 +377,3 @@ SignatureFunction.__doc__ = \
and value encodes the value of the jump. Remember that we treat
signature functions as defined on the interval [0,1).
"""
mod_one.__doc__ = \
"""
Argument:
a number
Return:
the fractional part of the argument
Examples:
sage: mod_one(9 + 3/4)
3/4
sage: mod_one(-9 + 3/4)
3/4
sage: mod_one(-3/4)
1/4
"""

View File

@ -2,25 +2,40 @@ import importlib
import os
import sys
import re
import math
def mod_one(n):
"""
Argument:
a number
Return:
the fractional part of the argument
Examples:
sage: mod_one(9 + 3/4)
3/4
sage: mod_one(-9 + 3/4)
3/4
sage: mod_one(-3/4)
1/4
"""
return n - math.floor(n)
def import_sage(module_name, package=None, path=None):
def import_sage(module_name, package=None, path=''):
"""
Import or reload SageMath modules with preparse if the sage file exist.
"""
sage_name = module_name + ".sage"
python_name = module_name + ".sage.py"
if package is not None:
path_from_package_name = re.sub(r'\.', r'\\', package)
file_path = os.path.join('', path, path_from_package_name)
else:
file_path = os.path.join('', path)
path = os.path.join(path, path_from_package_name)
sage_path = os.path.join(file_path, sage_name)
python_path = os.path.join(file_path, python_name)
module_path = os.path.join(file_path, module_name)
sage_path = os.path.join(path, sage_name)
python_path = os.path.join(path, python_name)
module_path = os.path.join(path, module_name)
if os.path.isfile(sage_path):
os.system('sage --preparse {}'.format(sage_path));

8
notebooks/path.py Normal file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import sys
import os
module_path = os.path.abspath(os.pardir)
if module_path not in sys.path:
sys.path.append(module_path)