Ask Your Question

# 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

## Comments

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

( 2011-02-08 06:02:47 -0500 )edit

## 2 answers

Sort by » oldest newest most voted

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

## Comments

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.

( 2011-02-08 16:25:32 -0500 )edit

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 :)

( 2011-02-08 19:53:42 -0500 )edit

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

## Comments

Thanks, yes, that's what I wanted.

( 2011-02-08 06:47:23 -0500 )edit

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.

( 2011-02-08 16:22:13 -0500 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2011-02-08 05:49:59 -0500

Seen: 745 times

Last updated: Feb 08 '11