Carl Love

Carl Love

27731 Reputation

25 Badges

12 years, 163 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

For nonnegative integer k,

sin(k*x)*cos(x)^k = Sum(binomial(k,j)*sin(2*j*x), j= 1..k)/2^k  (* Prop 1 *)

Since Int(sin(2*j*x)/x, x) = Si(2*j*x)Si(0) = 0Si(infinity) = Pi/2, and Sum(binomial(k,j), j= 1..k) = 2^k - 1,

Int(sin(k*x)*cos(x)^k/x, x= 0..infinity) = (Pi/2)*(2^k - 1)/2^k = Pi/2*(1 - 2^(-k))

Looking for the pattern in the following iteration makes the first proposition obvious to me, although that is not proof:

for k to 9 do combine(2^k*sin(k*x)*cos(x)^k) od

The closed interval containing the single point 1 can be entered as simply 1, or as RealRange(1,1), which automatically reduces to 1. Note that all intervals entered in 2D Input are re-expressed in RealRange form. You can see this with lprint, as in

lprint(correct_form);

It is that automatic conversion of RealRange(1,1) to 1 that causes the problem. When you construct the correct_form, use y=1 instead of y::1, because convert(..., relation) will not correctly convert y::1 (although it is valid Maple syntax). To solve, use

solve(Or(convert(correct_form, relation)[]));
or, if you insist on using the cluttery op,
solve(Or(op(convert(correct_form, relation))));
instead of your
solve(convert~(Or(op(correct_form)), relation));
(and note that the ~ does nothing in your command).

Here is an elementary proof:

Author: Carl Love <carl.j.love@gmail.com> 2025-Mar-6

restart:

We want to sum this series:

S:= Sum(arctan(2/n^2), n= 1..infinity);

Sum(arctan(2/n^2), n = 1 .. infinity)

I devised an elementary proof of this. Since I only spent a half hour on it, I wouldn't be surprised if it could be done more simply.

First, Here's a trig identity that's very easy to prove, but I'll state it without proof because Maple already knows it:

arctan(a) + arctan(b):
ATid:= % = combine(%) assuming abs(a*b) < 1;

arctan(a)+arctan(b) = arctan((a+b)/(-a*b+1))

This proposition, proved by induction, will allow us to sum separately the odd and even terms of the series. It's valid for n > 1.

P:= sum(arctan(2/(n+2*k)^2), k= 0..K) = arctan((K+1)/(K*(n-1) + n^2/2));  #where n > 1

sum(arctan(2/(n+2*k)^2), k = 0 .. K) = arctan((K+1)/(K*(n-1)+(1/2)*n^2))

The base case, K = 0: This is obviously true:

eval(P, K= 0);

arctan(2/n^2) = arctan(2/n^2)

Assuming that P is true for the sum of the first K-1 terms, we break off and add separately the Kth term:

IH:= eval(rhs(P), K= K-1) + eval(op(1, lhs(P)), k= K);

arctan(K/((K-1)*(n-1)+(1/2)*n^2))+arctan(2/(n+2*K)^2)

Apply the trig identity:

simplify(eval(rhs(ATid), [a= op(op(1,IH)), b= op(op(2,IH))]));

arctan((2*K+2)/((2*n-2)*K+n^2))

simplify(op(1,%) - op(rhs(P)));

0

Q.E.D.

 

Taking the limit of the partial sums,

SS:= eval(lhs(P), K= infinity) = limit(rhs(P), K= infinity);

sum(arctan(2/(n+2*k)^2), k = 0 .. infinity) = arctan(1/(n-1))

From the original sum, we consider separately n=1, the remaining terms for even n, and the remaining terms for odd n. We get

S = eval(op(1,S), n= 1) + eval(rhs(SS), n= 2) + eval(rhs(SS), n= 3);

Sum(arctan(2/n^2), n = 1 .. infinity) = arctan(2)+(1/4)*Pi+arctan(1/2)

simplify(%);

Sum(arctan(2/n^2), n = 1 .. infinity) = (3/4)*Pi

 

Download ArctanSum.mw

A sequence can be accumulated (as a sum or via any other function) very efficiently at the same time as it's created by using the scan option to seq:

y:= [seq['scan'= rand(1..6)]](1..10);
              y := [1, 5, 2, 5, 6, 2, 3, 4, 4, 6]

(L,H):= selectremove(`<=`, {y[]}, 3); 
                  L, H := {1, 2, 3}, {4, 5, 6}

y:= subs((L=~ -1) union (H=~ 1), y);
            y := [-1, 1, -1, 1, 1, -1, -1, 1, 1, 1]

y:= [seq['scan'= `+`]](y);
             y := [-1, 0, -1, 0, 1, 0, -1, 0, 1, 2]

#The plot can be done by
dataplot(y);

#The 1st 4 commands can be done by this single command:
y:= [seq['scan'= `+`]](seq['scan'= 2*rand(0..1) - 1](1..10));

