[sage-support] derivative bug in Sage 4.0 symbolics?

2009-06-07 Thread Alex Raichev

Hi all:

Upon upgrading to Sage 4.0, i can no longer make a dictionary with
derivatives as keys (see below).  Can someone please fix this?

Alex

--
| Sage Version 4.0, Release Date: 2009-05-29 |
| Type notebook() for the GUI, and license() for information.|
--
sage: X= var('x,y')
sage: f= function('f',*X); f
f(x, y)
sage: for x in X:
: diff(f,x)
:
D[0](f)(x, y)
D[1](f)(x, y)
sage: d= {}
sage: for x in X:
: d[diff(f,x)] = 1
:
---
NotImplementedError   Traceback (most recent call
last)

/Users/raichev/ in ()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression.__nonzero__ (sage/
symbolic/expression.cpp:7814)()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression.test_relation
(sage/symbolic/expression.cpp:9187)()

/Applications/sage/local/lib/python2.5/site-packages/sage/rings/
complex_interval_field.pyc in __call__(self, x, im)
286
287 try:
--> 288 return x._complex_mpfi_( self )
289 except AttributeError:
290 pass

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression.so in sage.symbolic.expression.Expression._complex_mpfi_
(sage/symbolic/expression.cpp:5484)()

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in __call__(self, ex)
212 div = self.get_fake_div(ex)
213 return self.arithmetic(div, div.operator())
--> 214 return self.arithmetic(ex, operator)
215 elif operator in relation_operators:
216 return self.relation(ex, operator)

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in arithmetic(self, ex, operator)
   1424 return base ** expt
   1425 else:
-> 1426 return reduce(operator, map(self, operands))
   1427
   1428 def composition(self, ex, operator):

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in __call__(self, ex)
216 return self.relation(ex, operator)
217 elif isinstance(operator, FDerivativeOperator):
--> 218 return self.derivative(ex, operator)
219 else:
220 return self.composition(ex, operator)

/Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
expression_conversions.pyc in derivative(self, ex, operator)
344 NotImplementedError: derivative
345 """
--> 346 raise NotImplementedError, "derivative"
347
348 def arithmetic(self, ex, operator):

NotImplementedError: derivative




--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: derivative bug in Sage 4.0 symbolics?

2009-06-07 Thread Burcin Erocal

Hi Alex,

On Sun, 7 Jun 2009 11:31:26 -0700 (PDT)
Alex Raichev  wrote:

> 
> Hi all:
> 
> Upon upgrading to Sage 4.0, i can no longer make a dictionary with
> derivatives as keys (see below).  Can someone please fix this?

> --
> | Sage Version 4.0, Release Date: 2009-05-29 |
> | Type notebook() for the GUI, and license() for information.|
> --
> sage: X= var('x,y')
> sage: f= function('f',*X); f
> f(x, y)
> sage: for x in X:
> : diff(f,x)
> :
> D[0](f)(x, y)
> D[1](f)(x, y)
> sage: d= {}
> sage: for x in X:
> : d[diff(f,x)] = 1
> :


> /Applications/sage/local/lib/python2.5/site-packages/sage/rings/
> complex_interval_field.pyc in __call__(self, x, im)
> 286
> 287 try:
> --> 288 return x._complex_mpfi_( self )
> 289 except AttributeError:
> 290 pass
> 
> /Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
> expression.so in sage.symbolic.expression.Expression._complex_mpfi_
> (sage/symbolic/expression.cpp:5484)()

> /Applications/sage/local/lib/python2.5/site-packages/sage/symbolic/
> expression_conversions.pyc in derivative(self, ex, operator)
> 344 NotImplementedError: derivative
> 345 """
> --> 346 raise NotImplementedError, "derivative"
> 347
> 348 def arithmetic(self, ex, operator):
> 
> NotImplementedError: derivative
> 

I opened a ticket for this:

http://trac.sagemath.org/sage_trac/ticket/6243

As I wrote on the ticket, I believe the correct fix is to change pynac
to handle more general numerical approximations. I will try to get this
done until the next release.

There might be an easier fix by implementing the derivative method in
sage.symbolic.expression_conversions.Converter. Maybe Mike can comment
on that.


Thanks.

Burcin

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] substitute values into a muttivariate polynomial

2009-06-07 Thread amps

I want to substitute n values into polynomial with n variables.

I guess the syntax to do this is (if g is my polynomial with
indeterminates z[1], ..., z[n]).

f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})

but how do I actually do this?  n is not set, so I just can't type
this out.
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread Justin C. Walker


On Jun 7, 2009, at 13:03 , amps wrote:

>
> I want to substitute n values into polynomial with n variables.
>
> I guess the syntax to do this is (if g is my polynomial with
> indeterminates z[1], ..., z[n]).
>
> f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})
>
> but how do I actually do this?  n is not set, so I just can't type
> this out.

