acer

32385 Reputation

29 Badges

19 years, 335 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

This can be considered as a feasibility question: given some linear constraints and the requirement of an integer-value solution then find a feasible point.

If one adds in a linear objective function then it can be seen as the familiar (I)LP. The Optimization package can handle this particular example, if we supply an (here inconsequential) objective.

Optimization:-Minimize(1,
                       {6*x+2*y>=49, 7*x+3*y=0, y>=0},
                       assume=integer)[2];

                         [x = 8, y = 1]

acer

Ok, so the inner addition can benefit from being done inside a procedure with `option remember`.

And I was mistaken about a recursive outer addition (with option remember) since the `x` value changes each time.

And there's another, relatively smaller, benefit from using `trunc` instead of `floor`.

restart:

S := x->1+add(trunc((x/(add(trunc(cos(Pi*(factorial(n-1)+1)/n)^2),
              n = 1 .. r)))^(1/x)), r = 1 .. 2^x):

CodeTools:-Usage( seq(S(x), x = 1 .. 7) );
memory used=1.10GiB, alloc change=63.99MiB, cpu time=15.13s, real time=15.13s
                     2, 3, 5, 7, 11, 13, 17

restart:

K := proc(r)
     option remember;
       add(trunc(cos(Pi*(factorial(n-1)+1)/n)^2),n=1..r);
     end proc:

S := x->1+add(trunc((x/K(r))^(1/x)),r=1..2^x):

CodeTools:-Usage( seq(S(x),x=1..7) );
memory used=0.87GiB, alloc change=63.99MiB, cpu time=12.08s, real time=12.08s
                     2, 3, 5, 7, 11, 13, 17

Of course, it still becomes slow quickly.

acer

Ok, so the inner addition can benefit from being done inside a procedure with `option remember`.

And I was mistaken about a recursive outer addition (with option remember) since the `x` value changes each time.

And there's another, relatively smaller, benefit from using `trunc` instead of `floor`.

restart:

S := x->1+add(trunc((x/(add(trunc(cos(Pi*(factorial(n-1)+1)/n)^2),
              n = 1 .. r)))^(1/x)), r = 1 .. 2^x):

CodeTools:-Usage( seq(S(x), x = 1 .. 7) );
memory used=1.10GiB, alloc change=63.99MiB, cpu time=15.13s, real time=15.13s
                     2, 3, 5, 7, 11, 13, 17

restart:

K := proc(r)
     option remember;
       add(trunc(cos(Pi*(factorial(n-1)+1)/n)^2),n=1..r);
     end proc:

S := x->1+add(trunc((x/K(r))^(1/x)),r=1..2^x):

CodeTools:-Usage( seq(S(x),x=1..7) );
memory used=0.87GiB, alloc change=63.99MiB, cpu time=12.08s, real time=12.08s
                     2, 3, 5, 7, 11, 13, 17

Of course, it still becomes slow quickly.

acer

@serena88 Sure, although my spare time is limited this month.

You could post it here, in this thread

