from sage.all import cached_method, CommutativeRings, prod, Rational, factorial, floor, Matrix, ZZ, subsets, var, RR, repr_lincomb, vector
from sage.rings.commutative_algebra import CommutativeAlgebra
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.element import CommutativeAlgebraElement
from allstrata import StrataPyramid
from stratagraph import StrataGraph, PsiKappaVars, graph_count_automorphisms
from intersect import decorate_with_monomial, genericGHstructures, shared_edges
class StrataAlgebraElement(CommutativeAlgebraElement):
def __init__(self,parent,coef_dict):
if parent is None:
raise ValueError("The parent must be provided")
self.coef_dict = coef_dict
CommutativeAlgebraElement.__init__(self, parent)
def _repr_(self):
l = self.coef_dict.items()
l.sort()
return repr_lincomb([(self._pretty_basis_name(index[0],index[1]), coef) for index, coef in l])
#terms = [self._pretty_coef(coef,codim,index) for (codim,index),coef in l if coef != 0]
#if len(terms) >0:
# return " + ".join(terms)
#return "0"
def _pretty_basis_name(self, codim, index):
name = self.parent().get_stratum(codim,index).nice_name()
if name == None:
name = "s_{0},{1}".format(codim,index)
return name
def _add_(self, other):
new_dict = self.coef_dict.copy()
for (codim,index), coef in other.coef_dict.items():
dict_plus_equals(new_dict,(codim,index), coef)
return StrataAlgebraElement(self.parent(), new_dict)
def _mul_(self,other):
#print self, "*", other
new_dict = dict()
for (codim,index), coef in self.coef_dict.items():
for (codim1,index1), coef1 in other.coef_dict.items():
for prod_index, prod_coef in self.parent()._prod((codim, index), (codim1, index1)).items():
dict_plus_equals(new_dict,(codim+codim1,prod_index),coef*coef1*prod_coef)
return StrataAlgebraElement(self.parent(),new_dict)
def __div__(self, other):
#print "lets try to divide!!!!!!!!"
#print "self", self
#print "other", other
if 1/other in self.parent().base():
return StrataAlgebraElement(self.parent(), {i:c/other for i,c in self.coef_dict.items()})
else:
raise Exception("Tried to divide by {0}. Such division not possible!".format(other))
def integrate(self):
"""
Return the integral of this class, i.e. its degree in the top codimension.
Classes of codimension less that the dimension of the moduli space will integrate to 0.
This uses the FZ relations to perform the integration. It is probably not very efficient. But it provides a nice check of the implementation. Consider using the ``topintersections`` module if you need to compute something quickly. ::
sage: from strataalgebra import *
sage: s = StrataAlgebra(QQ,1,(1,2))
sage: (s.psi(1)*s.psi(2)).integrate()
1/24
sage: s.kappa(2).integrate()
1/24
sage: s.get_stratum(2,0) #just so you can see it.
[0 1 2 0 0]
[0 0 0 2 1]
[0 1 1 0 1]
sage: s(2,0).integrate()
1
sage: s(1,2).integrate()
0
sage: (42*s(2,0) + s(1,1) + 48*s.kappa(2)).integrate()
44
"""
if self.codim() < self.parent().moduli_dim:
return 0
result = 0
ints = self.parent().basis_integrals()
for (codim,index), coef in self.coef_dict.items():
if codim == self.parent().moduli_dim:
result += coef*ints[index]
return result
def dict(self):
"""
Return a dictionary with keys as :class:`StrataGraph` objects and values as the coefficient of that stratum in this element. ::
sage: from strataalgebra import *
sage: s = StrataAlgebra(QQ,1,(1,2,3)); s
Strata algebra with genus 1 and markings (1, 2, 3) over Rational Field
sage: a = s.psi(1)*s.psi(2) - 7* s.kappa(3); a
ps1*ps2 - 7*ka3
sage: a.dict()
{ps1*ps2: 1, ka3: -7}
"""
return {self.parent().strataP.get_stratum(r,i) : c for (r,i), c in self.coef_dict.items() if c !=0}
def __eq__(self, other):
if 0 in self.coef_dict.values():
self.coef_dict = {i:c for i,c in self.coef_dict.items() if c != 0}
if 0 in other.coef_dict.values():
other.coef_dict = {i:c for i,c in self.coef_dict.items() if c != 0}
return self.coef_dict == other.coef_dict
def in_kernel(self):
"""
Determine whether this :class:`StrataAlgebraElement` is in the span of the FZ relations, and hence in the kernel of the map to the tautological ring. ::
sage: from strataalgebra import *
sage: s = StrataAlgebra(QQ,0,(1,2,3,4,5))
sage: b = s.boundary(0,(1,2,5)) + s.boundary(0,(1,2)) - s.boundary(0,(1,3,5)) - s.boundary(0,(1,3))
sage: b
Dg0m1_2_5 + Dg0m1_2 - Dg0m1_3_5 - Dg0m1_3
sage: b.in_kernel()
True
sage: (s.psi(1) - s.psi(2)).in_kernel()
False
It should work fine for non-homogeneous things as well. ::
sage: (b + s.psi(1)).in_kernel()
False
sage: (b + s.psi(1)**2 - s.psi(2)**2).in_kernel()
True
"""
for codim in range(self.codim()+1):
v = vector([0]*self.parent().hilbert(codim))
for (cd, index), coef in self.coef_dict.items():
if cd == codim:
v[index] = coef
if v not in self.parent().FZ_matrix(codim).row_space():
return False
return True
def codim(self):
"""
Returns the codimensions of this :class:`StrataAlgebraElement`.
If it is not homogeneous, it retunrs the maximum codimension of a basis element with a non-zero coefficient. ::
sage: from strataalgebra import *
sage: s = StrataAlgebra(QQ,2)
sage: s(1,0).codim()
1
sage: s(2,1).codim()
2
sage: s(0,0).codim()
0
sage: (35*s(2,3) - 7*s(1,1) + s.kappa(2) - s(0,0)).codim()
2
sage: s.zero().codim()
-1
"""
codim = -1
for (cd, index), coef in self.coef_dict.items():
if cd > codim and coef != 0:
codim = cd
return codim
def dict_plus_equals(d, key, value):
if key in d.keys():
d[key]+=value
else:
d[key]=value
class StrataAlgebra(CommutativeAlgebra, UniqueRepresentation):
"""
StrataAlgebra
"""
#Need these to make the autodocs work.
get_stratum = StrataPyramid.get_stratum
FZ_matrix = StrataPyramid.FZ_matrix
FZ_matrix_pushforward_basis = StrataPyramid.FZ_matrix_pushforward_basis
print_strata = StrataPyramid.print_strata
def __init__(self,base,g,markings=(), make_vars = True):
r"""
A ring representing the Strata algebra.
:param Ring base: The ring of coefficients you want to work over, usually ``QQ``.
:param int g: The genus.
:param tuple markings: The markings should be positive integers. Repeats are allowed. Defaults to no markings.
:param bool make_vars: Defaults to True. If True, creates variables ``ps``, ``ps_``, ``ka1``, ... , ``ka{d}`` (where d is the dimension of the moduli spa
Python库 | mgn-1.1.0.tar.gz
版权申诉
155 浏览量
2022-04-10
20:31:19
上传
评论
收藏 49KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- UI Particle Image v1.2.2.unitypackage
- Highlight Plus All in One Outline Selection Effects v12.0
- ALINE v1.7.4.unitypackage
- Curvy Splines 8 v8.9.0.unitypackage
- Touch Camera PRO 2024 Easy Mobile Desktop Camera Controller3.1.2
- Translucent Image - Fast UI Background Blur v3.16.0.unitypackage
- STM32F103RC串口收发DMA程序
- 环境部署配置脚本-Tomcat
- SpringBoot+Vue实现图片滑块和文字点击验证码
- 基于参数优化多样性熵的滚动轴承故障诊断源代码,实现了对多个数据集的测试,并添加了排列熵、样本熵等方法的对比
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