That's intriguing syntax, but I don't think it will work.

Assuming that, at the call site, you know all your values, you can  
cobble up a tuple or list, something like the following:

   L = [f(i+1) for i in range(n)]
   print g(L)

You can do this to determine 'n', assuming you don't know it at the  
call site:

   n = len(g.variables())

HTH

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Director
Institute for the Enhancement of the Director's Income

"Weaseling out of things is what separates us from the animals.
  Well, except the weasel."
   - Homer J Simpson




--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread amps

sorry, i meant

g.subs({z[1]:value1...})

I am not sure why you call this intriguing syntax, but it is what
works.

Example:
g=x+y
g.subs({x:2,y:4})
6

My problem is that I don't know how to do this if the number of
variables is not predetermined.
I tried to make a list with
a=list()
for i in range(n):
a.append(z[i]:value[i])
but it does not like this kind of list (gives an error).

you can think of it this way.  Suppose n is not predetermined.
R=PolynomialRing(QQ,n,'z')
z=R.gens()
g=sum(z[i] for i in range(n))

now how would I substitute into g the values z[i]=i?
On 7 June, 21:48, "Justin C. Walker"  wrote:
> On Jun 7, 2009, at 13:03 , amps wrote:
>
>
>
> > I want to substitute n values into polynomial with n variables.
>
> > I guess the syntax to do this is (if g is my polynomial with
> > indeterminates z[1], ..., z[n]).
>
> > f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})
>
> > but how do I actually do this?  n is not set, so I just can't type
> > this out.
>
> That's intriguing syntax, but I don't think it will work.
>
> Assuming that, at the call site, you know all your values, you can  
> cobble up a tuple or list, something like the following:
>
>    L = [f(i+1) for i in range(n)]
>    print g(L)
>
> You can do this to determine 'n', assuming you don't know it at the  
> call site:
>
>    n = len(g.variables())
>
> HTH
>
> Justin
>
> --
> Justin C. Walker, Curmudgeon-At-Large
> Director
> Institute for the Enhancement of the Director's Income
> 
> "Weaseling out of things is what separates us from the animals.
>   Well, except the weasel."
>        - Homer J Simpson
> 
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread amps

When I say that n is not predetermined, I mean that I want my script
to work for any n.  So before I define the polynomial ring, n is
determined, but I want this to work for all n.  So my question is how
do I do the following.

n=6
R=PolynomialRing(QQ,n,'z')
z=R.gens()
g=sum(z[i] for i in range(n))

now how would I substitute into g the values z[i]=i?  I want to keep n
as a variable.

On 7 June, 23:23, amps  wrote:
> sorry, i meant
>
> g.subs({z[1]:value1...})
>
> I am not sure why you call this intriguing syntax, but it is what
> works.
>
> Example:
> g=x+y
> g.subs({x:2,y:4})
> 6
>
> My problem is that I don't know how to do this if the number of
> variables is not predetermined.
> I tried to make a list with
> a=list()
> for i in range(n):
>         a.append(z[i]:value[i])
> but it does not like this kind of list (gives an error).
>
> you can think of it this way.  Suppose n is not predetermined.
> R=PolynomialRing(QQ,n,'z')
> z=R.gens()
> g=sum(z[i] for i in range(n))
>
> now how would I substitute into g the values z[i]=i?
> On 7 June, 21:48, "Justin C. Walker"  wrote:
>
> > On Jun 7, 2009, at 13:03 , amps wrote:
>
> > > I want to substitute n values into polynomial with n variables.
>
> > > I guess the syntax to do this is (if g is my polynomial with
> > > indeterminates z[1], ..., z[n]).
>
> > > f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})
>
> > > but how do I actually do this?  n is not set, so I just can't type
> > > this out.
>
> > That's intriguing syntax, but I don't think it will work.
>
> > Assuming that, at the call site, you know all your values, you can  
> > cobble up a tuple or list, something like the following:
>
> >    L = [f(i+1) for i in range(n)]
> >    print g(L)
>
> > You can do this to determine 'n', assuming you don't know it at the  
> > call site:
>
> >    n = len(g.variables())
>
> > HTH
>
> > Justin
>
> > --
> > Justin C. Walker, Curmudgeon-At-Large
> > Director
> > Institute for the Enhancement of the Director's Income
> > 
> > "Weaseling out of things is what separates us from the animals.
> >   Well, except the weasel."
> >        - Homer J Simpson
> > 
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread Justin C. Walker


On Jun 7, 2009, at 15:23 , amps wrote:

>
> sorry, i meant
>
> g.subs({z[1]:value1...})
>
> I am not sure why you call this intriguing syntax, but it is what
> works.

