# python equivalent of T(x,y)=(x*y,x+y) ? In sage command line, I can write T(x,y) = (x*y,x+y) and can apply T.diff() to compute Jacobian.

But when I write the same in python, it says you can not assign to a function.

Does anyone know what I should write in python for T(x,y)=(x*y,x+y)?

edit retag close merge delete

I'm not sure if this belongs on ask.sagemath... after all, this is a Sage help site. Or am I missing something?

Sort by » oldest newest most voted

I don't know if this is what you are looking for, but the Sage preparser can tell you exactly what is done in Python behind the scenes:

sage: preparse('T(x,y) = (x*y,x+y)')
'__tmp__=var("x,y"); T = symbolic_expression((x*y,x+y)).function(x,y)'

more

Great! If it answers things exactly, you can click the check mark to indicate this in case someone else searches for a similar question and wants to know if the right answer was found.

This is not an answer, but I need more room for my text.

I think that what Shu wants is the following :

#! /usr/bin/sage -python
# -*- coding: utf8 -*-

from sage.all import *
var('x,y')
T = (x+y,x*y)  # (1)
print T.diff() # (2)


But the execution of that code finishes on :

AttributeError: 'tuple' object has no attribute 'diff'


Thus the question is : how to modify the line (1) in order the line (2) to produce that answer :

[(x, y) |--> y (x, y) |--> x]
[(x, y) |--> 1 (x, y) |--> 1]

more

Does T = symbolic_expression((x*y,x+y)).function(x,y) do what you need? It is true that things in parentheses are just 'tuples' in normal Python syntax.

Yes, that makes the work for what I was thinking about. I seems however that it was not the original poster's original need. Well at least I learn something :)