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.Tue, 30 Apr 2024 00:58:00 +0200How to generate map in sagehttps://ask.sagemath.org/question/77153/how-to-generate-map-in-sage/As you can see, I'm trying to repeatedly take the map x,y,z to xyx^-1, xzx^-1, (zy+1)x^-1 repeatedly. I'm getting a lot of errors though. Does anyone know how to fix my code? I think It might have something to do with the multiple variables calling the symbol 'x' but idk how else to not cause issues when I'm doing the three different parts of my map (like if I change X then the middle part has the wrong iteration of x).
That was my old question and someone gave me a response and I updated my code. I don't get why my new code doesn't work. If anyone knows how to fix it, or tell me another way to this please let me know!
A = algebras.Free(QQ, list('XYZ'), degrees=(1,1,1))
Ahat = A.completion()
A.inject_variables()
# Define elements x, y, and z
a = Ahat(X)
b = Ahat(Y)
c = Ahat(Z)
# Define the mapping function
def mymap(vx, vy, vz):
return vx * vy * ~vx, vx * vz * ~vx, (vz * vy + 1) * ~vx
# Apply the mapping function with the generators X, Y, and Z
print(mymap(a, b, c))babyturtleTue, 30 Apr 2024 00:58:00 +0200https://ask.sagemath.org/question/77153/Map_threaded and restriction on the precisionhttps://ask.sagemath.org/question/63765/map_threaded-and-restriction-on-the-precision/ When Applying map_threaded, is there a way to restrict the number of decimals displayed?CyrilleThu, 25 Aug 2022 10:13:49 +0200https://ask.sagemath.org/question/63765/Degree of a rational map and the corresponding map between function fieldshttps://ask.sagemath.org/question/63229/degree-of-a-rational-map-and-the-corresponding-map-between-function-fields/Let $X$ and $Y$ be two curves defined over $\mathbb{F}_q $ and $f:X \rightarrow Y$ be a separable rational map. Then there is field embedding
$$
f^\ast : \mathbb{F}_q (Y) \rightarrow \mathbb{F}_q (X)
$$ defined by
$f^\ast(\alpha) = \alpha \circ f$.
The degree of $f$ is then defined to be $[\mathbb{F}_q (X) : f^\ast(\mathbb{F}_q (Y))]$.
If I take two curves $X$ and $Y$ in sagemath over some $\mathbb{F}_q $ in sagemath, is there any way to automatically get the map $f^\ast$ and degree of $f$?DodulWed, 13 Jul 2022 08:56:42 +0200https://ask.sagemath.org/question/63229/map, lambda confusionhttps://ask.sagemath.org/question/53437/map-lambda-confusion/ What am I doing wrong here? The map creates an iterator OK, but when I try to list it I get a type error.
list(map(lambda x,y : x + y,[(1,2),(3,4),(5,6)]))
TypeError Traceback (most recent call last)
<ipython-input-11-031490d94268> in <module>()
----> 1 list(map(lambda x,y : x + y,[(Integer(1),Integer(2)),(Integer(3),Integer(4)),(Integer(5),Integer(6))]))
TypeError: <lambda>() missing 1 required positional argument: 'y'
cybervigilanteSun, 13 Sep 2020 04:17:44 +0200https://ask.sagemath.org/question/53437/Some code gives error in sagemath 9 but OK in 8.9https://ask.sagemath.org/question/50204/some-code-gives-error-in-sagemath-9-but-ok-in-89/After I upgraded to sagemath 9.0 some of the code that used to work now gives error. The code was used to obtain an estimate of size of expression.
>sage --version
SageMath version 9.0, Release Date: 2020-01-01
>which sage
/bin/sage
It looks like sagemath 9 now uses python 3.0 while 8.9 used python 2 (since I had to change all my print statements to use () to make them work.
Here is an example of function that now gives an error. This is in file, say `bug_sage.py`
#!/usr/bin/env sage
from sage.all import *
def tree(expr):
if expr.operator() is None:
return expr
else:
return [expr.operator()]+map(tree, expr.operands())
var('x')
tree(x*e**((x*log(x) + 1)/log(x)))
Now from command line at Linux, I type `sage ./bug_sage.py` and it gives the error
Traceback (most recent call last):
File "./bug_sage.py", line 12, in <module>
print (tree(x*e**((x*log(x) + 1)/log(x))))
File "./bug_sage.py", line 9, in tree
return [expr.operator()]+map(tree, expr.operands())
TypeError: can only concatenate list (not "map") to list
In 8.9, no error is generated.
It looks like this is due to change in Python itself? This function is meant to generate list of all operands in expression in order to estimate the size of the expression. It is later used as follows
len(flatten(tree(anti)))
Any idea how to fix it? Or do you suggest better way to obtain size of expression (called leaf count in other CAS systems).
NasserMon, 09 Mar 2020 21:52:26 +0100https://ask.sagemath.org/question/50204/Map a matrix to a block matrixhttps://ask.sagemath.org/question/41974/map-a-matrix-to-a-block-matrix/ Hello,
I have a function that maps an element $x$ into a $1\times n$ matrix, say for example $[x,x,x]$. I would like to map this function to a matrix and consider the resulting matrix as a "block matrix". E.g: change matrix([[1,2],[3,4]]) into matrix([[1,1,1,2,2,2],[3,3,3,4,4,4]]).
For now, I use a trick that basically converts back the matrix to a a list using something like:
block_matrix([[f(elt) for elt in row] for row in M.rows()])
but it looks quite dirty so I would like to know if there are some better way to proceed.
Thank you!tobiasBoraWed, 11 Apr 2018 00:15:48 +0200https://ask.sagemath.org/question/41974/Does "map" destroy its input?https://ask.sagemath.org/question/32613/does-map-destroy-its-input/I write the following in the SageMath cloud:
Bob="xyz"
sB = subsets(Bob)
print map(str, sB)
print map(str, sB)
and the output is:
['[]', "['x']", "['y']", "['x', 'y']", "['z']", "['x', 'z']", "['y', 'z']", "['x', 'y', 'z']"]
[]
I.e, after the first "map", the variable "sB" becomes empty!
Why does this happen?
Erel Segal-HaleviSun, 21 Feb 2016 16:09:15 +0100https://ask.sagemath.org/question/32613/Map a function to each element of a matrix?https://ask.sagemath.org/question/9459/map-a-function-to-each-element-of-a-matrix/Is there a direct way to apply a function to each entry of a matrix and return the resulting matrix?
A = matrix([[1,2],[3,4]])
B = matrix([[j^2 for j in i] for i in A])
Not terribly hard, but it's not ideal.daniel.e2718Tue, 23 Oct 2012 16:19:47 +0200https://ask.sagemath.org/question/9459/