My turn to say sorry.  I just mentally wiped out the '.subs' part.

> My problem is that I don't know how to do this if the number of
> variables is not predetermined.
> I tried to make a list with
> a=list()
> for i in range(n):
>a.append(z[i]:value[i])
> but it does not like this kind of list (gives an error).

Yup; the {x:i...} syntax is creating a dictionary, which doesn't work  
where you use it here (it does work in procedure calls, since that's  
how variable binding is done).

> you can think of it this way.  Suppose n is not predetermined.
> R=PolynomialRing(QQ,n,'z')
> z=R.gens()
> g=sum(z[i] for i in range(n))
>
> now how would I substitute into g the values z[i]=i?

More or less like I indicated below:
L = [i for i in range(n)]
v = g(L)

There is some nuance to what you are doing above.  In the first place,  
z is a 'tuple', and as such, immutable, so the assignment 'z[i]=i'  
won't work.

In the second, even if it did, you are assigning values to the  
variables that define the ring R, not to the "variables" defining the  
polynomial g.

You may already know this, but I'm pointing it out for clarity.

Doing something like I suggest will get you what you want, I think.   
No need to use "g.subs()".

Think of it this way: R is defined in (say) the outer block (drawing  
an analogy with block structured languages), while the computation  
that g() implements is an inner block, so you want to assign values to  
those variables in the calling sequence, not in the block where R is  
defined.

HTH

Justin

>
> On 7 June, 21:48, "Justin C. Walker"  wrote:
>> On Jun 7, 2009, at 13:03 , amps wrote:
>>
>>
>>
>>> I want to substitute n values into polynomial with n variables.
>>
>>> I guess the syntax to do this is (if g is my polynomial with
>>> indeterminates z[1], ..., z[n]).
>>
>>> f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})
>>
>>> but how do I actually do this?  n is not set, so I just can't type
>>> this out.
>>
>> That's intriguing syntax, but I don't think it will work.
>>
>> Assuming that, at the call site, you know all your values, you can
>> cobble up a tuple or list, something like the following:
>>
>>L = [f(i+1) for i in range(n)]
>>print g(L)
>>
>> You can do this to determine 'n', assuming you don't know it at the
>> call site:
>>
>>n = len(g.variables())
>>
>> HTH
>>
>> Justin
>>
>> --
>> Justin C. Walker, Curmudgeon-At-Large
>> Director
>> Institute for the Enhancement of the Director's Income
>> 
>> "Weaseling out of things is what separates us from the animals.
>>   Well, except the weasel."
>>- Homer J Simpson
>> 
> >

--
Justin C. Walker
Curmudgeon-at-large
Director
Institute for the Absorption of Federal Funds

186,000 Miles per Second
Not just a good idea:
   it's the law!



--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread Mike Hansen

This works:

sage: n=6
sage: R=PolynomialRing(QQ,n,'z')
sage: z=R.gens()
sage: g=sum(z[i] for i in range(n))
sage: g.subs(dict((z[i], i) for i in range(n)))
15

--Mike

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: substitute values into a muttivariate polynomial

2009-06-07 Thread Justin C. Walker


On Jun 7, 2009, at 15:53 , amps wrote:

>
> When I say that n is not predetermined, I mean that I want my script
> to work for any n.  So before I define the polynomial ring, n is
> determined, but I want this to work for all n.  So my question is how
> do I do the following.
>
> n=6
> R=PolynomialRing(QQ,n,'z')
> z=R.gens()
> g=sum(z[i] for i in range(n))
>
> now how would I substitute into g the values z[i]=i?  I want to keep n
> as a variable.

I understand what you want to do, I think.  If my reply to your last  
message doesn't answer your question, let us know.

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
---
I'm beginning to like the cut of his jibberish.
---




--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Issues with gcd

2009-06-07 Thread salte...@gmail.com

I am running into problems using the gcd function in sage. (version
3.4.2)

