[sage-support] Re: Dumb question about sums

2016-12-28 Thread Nils Bruin
On Wednesday, December 28, 2016 at 6:18:28 AM UTC-8, Emmanuel Charpentier 
wrote:
>
> I d not understand what is possible and not possible about sums with Sage 
> (and its minions).
>
> I am interested in the symbolic manipulation of a sum of (unspecified) 
> data series X. Since Sage does nott (yet) admits indiced symbolic variable, 
> it is reprsented by a function of an integer argument.
>
> Sage seems unable to show that 
> $\sum_{i=1}^{p+1}X_i-\sum_{i=1}^pX_i==X_{p+1}$ :
>
> sage: var("p,j", domain="integer")
> : assume(p,"integer",j,"integer",p>0)
> : X=function("X")(j)
>

You can avoid the warning downstairs by simply setting X=function("X") or 
(because of the side-effects of toplevel function, just function("X") . 

> : foo(p)=sum(X(j),j,1,p)
>

This has the nasty sideeffect of clobbering "p" (which in your case doesn't 
make any difference, I think). Calling

foo = sum(x(j),j,1,p).function(p)

has a cleaner result. 


: print foo
> : bool(foo(p+1)-foo(p)==X(p+1))
> : 
> (p, j)
> /usr/local/sage-7/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2881:
>  
> DeprecationWarning: Substitution using function-call syntax and unnamed 
> arguments is deprecated and will be removed from a future release of Sage; 
> you can use named arguments instead, like EXPR(x=..., y=...)
> See http://trac.sagemath.org/5930 for details.
>   exec(code_obj, self.user_global_ns, self.user_ns)
> p |--> sum(X(j), j, 1, p)
> False
>
> I understand the warning, and think it's irrelevant. But I do not 
> understand why the "obvious" expansion is not used. Similarly :
> sage: (foo(p+1)-foo(p)).maxima_methods().sumcontract()
> sum(X(j), j, 1, p + 1) - sum(X(j), j, 1, p)
>
> Am I missing something ?
>

It seems to me that this is an unnecessary limitation in the maxima 
routines. It clearly knows something about sum manipulations. Perhaps it's 
worth reporting to the Maxima tracker. I'm not so sure this will ever be 
very powerful, though, but the following example shows that some 
improvements should be within reach:

sage: T=foo(p+1)+foo(p)
sage: T.maxima_methods().sumcontract()
X(p + 1) + 2*sum(X(j), j, 1, p)

It does agree with the documentation of sumcontract, which deals with 
addition of sums. Apparently, that does not include differences of sums ...
 

> --
> Emmanuel Charpentier
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Plotting secant functions

2016-12-28 Thread Nils Bruin

On Wednesday, December 28, 2016 at 4:19:55 AM UTC-8, Fjordforsk A/S wrote:
>
> Hello, I am having trouble plotting this function:
>
> sage: *plot3d([(-t+x)^(0.5)*(sech[(t-x)^2]^2)] (x,-5,5), (t, -5, 5))*
>

In python syntax, *sech[(t-x)^2]^2)] *is list indexing, so it will try to 
convert the argument into an integer index in order to retrieve  that 
argument. In python (and hence sage, and most computer algebra systems, "[ 
]" and "( )" are not interchangeable.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Plotting long functions

2016-12-28 Thread Michael Orlitzky
On 12/28/2016 10:33 AM, Fjordforsk A/S wrote:
> This is how its supposed to go:
> 
> sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + 
> i*x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 
> 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(i*x)), (x, -2, 2), (t, 
> -2, 2)
> 
> 
> However, Sage thinks that 3*t^2 = Integer(3)*tInteger(2) 
> 
> That is , twice multiplied with 2, and not exponent to two.

The double-star means exponentiation in both python and in sage:

  sage: 2^8
  256
  sage: 2**8
  256

But beware, the carat "^" has a special meaning in sage. In python, it
does something else entirely:

  >>> 2^8
  10

In any case, your problem is elsewhere... I think you've got an extra
parenthesis at the end of your expression. Instead of "e^(i*x))", you
should have "e^(i*x)". Then you'll need another parenthesis at the end
of the whole thing.

After that, well, at least you get a different error =)

It crashes for me because it's trying to plot a point with a non-zero
imaginary part. It could be that the imaginary part is tiny -- in which
case you can throw it away -- or else you might have to rearrange your
expression, or break up the domain.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Plotting long functions

2016-12-28 Thread Fjordforsk A/S
This is how its supposed to go:

sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + 
i*x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 
4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(i*x)), (x, -2, 2), (t, 
-2, 2)


However, Sage thinks that 3*t^2 = Integer(3)*tInteger(2) 

That is , twice multiplied with 2, and not exponent to two.

How should I otherwise write this function?



---
TypeError Traceback (most recent call last)
 in ()