..or you could email it to me (I'll contact you, so you have my address)

..or you could upload it to the Maple Cloud (see my profile page, for a cloud group where it would be private)

@serena88 Sure, although my spare time is limited this month.

You could post it here, in this thread

..or you could email it to me (I'll contact you, so you have my address)

..or you could upload it to the Maple Cloud (see my profile page, for a cloud group where it would be private)

The Matrix() constructor can build that full Matrix directly, as it is pretty smart about flattening the various blocks that you've defined.

O31 := Matrix(3,1):

Matrix([[     Id,       Y,    -X,  a*X ],
        [    b*Y,       Z,   O31,  O31 ],
        [   X^%T,  O31^%T,     0,    0 ],
        [ O31^%T,  O31^%T,     0,    q ]]);

                        [ 1   0   0  4  9  9  -4  8]
                        [                          ]
                        [ 0   1   0  7  6  2  -4  8]
                        [                          ]
                        [ 0   0   1  4  9  7  -3  6]
                        [                          ]
                        [12  27  27  2  3  9   0  0]
                        [                          ]
                        [21  18   6  5  5  4   0  0]
                        [                          ]
                        [12  27  21  3  9  7   0  0]
                        [                          ]
                        [ 4   4   3  0  0  0   0  0]
                        [                          ]
                        [ 0   0   0  0  0  0   0  5]

But I fear that was the questioner really wants is not so much a fully explicit entry-by-entry representation of the inverse of this explicit Matrix. I suspect that what he may be asking for is a block-Matrix representation of the inverse of his block-Matrix. And Maple does not have tools in LinearAlgebra to do that. One of the practical difficulties with attempting it (using the current toolset) is that at some point some compound products of the block's names (scalar names) will be computed wrongly, as if the blocks (Matrix blocks) commuted under Matrix-multiplication.

For example, consider the determinant which would get computed if all these block names had not yet been assigned,

restart:
with(LinearAlgebra):

M := Matrix([[     Id,       Y,    -X,  a*X ],
             [    b*Y,       Z,   O31,  O31 ],
             [   X^%T,  O31^%T,     0,    0 ],
             [ O31^%T,  O31^%T,     0,    q ]]):

Determinant(M);

       2         2                      2  2        3      3                
 -q O31  Id + q X  Z - q O31 b Y X - O31  X  + X O31  + O31  a X + q X Y O31

         2  2  
    - O31  X  a

That q*X^2*Z term, for example, looks like it has violated noncommativity of the blocks under Matrix-multiplication. Many years ago, I might have tried to work aorund this, by using non-commuting `&*` as possible overload. But nowaways I'd prefer to submit yet another SCR for such this block Matrix support (a weaker kind of abstract linear algbera).

acer

The Matrix() constructor can build that full Matrix directly, as it is pretty smart about flattening the various blocks that you've defined.

O31 := Matrix(3,1):

Matrix([[     Id,       Y,    -X,  a*X ],
        [    b*Y,       Z,   O31,  O31 ],
        [   X^%T,  O31^%T,     0,    0 ],
        [ O31^%T,  O31^%T,     0,    q ]]);

                        [ 1   0   0  4  9  9  -4  8]
                        [                          ]
                        [ 0   1   0  7  6  2  -4  8]
                        [                          ]
                        [ 0   0   1  4  9  7  -3  6]
                        [                          ]
                        [12  27  27  2  3  9   0  0]
                        [                          ]
                        [21  18   6  5  5  4   0  0]
                        [                          ]
                        [12  27  21  3  9  7   0  0]
                        [                          ]
                        [ 4   4   3  0  0  0   0  0]
                        [                          ]
                        [ 0   0   0  0  0  0   0  5]

But I fear that was the questioner really wants is not so much a fully explicit entry-by-entry representation of the inverse of this explicit Matrix. I suspect that what he may be asking for is a block-Matrix representation of the inverse of his block-Matrix. And Maple does not have tools in LinearAlgebra to do that. One of the practical difficulties with attempting it (using the current toolset) is that at some point some compound products of the block's names (scalar names) will be computed wrongly, as if the blocks (Matrix blocks) commuted under Matrix-multiplication.

For example, consider the determinant which would get computed if all these block names had not yet been assigned,

restart:
with(LinearAlgebra):

M := Matrix([[     Id,       Y,    -X,  a*X ],
             [    b*Y,       Z,   O31,  O31 ],
             [   X^%T,  O31^%T,     0,    0 ],
             [ O31^%T,  O31^%T,     0,    q ]]):

Determinant(M);

       2         2                      2  2        3      3                
 -q O31  Id + q X  Z - q O31 b Y X - O31  X  + X O31  + O31  a X + q X Y O31

         2  2  
    - O31  X  a

That q*X^2*Z term, for example, looks like it has violated noncommativity of the blocks under Matrix-multiplication. Many years ago, I might have tried to work aorund this, by using non-commuting `&*` as possible overload. But nowaways I'd prefer to submit yet another SCR for such this block Matrix support (a weaker kind of abstract linear algbera).

acer

@Danik Change all instances of `pi` to `Pi`.

In Maple, `Pi` is a name which evaluates in floating-point approximation to 3.14...

But `pi` is just another name, with no such meaning or behaviour by default.

@Danik Change all instances of `pi` to `Pi`.

In Maple, `Pi` is a name which evaluates in floating-point approximation to 3.14...

But `pi` is just another name, with no such meaning or behaviour by default.

@toandhsp 

ksols :=  isolve({(1/9)*Pi+2*k*Pi*(1/3) >= 1, (1/9)*Pi+2*k*Pi*(1/3)<= 2^Pi}) ;

               {k = 1}, {k = 2}, {k = 3}, {k = 4}

op( map2( eval, Pi/9+2*k*Pi/3, {ksols} ) );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

seq( eval( Pi/9+2*k*Pi/3, K), K in ksols );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

f := k -> Pi/9+2*k*Pi/3:

seq( f(rhs(op(K))), K in ksols );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

@toandhsp 

ksols :=  isolve({(1/9)*Pi+2*k*Pi*(1/3) >= 1, (1/9)*Pi+2*k*Pi*(1/3)<= 2^Pi}) ;

               {k = 1}, {k = 2}, {k = 3}, {k = 4}

op( map2( eval, Pi/9+2*k*Pi/3, {ksols} ) );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

seq( eval( Pi/9+2*k*Pi/3, K), K in ksols );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

f := k -> Pi/9+2*k*Pi/3:

seq( f(rhs(op(K))), K in ksols );

                   7     13     19     25   
                   - Pi, -- Pi, -- Pi, -- Pi
                   9     9      9      9    

@Lautrup I have a copy of what appears to be the Dcoument, repaired. It is 8.5Mb. Uploading it to Mapleprimes, even zipped, fails.

I will contact you. If you respond to the email then I will have your address and can send you the zipped file.

acer

@Lautrup I have a copy of what appears to be the Dcoument, repaired. It is 8.5Mb. Uploading it to Mapleprimes, even zipped, fails.

I will contact you. If you respond to the email then I will have your address and can send you the zipped file.

acer

@KCM 

p:=expand( (x+x^2)*(x+2) );

                           2          3
                        3 x  + 2 x + x 

sort(p,x);

                         3      2      
                        x  + 3 x  + 2 x

sort(p,x,ascending);

                                 2    3
                        2 x + 3 x  + x 

You can read about `sort` on its help-page.

@KCM 

p:=expand( (x+x^2)*(x+2) );

                           2          3
                        3 x  + 2 x + x 

sort(p,x);

                         3      2      
                        x  + 3 x  + 2 x

sort(p,x,ascending);

                                 2    3
                        2 x + 3 x  + x 

You can read about `sort` on its help-page.

First 413 414 415 416 417 418 419 Last Page 415 of 592