I tested by defining the function in the notebook and it worked. The reason why it works in the notebook is because Sage preparses the input that you provide it. By default it preparses x to make it a symbolic variable. I am just surprised that var() does not work if you make your function a library. Looking at the help shows that it is made to work only for interactive use.

To make it work from within the Sage library you will need to define the variable as a symbolic variable. The code to do this should be like this:

def symmetry(w):
        from sage.symbolic.ring import SR
        x,y = SR.var('x, y')

I suppose the above should work. I haven't tested it as yet.

On 05/01/2012 12:50 AM, yogesh gupta wrote:


---------- Forwarded message ----------
From: *yogesh gupta* <[email protected] <mailto:[email protected]>>
Date: Mon, Apr 30, 2012 at 10:19 PM
Subject: Re: [sage-support] Re: including sage library
To: [email protected] <mailto:[email protected]>


thanks for reply.
first method is worked perfectly. But in the second method it says
"global name var is not defined". and i want to implement the libraries
in the fashion so that i have to pass as minimum as possible arguments.
so plz help me.


On Mon, Apr 30, 2012 at 7:37 PM, P Purkayastha <[email protected]
<mailto:[email protected]>> wrote:



    On Monday, April 30, 2012 8:11:29 PM UTC+8, yogesh wrote:

        Hello Sir,

        def symmetry(w):
             if(w==w(x=-x,y=-y)):
                     print "symmetrical about origin"
             else:
                 print "not symmetrical about origin"

             if(w==w(x=-x)):
                     print "symmetrical about y axis"
             else:
                 print "not symmetrical about y axis"
             if(w==w(y=-y)):
                     print "symmetrical about x axis"
             else:
                 print "not symmetrical about x axis"
             if(w==w(x=y,y=x)):
                     print "symmetrical about y=x line"
             else:
                 print "not symmetrical about y=x line"


        var('x y a')
        w=x^2+y^2-a^2

        html("<h2>Find the symmetry of a curve </h2>")
        symmetry(w)

        this is our function symmetry. We had included this into our
        sage test copy but when we try to call it from sage command
        prompt then it gives error that "global variable x is not
        defined" how to resolve this problem ??????/

        plz reply asap. We need it very urgent.
        Thanks

    You can either
    1. pass the variables into your function as in
    ||
    defsymmetry(w,x,y):


    2. Declare x and y inside the function:
    ||
    defsymmetry(w):
         x,y =var('x y');

    --
    To post to this group, send email to [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:sage-support%[email protected]>
    For more options, visit this group at
    http://groups.google.com/group/sage-support
    URL: http://www.sagemath.org




--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to