The Maple expressions cos(x)=sqrt(1-sin(x)^2) or cos(x)=-sqrt(1-sin(x)^2) and x=0 or x<>0 automatically evaluate to false and true, respectively, before they are passed to is. The solution is to replace A or B with its inert form Or(A, B). See help page ?boolean.

To completely achieve the effect that you were hoping for from U:= U(x), you need to use alias as well as PDEtools:-declare:

restart;
alias(U=U(x)); PDEtools:-declare(U);

This will abbreviate U(x) to U for both input and output. Using declare without alias will not let you abbreviate your input.

If is an unassigned symbol, then A[B] is equivalent to A:-B. On the other hand, if is an export of A, and is also an assigned symbol outside of A, then A:-B must be used to disambiguate the Bs.

Like this:

foldl(gcd, lst1[]);

You could also use foldr. Since gcd is associative, it doesn't make any difference.

If is any set, and f is any binary operation on S, then the fold commands can be used to extend f to an arbitrary number of arguments.

After the loop, do

save f, "filename";

I don't know any way to append to a file with the save command.

Here is an implementation in Maple of an infix operator akin to the that you showed from bash. I added an additional feature that the version number is automatically incremented.

restart
:
(* An infix operator for filename formatting with automatically incrementing
   version number

Parameters:
   f::anything   the "stem" of the filename
   V::anything   the version
      If V is a variable assigned an integer, then it's incremented and used;
      if V is an unassigned variable, then it's assigned 1 and used;
      if V is anything else, it's appended to the filename as is.
   w::posint     the version field width
      The field width to use for nonnegative integer version numbers. They get
      padded with leading zeros to width w.
   ext::string   the file name "extension" 
*)

`&$`:= proc(f, V::uneval, w::posint:= 2, ext::string:= "txt")
local v:= eval(V), N:= V::name, n:= v::name, i:= v::integer, p:= `if`(N,1,0);
    String(
        f,
        0 $ w - 
            if i and (N implies v > -2) then length(v+p) + `if`(v = -p, 1, 0)
            else `if`(n,1,0)
            fi,
        `if`(N, `if`(n, (V:= 1), `if`(i, ++V, v)), v), 
        `if`(ext="", "", "."||ext)
    )
end proc
:
#Usage examples:
V:= 'V': #Erase prior value, if any
filename &$ V;
                        "filename01.txt"
filename &$ V;
                        "filename02.txt"
V;
                               2

#To change the width or extension from their defaults, use the operator in prefix form:
&$ (myfile, 7, 3, "map");
                        "myfile007.map"

 

What you want is a basic string operation, not a file operation. That might be why you had trouble finding it.

MakeName:= proc(f::string, ver::posint, wid::posint:= 2, ext::string:= "txt")
    sprintf("%s%0*d.%s", f, wid, ver, ext)
end proc:

MakeName("MyFile", 1);
                         "MyFile01.txt"

 

This works:

thaw(eval(evalindets(expr, specfunc(invlaplace), freeze), t= 0));

To understand why your other ideas can't work, look at

In1:= indets(expr, anything);
In2:= indets(expr, Not(specfunc(invlaplace)));

For any type TNot(T) is also a type; it doesn't help you do want you want in this case.

Just add this to your initialization file:

plots:-setoptions(size= [300, 300]):

For some of the negative values of in your given range (-0.9 .. 0.2*Pi), the solve command in Proc returns (correctly) results with nonzero imaginary parts. This causes problems for some of the subsequent plotting commands. If you change the range to -0.4 .. 0.2*Pi, for example, then the command completes fine. I'm not saying that this is the widest range that'll work, simply that it's one that works.

Both your mysterious lack of randomization and the absence of infolevel printouts are due to the integral's value being "remembered" by evalf. If you simply put forget(evalf) into your loops, those anomalies will disappear.  Indeed, all that you need is this forget; you can remove the randomize.

restart:
infolevel[`evalf/int`]:= 4:
to 3 do
    ## seed:= randomize(rand());
    forget(evalf);
    J:= (evalf@Int)(
        4*x1*x3^2*exp(2*x1*x3)/(1+x2+x4)^2, 
        [x||(1..4)]=~ 0..1, method= _MonteCarlo, epsilon= 1e-2
    )
    ## print('seed' = seed,  'J' = J);
od;

Furthermore, it seems as if you were to use randomize, it would have no effect. I suspect (but I'm not sure) that this is because the random numbers are being generated by externally compiled code rather than by the Maple call-backs mentioned by @acer. This is unfortunate, because it means that the values cannot be stabilized by using randomize(key) where key is a loop invariant. The lack of stable answers makes debugging difficult.

I find this little utility procedure useful, because it lets you "forget" without needing a separate line of code for it (thus promoting functional programming):

forgotten:= C-> (forget(C), C):

Then in the loop, remove forget(evalf), and replace evalf@Int with forgotten(evalf)@Int.

1 2 3 4 5 6 7 Last Page 1 of 392