ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 Feb 2011 19:53:42 -0600python equivalent of T(x,y)=(x*y,x+y) ?http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/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)?
Tue, 08 Feb 2011 05:49:59 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/Comment by kcrisman for <p>In sage command line, I can write T(x,y) = (x*y,x+y) and can apply T.diff() to compute Jacobian.</p>
<p>But when I write the same in python, it says you can not assign to a function.</p>
<p>Does anyone know what I should write in python for T(x,y)=(x*y,x+y)?</p>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22177#post-id-22177I'm not sure if this belongs on ask.sagemath... after all, this is a Sage help site. Or am I missing something?Tue, 08 Feb 2011 06:02:47 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22177#post-id-22177Answer by kcrisman for <p>In sage command line, I can write T(x,y) = (x*y,x+y) and can apply T.diff() to compute Jacobian.</p>
<p>But when I write the same in python, it says you can not assign to a function.</p>
<p>Does anyone know what I should write in python for T(x,y)=(x*y,x+y)?</p>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?answer=12073#post-id-12073I 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)'
Tue, 08 Feb 2011 06:03:21 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?answer=12073#post-id-12073Comment by kcrisman for <p>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:</p>
<pre><code>sage: preparse('T(x,y) = (x*y,x+y)')
'__tmp__=var("x,y"); T = symbolic_expression((x*y,x+y)).function(x,y)'
</code></pre>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22170#post-id-22170Great! 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.Tue, 08 Feb 2011 16:22:13 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22170#post-id-22170Comment by Shu for <p>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:</p>
<pre><code>sage: preparse('T(x,y) = (x*y,x+y)')
'__tmp__=var("x,y"); T = symbolic_expression((x*y,x+y)).function(x,y)'
</code></pre>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22176#post-id-22176Thanks, yes, that's what I wanted.Tue, 08 Feb 2011 06:47:23 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22176#post-id-22176Answer by Laurent Claessens for <p>In sage command line, I can write T(x,y) = (x*y,x+y) and can apply T.diff() to compute Jacobian.</p>
<p>But when I write the same in python, it says you can not assign to a function.</p>
<p>Does anyone know what I should write in python for T(x,y)=(x*y,x+y)?</p>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?answer=12074#post-id-12074This 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]
Tue, 08 Feb 2011 07:00:15 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?answer=12074#post-id-12074Comment by kcrisman for <p>This is not an answer, but I need more room for my text.</p>
<p>I think that what Shu wants is the following :</p>
<pre><code>#! /usr/bin/sage -python
# -*- coding: utf8 -*-
from sage.all import *
var('x,y')
T = (x+y,x*y) # (1)
print T.diff() # (2)
</code></pre>
<p>But the execution of that code finishes on :</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'diff'
</code></pre>
<p>Thus the question is : how to modify the line (1) in order the line (2) to produce that answer :</p>
<pre><code>[(x, y) |--> y (x, y) |--> x]
[(x, y) |--> 1 (x, y) |--> 1]
</code></pre>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22168#post-id-22168Does `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.Tue, 08 Feb 2011 16:25:32 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22168#post-id-22168Comment by Laurent Claessens for <p>This is not an answer, but I need more room for my text.</p>
<p>I think that what Shu wants is the following :</p>
<pre><code>#! /usr/bin/sage -python
# -*- coding: utf8 -*-
from sage.all import *
var('x,y')
T = (x+y,x*y) # (1)
print T.diff() # (2)
</code></pre>
<p>But the execution of that code finishes on :</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'diff'
</code></pre>
<p>Thus the question is : how to modify the line (1) in order the line (2) to produce that answer :</p>
<pre><code>[(x, y) |--> y (x, y) |--> x]
[(x, y) |--> 1 (x, y) |--> 1]
</code></pre>
http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22165#post-id-22165Yes, 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 :)Tue, 08 Feb 2011 19:53:42 -0600http://ask.sagemath.org/question/7930/python-equivalent-of-txyxyxy/?comment=22165#post-id-22165