Ask Your Question
1

python equivalent of T(x,y)=(x*y,x+y) ?

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

Shu gravatar image

updated 2015-01-14 02:44:04 -0500

FrédéricC gravatar image

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 flag offensive 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?

kcrisman gravatar imagekcrisman ( 2011-02-08 06:02:47 -0500 )edit

2 answers

Sort by » oldest newest most voted
3

answered 2011-02-08 06:03:21 -0500

kcrisman gravatar image

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)'
edit flag offensive delete link more

Comments

Thanks, yes, that's what I wanted.

Shu gravatar imageShu ( 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.

kcrisman gravatar imagekcrisman ( 2011-02-08 16:22:13 -0500 )edit
0

answered 2011-02-08 07:00:15 -0500

updated 2011-02-08 07:00:41 -0500

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]
edit flag offensive delete link 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.

kcrisman gravatar imagekcrisman ( 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 :)

Laurent Claessens gravatar imageLaurent Claessens ( 2011-02-08 19:53:42 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

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

Seen: 685 times

Last updated: Feb 08 '11