Joe Riel

9660 Reputation

23 Badges

20 years, 20 days

MaplePrimes Activity


These are replies submitted by Joe Riel

It has some advantages.  However, if operators are used then we should use D to compute the differential:

D[1,2](g);
                                           2    2       2        2   2    2
                                          x  - y     2 x      2 x  (x  - y )
(x, y) -> piecewise(And(x = 0, y = 0), 0, ------- + ------- - --------------
                                           2    2    2    2       2    2 2
                                          x  + y    x  + y      (x  + y )

           2        2   2    2       2  2   2    2
        2 y      2 y  (x  - y )   8 x  y  (x  - y )
     - ------- - -------------- + -----------------)
        2    2       2    2 2          2    2 3
       x  + y      (x  + y )         (x  + y )

which is incorrect at the origin. 

I was testing with Maple12.  I see what you mean when using Maple11:

In Maple11:

for x to 4 do printf("%5a: %a\n", x,tmp(x,0.7)); end do:
    1: .4285714286 = 2.307800000
    2: .8571428571 = 4.668000000
    3: 1.285714286 = 6.961600000
    4: 1.714285714 = 9.369700000

In Maple12:

    1: .4285714286 = .4169000000
    2: .8571428571 = .8554000000
    3: 1.285714286 = 1.277800000
    4: 1.714285714 = 1.720100000

It appears that this works properly only when x, the number of trials, is integral. 

tmp := proc(x,p,n::posint:=10\000)
local NBN;
uses Statistics;
    NBN := RandomVariable(NegativeBinomial(x,p));
    ([Mean,Variance](NBN) = [Mean,Variance](Sample(NBN,n)));
end proc:

tmp(1, 0.5);
           [1.000000000, 2.000000000] = [0.9941000000, 1.980987860]

tmp(1.5, 0.5);
           [1.500000000, 3.000000000] = [0.9949000000, 1.985792818]

tmp(2, 0.5);
            [2.000000000, 4.000000000] = [1.989200000, 4.060187207]

tmp(3, 0.5);
            [3.000000000, 6.000000000] = [2.988600000, 5.969710531]

In fact, the sample operation appears to return a Pascal distribution for floor(x):

tmp(1.3, 0.5);
            [1.300000000, 2.600000000] = [1.017100000, 2.000993339]
tmp(2, 0.5);
            [2.000000000, 4.000000000] = [1.997000000, 3.937246114]
tmp(2.3, 0.5);
            [2.300000000, 4.600000000] = [1.976200000, 3.909588949]
tmp(2.9, 0.5);
            [2.900000000, 5.800000000] = [2.018600000, 3.939885830]
 

Your description of the problem is not entirely clear. Maybe you could clarify.  Is the 5x5 size of the Matrix completely arbitrary (from an algorithmic standpoint)?  Seems like it.  

How is the left side of condition 1 to be interpreted?  For example, suppose a(1,1) = [x1,...,x6] and a(1,2) = [y1,...,y6],  what is min(a(1,1),a(1,2))?  Do you mean [min(x1,y1),...,min(x6,y6)]?

Similarly, how is condition 2 interpreted?  Why not post Maple code that validates the conditions; that would clarify things and writing that code should be considerably easier than generating an algorithm to meet them.  Also, you might demonstrate a Matrix that meets your requirements for a simpler case, say A = [0,1] and M a 2x2 matrix.

 

 

The usual way to assign the expression is

f := x*y*(x^2-y^2)/(x^2+y^2);

However, that is undefined at x=0, y=0 (actually, evaluating there generates an error).  We could try to use piecewise to assign a value of 0 there

f1 := piecewise(And(x=0,y=0), 0, f);

however, that doesn't work since the presence of the inert boolean prevents, apparently, the entire expression from being evaluated even when it evaluates true:

eval(f1, [x=0,y=0]);
Error, (in eval/piecewise) numeric exception: division by zero

One way around that it to use a nested piecewise, that avoids the use of the inert boolean (And), however, it is quite ugly:

f2 := piecewise(x=0, piecewise(y=0, 0, f), f);
eval(f2, [x=0,y=0]);
                                     0

What do you hope to accomplish with the expression?  Your best solution may be to create a procedure:

f := proc(N) local n; add(n, n=select(isprime([seq(1..N)])) end proc:

Preferable might be to move the prime selection into the expression:

f := proc(N) local n; add(`if`(isprime(n),n,0), n = 1..N) end proc:

 

What do you hope to accomplish with the expression?  Your best solution may be to create a procedure:

f := proc(N) local n; add(n, n=select(isprime([seq(1..N)])) end proc:

Preferable might be to move the prime selection into the expression:

f := proc(N) local n; add(`if`(isprime(n),n,0), n = 1..N) end proc:

 

I tested the three Ramanujan congruence identities (5, 7, and 11) for all appropriate integers between 20,000 and 30,000 with the modification I mentioned (replace 0.1 with 0.03).  All passed.

Yes.  Doing so may be tricky.  Conceptually easier, I think, is using ListTools:

use ListTools in
    L := Transpose([LengthSplit([seq(0..31)],4)]);
    L1 := Interleave(L[..2][]);
    L2 := Interleave(L[3..][]);
end use;

Look closely and you'll see some new (to Maple 12) syntactical sugar: the ability to omit end points of a range.

Here's one implementation of your suggestion of using ArrayTools:

use ArrayTools in
    A1 := Array([seq(0..31)]);
    A2 := Alias(A1, [4,8]);
    A3 := Alias(A2[..2,..], [16]);
    A4 := Alias(A2[3..,..], [16]);
end use:

Yes.  Doing so may be tricky.  Conceptually easier, I think, is using ListTools:

use ListTools in
    L := Transpose([LengthSplit([seq(0..31)],4)]);
    L1 := Interleave(L[..2][]);
    L2 := Interleave(L[3..][]);
end use;

Look closely and you'll see some new (to Maple 12) syntactical sugar: the ability to omit end points of a range.

Here's one implementation of your suggestion of using ArrayTools:

use ArrayTools in
    A1 := Array([seq(0..31)]);
    A2 := Alias(A1, [4,8]);
    A3 := Alias(A2[..2,..], [16]);
    A4 := Alias(A2[3..,..], [16]);
end use:

seq is slightly more efficient than $ for generating sequences ($ is better for replicating); the differences, however, are small.

For my amusement, here's a weird parameterless variation (not particularly efficient):

selectremove(rcurry(type,{0,1})@irem, [seq(0..30)], 4);

seq is slightly more efficient than $ for generating sequences ($ is better for replicating); the differences, however, are small.

For my amusement, here's a weird parameterless variation (not particularly efficient):

selectremove(rcurry(type,{0,1})@irem, [seq(0..30)], 4);

I assumed you'd be able to write it without Maple; I occasionally answer "open-loop".  Here is one possiblity, I couldn't think of anything shorter:

selectremove(n -> irem(n,4)<2, [seq(0..30)]);

 

I assumed you'd be able to write it without Maple; I occasionally answer "open-loop".  Here is one possiblity, I couldn't think of anything shorter:

selectremove(n -> irem(n,4)<2, [seq(0..30)]);

 

Agreed.  I know nothing about the particular algorithm, just printed the code, noted that it appears to be a truncation of Rademacher's infinite sum, and made an adjustment to the termination condition.  My first try, 0.05, worked for all but one of the list of known failures (I forget which, but it was closer to the beginning (smaller values) than the end). Fortunately, it is easy to change the value using subs...

First 138 139 140 141 142 143 144 Last Page 140 of 195