> 1 plot3d(((Integer(1) - (Integer(3)/Integer(8) - 
Integer(3)*t**Integer(2) - Integer(2)*t**Integer(4) - 
Integer(9)*x**Integer(2) - Integer(10)*x**Integer(4) - 
Integer(12)*t**Integer(2)*x**Integer(2)) + i*x*(Integer(15)/Integer(4) + 
Integer(6)*t**Integer(2) - Integer(4)*t**Integer(2) - 
Integer(2)*x**Integer(2) - Integer(4)*x**Integer(4) + 
Integer(8)*t**Integer(2)*x**Integer(2)))/(Integer(1)/Integer(8)*(Integer(3)/Integer(4)
 
+ Integer(9)*t**Integer(2) + Integer(4)*t**Integer(2)+ 
Integer(16)/Integer(3)*t**Integer(6) + Integer(33)*x**Integer(2) + 
Integer(36)*x**Integer(24) + 
Integer(16)/Integer(3)*x**Integer(6*e**(i*x)), (x, -Integer(2), 
Integer(2)), (t, -Integer(2), Integer(2))

TypeError: plot3d() takes at least 3 arguments (1 given)
sage: 




onsdag 28. desember 2016 13.19.55 UTC+1 skrev Fjordforsk A/S følgende:
>
> Hello, I am not sure on the reply sage gives me on plotting a long 
> function:
>
> sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + 
> x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 
> 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(x)), (x, -2, 2), (t, 
> -2, 2) 
>
>
> TypeError: plot3d() takes at least 3 arguments (1 given)
>
> I have defined x and t as variables, should I define e as well?
>
> Thanks!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Dumb question about sums

2016-12-28 Thread Emmanuel Charpentier
I d not understand what is possible and not possible about sums with Sage 
(and its minions).

I am interested in the symbolic manipulation of a sum of (unspecified) data 
series X. Since Sage does nott (yet) admits indiced symbolic variable, it 
is reprsented by a function of an integer argument.

Sage seems unable to show that 
$\sum_{i=1}^{p+1}X_i-\sum_{i=1}^pX_i==X_{p+1}$ :

sage: var("p,j", domain="integer")
: assume(p,"integer",j,"integer",p>0)
: X=function("X")(j)
: foo(p)=sum(X(j),j,1,p)
: print foo
: bool(foo(p+1)-foo(p)==X(p+1))
: 
(p, j)
/usr/local/sage-7/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2881:
 
DeprecationWarning: Substitution using function-call syntax and unnamed 
arguments is deprecated and will be removed from a future release of Sage; 
you can use named arguments instead, like EXPR(x=..., y=...)
See http://trac.sagemath.org/5930 for details.
  exec(code_obj, self.user_global_ns, self.user_ns)
p |--> sum(X(j), j, 1, p)
False

I understand the warning, and think it's irrelevant. But I do not 
understand why the "obvious" expansion is not used. Similarly :
sage: (foo(p+1)-foo(p)).maxima_methods().sumcontract()
sum(X(j), j, 1, p + 1) - sum(X(j), j, 1, p)

Am I missing something ?

--
Emmanuel Charpentier

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Plotting long functions

2016-12-28 Thread Michael Orlitzky
On 12/28/2016 07:12 AM, Fjordforsk A/S wrote:
> Hello, I am not sure on the reply sage gives me on plotting a long function:
> 
> sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + 
> x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 
> 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(x)), (x, -2, 2), (t, 
> -2, 2) 
> 
> 
> TypeError: plot3d() takes at least 3 arguments (1 given)
> 
> I have defined x and t as variables, should I define e as well?
> 

I think you just made a typo in there somewhere. The function part of
your example doesn't parse as a function; I get a syntax error if I do f
= .

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Plotting secant functions

2016-12-28 Thread Fjordforsk A/S
Hello, I am having trouble plotting this function:

sage: *plot3d([(-t+x)^(0.5)*(sech[(t-x)^2]^2)] (x,-5,5), (t, -5, 5))*
---
TypeError Traceback (most recent call last)
 in ()
> 1 
plot3d([(-t+x)**(RealNumber('0.5'))*(sech[(t-x)**Integer(2)]**Integer(2))] 
(x,-Integer(5),Integer(5)), (t, -Integer(5), Integer(5)))

/home/sem/SageMath/sage-7.4/src/sage/symbolic/expression.pyx in 
sage.symbolic.expression.Expression.__index__ 
(/home/sem/SageMath/sage-7.4/src/build/cythonized/sage/symbolic/expression.cpp:29931)()
   5303 [0, 1, 2, 3, 4]
   5304 """
-> 5305 return int(self._integer_())
   5306 
   5307 def iterator(self):

/home/sem/SageMath/sage-7.4/src/sage/symbolic/expression.pyx in 
sage.symbolic.expression.Expression._integer_ 
(/home/sem/SageMath/sage-7.4/src/build/cythonized/sage/symbolic/expression.cpp:8088)()
   1075 n = self.pyobject()
   1076 except TypeError:
-> 1077 raise TypeError("unable to convert %r to an integer" % 
self)
   1078 if isinstance(n, sage.rings.integer.Integer):
   1079 return n

TypeError: unable to convert (t - x)^2 to an integer


I am not sure what this is caused by, Both x and t are defined as 
variables, but it asks for an integer .

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Plotting long functions

2016-12-28 Thread Fjordforsk A/S
Hello, I am not sure on the reply sage gives me on plotting a long function:

sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + 
x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 
4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(x)), (x, -2, 2), (t, 
-2, 2) 


TypeError: plot3d() takes at least 3 arguments (1 given)

I have defined x and t as variables, should I define e as well?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.