ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 Feb 2022 15:18:43 +0100Possible bug - specifying category messes up coercion?https://ask.sagemath.org/question/60903/possible-bug-specifying-category-messes-up-coercion/The snippet
D = CombinatorialFreeModule(ZZ, [1,2])
D(0)
works fine, however
C = CombinatorialFreeModule(ZZ, [1,2], category=AlgebrasWithBasis(ZZ))
C(0)
gets into an infinite loop:
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/magmas.py", line 488, in one
return self(1)
File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
return mor._call_(x)
File "sage/categories/map.pyx", line 1694, in sage.categories.map.FormalCompositeMap._call_ (build/cythonized/sage/categories/map.c:11607)
x = f._call_(x)
File "sage/categories/morphism.pyx", line 549, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8489)
cpdef Element _call_(self, x):
File "sage/categories/morphism.pyx", line 568, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8439)
return self._function(x)
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/unital_algebras.py", line 70, in from_base_ring
return self.one()._lmul_(r)
File "sage/misc/cachefunc.pyx", line 2310, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
self.cache = f(self._instance)
Why is this? Is this expected behaviour?makosWed, 02 Feb 2022 15:18:43 +0100https://ask.sagemath.org/question/60903/Define morphism of Q[i,w] in terms of i and whttps://ask.sagemath.org/question/58849/define-morphism-of-qiw-in-terms-of-i-and-w/ I want to construct the field $K=Q[i,w]$ where $w=\sqrt[4]{2}$ and define a field homomorphism such as $w\mapsto iw$, $i\mapsto -i$.
I'd like to do
K.<w,I> = NumberField([x^4-2,x^2+1])
H = End(K)
H([I*w,-I])
but it doesn't work because $K$ is considered to be the relative field $(Q[i])[w]$.
I know I could work with the absolute field
K_abs.<theta> = K.absolute_field()
but I'd really like to define the morphism in terms of $w,i$. Is it possible?
JNSMon, 06 Sep 2021 10:35:27 +0200https://ask.sagemath.org/question/58849/codomain could not be determinedhttps://ask.sagemath.org/question/42732/codomain-could-not-be-determined/ I created an InfiniteDimensionalFreeAlgebra using CombinatorialFreeModule. It looks something like this:
class InfiniteDimensionalFreeAlgebra(CombinatorialFreeModule):
r""" The algebra generated by ``a[0], a[1], a[2], ...`` over the integers. """
def __init__(self,
base_ring=IntegerRing(),
prefix='a',
index_set=NonNegativeIntegerSemiring()):
self._base_ring = base_ring
self._basis_monoid = FreeMonoid(index_set=index_set, commutative=True, prefix=prefix)
# category
category = Algebras(self._base_ring.category()).WithBasis().Commutative()
category = category.or_subcategory(category)
# init
CombinatorialFreeModule.__init__(
self,
self._base_ring,
self._basis_monoid,
category=category,
prefix='',
bracket=False)
Now I want to view it as a *ring* and take symmetric polynomials over the ring. For example, in 2 variables, the following is one such symmetric polynomial:
2a[7] * x[1] + 2a[7] * x[2] + x[1]x[2] + 5
In my code, I attempt to initialize some Schur symmetric functions over this ring with something like:
a = InfiniteDimensionalFreeAlgebra()
sym = SymmetricFunctions(a)
s = sym.s()
one = s.one()
one_poly = one.expand(2)
at which point I run into the error `codomain could not be determined` when it attempts to apply some sort of morphism to the Schur function `one`. The full stacktrace is
Traceback (most recent call last):
File "./test_all.py", line 1162, in <module>
h = double_homogeneous(1, 1)
File "/Users/Matthew/programming/sage/morse-code/k_combinat_for_sage/all.py", line 664, in double_homogeneous
one_poly = one.expand(n)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/schur.py", line 537, in expand
return self._expand(condition, n, alphabet)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/sfa.py", line 4986, in _expand
return parent._apply_module_morphism(self, f)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/categories/modules_with_basis.py", line 1096, in _apply_module_morphism
raise ValueError('codomain could not be determined')
ValueError: codomain could not be determined
and the full code can be found at [k_combinat_for_sage](https://github.com/MareoRaft/k_combinat_for_sage/blob/master/k_combinat_for_sage/all.py).
Thank you, your help is greatly appreciated.ml9nnMon, 25 Jun 2018 21:12:25 +0200https://ask.sagemath.org/question/42732/Map between projective curves defined in an extension fieldhttps://ask.sagemath.org/question/38263/map-between-projective-curves-defined-in-an-extension-field/For example, suppose I have the following 2 projective curves:
k = GF(13)
x,y,z = ProjectiveSpace(k, 2, 'x,y,z').gens()
E = Curve(2*x^2 + 8*y*z + 8*z^2)
W = Curve(x^2 + y*z + z^2)
I like to define a map from E to W that involves $\sqrt 2$ and $\sqrt 8$, which do not exist in k = GF(13), but do in an extension of k:
x = PolynomialRing(k,'x').gen()
K = GF(13**2, 'w', modulus=x^2-2)
w = K.gen()
So $w = \sqrt 2$ and $2w = \sqrt 8$. The map I like to define sends $(x:y:z)$ to $(wx:2wy:2wz)$.
In this particular example, it's obvious that $(wx:2wy:2wz) = (x:2y:2z)$; but it's just a simple example do demonstrate the problem.
Something like this doesn't work:
x,y,z = ProjectiveSpace(k, 2, 'x,y,z').gens() #or ProjectiveSpace(K, 2, 'x,y,z').gens()
E.Hom(W)([w*x, 2*w*y, 2*w*z])
Thank you.RoadFri, 14 Jul 2017 18:08:01 +0200https://ask.sagemath.org/question/38263/Compose Affine/Projective Curve morphism with Elliptic Curve isogenyhttps://ask.sagemath.org/question/38045/compose-affineprojective-curve-morphism-with-elliptic-curve-isogeny/When I tried to do this, I got TypeError: ... must be a map to multiply it by Isogeny ...
And when I tried to dehomogenize projective curve morphism in x,y,z by z-coordinate, the remaining variables become x0 and x1. Can I keep them as x and y instead?
EDIT: Example code:
k = GF(23)
x,y,z = k['x,y,z'].gens()
d = k(2)
C = Curve([x^3+y^3+z^3-3*d*x*y*z]) #domain curve
a = d+2
b = 4*(d^2+d+1)/3
E = EllipticCurve(y^2-x^3-(a*x+b)^2) #codomain curve
m = b
n = 4*(d^3 -1)/3
X = m*(x+y+z)
Y = n*(z-y)
Z = -z-y-d*x
f = C.Hom(E)([X,Y,Z]) #map from C to E
Q = E(2,9,1) #a point on E
g = E.isogeny(Q) #isogeny
g*f #TypeError hereRoadWed, 21 Jun 2017 17:43:25 +0200https://ask.sagemath.org/question/38045/Unable to coerce dictionary to morphism between finite posetshttps://ask.sagemath.org/question/34059/unable-to-coerce-dictionary-to-morphism-between-finite-posets/Using the code below, I am unsure why I cannot form the identity map (or others such as constant maps) via dictionary. I have done the same process for finite simplicial complexes, so maybe this isn't implemented for finite posets? Thanks for any help!
The input:
X=Poset({1:[],2:[1]}) <br>
Hom(X,X)({1:1,2:2})
The output error message:
TypeError: Unable to coerce x (={1: 1, 2: 2}) to a morphism in Set of Morphisms from Finite poset containing 2 elements to Finite poset containing 2 elements in Join of Category of finite posets and Category of finite enumerated sets and Category of facade sets jobrien715Sat, 09 Jul 2016 10:53:21 +0200https://ask.sagemath.org/question/34059/Sparse morphism versus sparse matrixhttps://ask.sagemath.org/question/10543/sparse-morphism-versus-sparse-matrix/I would like to use VectorSpaceMorphism when the underlying domain, codomain and matrix are sparse. However, the morphism seems to convert everything to dense. The following is from Sage 5.9.
sage: V = VectorSpace(QQ, 2, sparse=True)
sage: V
Sparse vector space of dimension 2 over Rational Field
sage: A = matrix(QQ, 2, 2, [[5, 6], [7, 8]], sparse=True)
sage: type(A)
sage.matrix.matrix_rational_sparse.Matrix_rational_sparse
sage: f = V.hom(A, V)
sage: f.matrix()
[5 6]
[7 8]
sage: type(f.matrix())
sage.matrix.matrix_rational_dense.Matrix_rational_dense
V.hom doesn't take the keyword 'sparse'.
sage: g = V.hom(A, V, sparse=True)
...
TypeError: hom() got an unexpected keyword argument 'sparse'
Let v be a vector in V, which is sparse. Tests with pdb show that when we call f(v), it converts v to dense behind the scenes, multiplies by the dense matrix, and
converts the dense vector result back to sparse. Of course this is slow. The more fundamental issue is that, in some of my applications, A will be too large to store densely.mmcconnellTue, 17 Sep 2013 01:08:35 +0200https://ask.sagemath.org/question/10543/Create Morphism's between Finite Fields and VectorSpaceshttps://ask.sagemath.org/question/10379/create-morphisms-between-finite-fields-and-vectorspaces/Hallo,
I am interested in creating morphims between $GF(2^{n+1}) \stackrel{h_1}{\longrightarrow} H_u \stackrel{h_2}\longrightarrow GF(2^n)$ where $H_u=\{x^{2^i} + x : x \in GF(2^{n+1})\}$ where $gcd(i,n+1) =1$. I am interested in constructing $h_1$ and $h_2$,
My attempt to create $h_1$ is:
<pre>
<code>
n = 4
i = 1
f = lambda x : x^(2^i) + x
Kn_1 = GF(2^(n+1),'x')
H_u = map(f, Kn_1)
hs = Hom(Kn_1,H_u)
pi = SetMorphism(Hom(Kn_1,Kn), lambda y : y^(2^i) + y)
pi(Kn_1.random_element()) in Kn
</code>
</pre>
now $hs$ is a set of morphism and $h_1 \in hs$. Can I get a (the) specific $h_1$ from $hs$? My attempt is $pi$ but 'pi(Kn_1.random_element()) in Kn' fails.
To construct $h_2$ I have more success.
<pre>
<code>
n = 4
i = 2
f = lambda x: x^(2^i) + x
Kn_1 = GF(2^(n+1),'x1')
Vn_1 = Kn_1.vector_space()
Sn_1 = Vn_1.subspace([Vn_1(f(u)) for u in Kn_1])
Kn = GF(2^n,'x')
Vn = Kn.vector_space()
h_a = Sn_1.basis_matrix().transpose()
</code>
</pre>
Now $h_a : Vn\rightarrow Sn_1$ where $Vn$ and $Sn_1$ is vector space representation of $GF(2^n)$ and $H_u$. To get from $GF(2^n)$ to $Vn$ and back I am good with But to create $h_2$ I have no luck. My attempts to use
<pre>
<code>
MatrixMorphism(Hom(Vn,Sn_1), Sn_1.basis_matrix().transpose())
</code>
</pre>
but get errors with regards to the dimensions of the matrix.
RegardsJohanTue, 23 Jul 2013 17:59:05 +0200https://ask.sagemath.org/question/10379/Constructing a morphism of free modules using the indexing sethttps://ask.sagemath.org/question/7748/constructing-a-morphism-of-free-modules-using-the-indexing-set/I have a set S indexed by triplets of numbers [i,j,k], and I want to construct an endomorphism T of the free module over S (call it F(S)) of the form:
T: e[i,j,k] ---> Sum over (u,v,w) : f(i,j,k, u,v,w) e[u,v,w]
where f(ijkuvw) is a certain function.
Is there a simple way to do this?
Thanks!Michael McBreenTue, 28 Dec 2010 09:46:12 +0100https://ask.sagemath.org/question/7748/