Specifically, I am iterating over a set of integers [a,b,c,r,s,t]
which I want to be coprime. I check this using gcd([a,b,c,r,s,t]). The
problem is that it returns 1 for tuples that should not have gcd = 1.
For example, for [a,b,c,r,s,t]=[2,2,2,0,0,0], it passes gcd
([a,b,c,r,s,t]) == 1. When I check this directly (by evaluating gcd
([2,2,2,0,0,0]) it evaluates correctly. This is driving me insane -
any help would be greatly appreciated. Here is the pertinent code: (If
you want to run into the [2,2,2,0,0,0] case, try d = 32 and N = 8)

def MakeTernaryQF(d,N):

## Make the list##
#r,s,t <= 0
QFlist = []
for a in range(1, 1+ceil((d/2)^(1/3))):
for b in range(a, floor(sqrt(d / (2*a)))+1):
for r in range(-b, 1):
for s in range(-a,1):
for t in range(-a,1):
if (d - r*s*t +a*r*r + 
b*s*s)%(4*a*b - t*t) == 0:
c = (d - r*s*t +a*r*r + 
b*s*s)/(4*a*b - t*t)
if gcd([a,b,c,r,s,t]) 
== 1 and a+b+c+r+s+t >= 0:
#print 'This 
dumb thing thinks gcd('+str(a)+','+str(b)+','+str
(c)+','+str(r)+','+str(s)+','+str(t)+') = '+str(gcd([a,b,c,r,s,t]))

QFlist.append([a,b,c,r,s,t])

#r,s,t > 0
for a in range(1, 1+ceil((d/2)^(1/3))):
for b in range(a, floor(sqrt(d / (2*a)))+1):
for r in range(1, b+1):
for s in range(1,a+1):
for t in range(1,a+1):
if (d - r*s*t +a*r*r + 
b*s*s)%(4*a*b - t*t) == 0:
c = (d - r*s*t +a*r*r + 
b*s*s)/(4*a*b - t*t)
if gcd([a,b,c,r,s,t]) 
== 1 and a+b+c+r+s+t >= 0:
#print 
'This dumb thing thinks gcd('+str(a)+','+str(b)+','+str
(c)+','+str(r)+','+str(s)+','+str(t)+') = '+str(gcd([a,b,c,r,s,t]))

QFlist.append([a,b,c,r,s,t])

return QFlist

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] element-wise multiplication of matrices

2009-06-07 Thread paramaniac

Dear Sage community,

Is there a possibility/workaround in Sage to compute the element-wise
multiplication of two matrices? In Matlab there's the .* operator, but
Matlab is useless in my case since I need a symbolic result.

Thanks in advance for every help
Regards,
Lukas

EXAMPLE:

sigma, tau, beta = var('sigma tau beta')
A = matrix([[-1/tau, sigma/tau],[sigma/tau, -1/tau]])
B = matrix([[beta/tau, 0],[0, beta/tau]])
C = matrix([[1,0],[0,1]])
D = matrix([[0,0],[0,0]])
I = identity_matrix(2)
s, t = var('s t')
P = C*(s*I-A)^(-1)*B+D
P = P.simplify_rational()

RGA = P .* P.inverse().transpose()


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: element-wise multiplication of matrices

2009-06-07 Thread Dan Drake
On Sun, 07 Jun 2009 at 11:12AM -0700, paramaniac wrote:
> Is there a possibility/workaround in Sage to compute the element-wise
> multiplication of two matrices? In Matlab there's the .* operator, but
> Matlab is useless in my case since I need a symbolic result.

There's no operator that I know of for that, but you can convert your
matrices to lists, multiply, and convert back:

sage: x,y,z,w = var('x y z w')
sage: a = matrix(SR, 2, 2, [x, y, z, w])
sage: b = matrix(SR, 2, 2, [1+x, 1+y, 1+z, 1+w])
sage: a.list()
[x, y, z, w]
sage: b.list()
[x + 1, y + 1, z + 1, w + 1]

Now make a list of corresponding pairs of entries with zip() and
multiply:

sage: [ x*y for x, y in zip(a.list(), b.list()) ]
[(x + 1)*x, (y + 1)*y, (z + 1)*z, (w + 1)*w]

...and make a matrix out of the new list:

sage: matrix(2, 2, [ x*y for x, y in zip(a.list(), b.list()) ])

[(x + 1)*x (y + 1)*y]
[(z + 1)*z (w + 1)*w]

You can easily put that sequence of steps into a function. You may need
to fiddle a bit with the rows and columns bits, and maybe add a ring
argument if you need to specify what ring the matrix should be over.

def componentwise_multiply(a, b, rows, cols):
return matrix(rows, cols, [x*y for x, y in zip(a.list(), b.list())])


Dan

-- 
---  Dan Drake 
-  KAIST Department of Mathematical Sciences
---  http://mathsci.kaist.ac.kr/~drake


signature.asc
Description: Digital signature


[sage-support] Re: Sage 4.0 can be installed on ubuntu 8.04?

2009-06-07 Thread Bruce Cohen

I installed this binary:
sage-4.0-linux-Debian_GNU_Linux_4.0_etch-sse2-i686-Linux
on my ubuntu 8.04 machine.  It appears to work.

-Bruce

On Jun 6, 5:55 am, Hobus  wrote:
> Sage 4.0 can be installed on ubuntu 8.04?
>
> I had this error:
> /home/jluxtux/sage-4.0-linux-Ubuntu_9.04-sse2-i686-Linux/local/bin/
> sage-sage: line 198:  7984 Instrucción ilegal     sage-ipython "$@" -i
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---