Alec Mihailovs

Dr. Aleksandrs Mihailovs

4470 Reputation

21 Badges

20 years, 22 days
Mihailovs, Inc.
Owner, President, and CEO
Tyngsboro, Massachusetts, United States

Social Networks and Content at Maplesoft.com

Maple Application Center

I received my Ph.D. from the University of Pennsylvania in 1998 and I have been teaching since then at SUNY Oneonta for 1 year, at Shepherd University for 5 years, at Tennessee Tech for 2 years, at Lane College for 1 year, and this year I taught at the University of Massachusetts Lowell. My research interests include Representation Theory and Combinatorics.

MaplePrimes Activity


These are replies submitted by Alec Mihailovs

It may be considered as a bug - they should be protected to avoid such problems.
To do further calculations, I produced a dll with code written in assembler. In Maple, it can be called as pt(b,A); for example, pt(10,A) for base 10 after defining
pt:=define_external( 
       'pt', 
       'b'::integer[1], 
       'A'::ARRAY(1..100,datatype=integer[1]), 
       'RETURN'::integer[4], 
       'LIB'="C:/MyProjects/Assembly/Ponder/Ponder.dll" 
);
A:=Array(1..100,datatype=integer[1]);
with changing the value of LIB to the location of Ponder.dll. It appeared to be about 3 times faster than the compiled procedure a3. Here are the results of calculations for b from 2 to 23, 2, 6, 7, 10, 11, 18, 17, 22, 25, 26, 28, 35, 39, 38, 39, 45, 48, 48, 52, 53, 56, 58.
Amanda, If I understand you correctly, you want to remove inequalities depending on other inequalities from the list. That can be done more simple with sets instead of lists,
R := proc(S)
local s, a;
    s := S;
    for a in S do
        if (is(a) assuming op(s minus {a})) then
            s := s minus {a}
        end if
    end do;
    s
end proc
For example,
s1:={x<3, x<9, x>0, x>1/2, x<2, x>-4}:
R(s1);
                           {1/2 < x, x < 2}
s2:={x>0,y>0,x+y<1,2*x+3*y<6}:
R(s2);
                      {0 < x, 0 < y, x + y < 1}
s3:={x<0,2*x<0}:
R(s3);
                              {2 x < 0}
Try if it works in your examples.
Amanda, If I understand you correctly, you want to remove inequalities depending on other inequalities from the list. That can be done more simple with sets instead of lists,
R := proc(S)
local s, a;
    s := S;
    for a in S do
        if (is(a) assuming op(s minus {a})) then
            s := s minus {a}
        end if
    end do;
    s
end proc
For example,
s1:={x<3, x<9, x>0, x>1/2, x<2, x>-4}:
R(s1);
                           {1/2 < x, x < 2}
s2:={x>0,y>0,x+y<1,2*x+3*y<6}:
R(s2);
                      {0 < x, 0 < y, x + y < 1}
s3:={x<0,2*x<0}:
R(s3);
                              {2 x < 0}
Try if it works in your examples.
Adding a link to this site in the Help menu of Maple 10.1 would be helpful... As well as adding links to the Welcome and other pages on the corporate site.
Also, if the purpose of this is to solve the system of inequalities, then it can be done using solve:
mylist:=[x<3, x<9, x>0, x>1/2, x<2, x>-4];

       mylist := [x < 3, x < 9, 0 < x, 1/2 < x, x < 2, -4 < x]

solve(mylist);

                           {1/2 < x, x < 2}
Also, if the purpose of this is to solve the system of inequalities, then it can be done using solve:
mylist:=[x<3, x<9, x>0, x>1/2, x<2, x>-4];

       mylist := [x < 3, x < 9, 0 < x, 1/2 < x, x < 2, -4 < x]

solve(mylist);

                           {1/2 < x, x < 2}
I would add a 100 frames (or more :)
I would add a 100 frames (or more :)
mylist:=[x<3, x<9, x>0, x>1/2, x<2, x>-4];

       mylist := [x < 3, x < 9, 0 < x, 1/2 < x, x < 2, -4 < x]

mylist:=[mylist[1],op(remove(is,mylist) assuming mylist[1])];

           mylist := [x < 3, 0 < x, 1/2 < x, x < 2, -4 < x]

mylist:=[op(mylist[1..2]),op(remove(is,mylist[3..-1]) assuming mylist[2])];

               mylist := [x < 3, 0 < x, 1/2 < x, x < 2]
mylist:=[x<3, x<9, x>0, x>1/2, x<2, x>-4];

       mylist := [x < 3, x < 9, 0 < x, 1/2 < x, x < 2, -4 < x]

mylist:=[mylist[1],op(remove(is,mylist) assuming mylist[1])];

           mylist := [x < 3, 0 < x, 1/2 < x, x < 2, -4 < x]

mylist:=[op(mylist[1..2]),op(remove(is,mylist[3..-1]) assuming mylist[2])];

               mylist := [x < 3, 0 < x, 1/2 < x, x < 2]
Also, the compiled procedure for Dumb Kopf is much faster. Again, it is just the first try - I have no doubt that it can be further improved,
a5 := proc(b::integer[4], A::Array(datatype = integer[4]))::
integer[4];
local c::integer[4], i::integer[4], j::integer[4],
k::integer[4], m::integer[4], K::integer[4], s::integer[4],
r::integer[4];
    A[1] := 1;
    i := 2;
    K := 1;
    s := 1;
    while 0 < i do
        if s = 1 then
            r := irem(A[1], i);
            for j from 2 to i - 1 do r := irem(r*b + A[j], i)
            end do;
            r := irem(r*b, i);
            c := -r;
            s := 0;
            for k to iquo(b - 1 + r, i) do
                c := c + i;
                for m to i - 1 do
                    if c = A[m] then break end if
                end do;
                if m = i then
                    A[i] := c;
                    K := max(K, i);
                    i := i + 1;
                    s := 1;
                    break
                end if
            end do;
            if s = 0 then i := i - 1 end if
        else
            if A[i] + i < b then
                c := A[i];
                for k to iquo(b - 1 - A[i], i) do
                    c := c + i;
                    for m to i - 1 do
                        if c = A[m] then break end if
                    end do;
                    if m = i then
                        A[i] := c; i := i + 1; s := 1; break
                    end if
                end do;
                if s = 0 then i := i - 1 end if
            else i := i - 1
            end if
        end if
    end do;
    K
end proc:

a6:=Compiler:-Compile(a5):
A:=Array(1..100,datatype=integer[4]):
It should be called as a6(b,A) where b is the base and A is a predefined Array with datatype=integer[4] and length greater than or equal to b. It returns the maximal number of digits for the Dumb Kopf problem. In particular, the returned values for b from 24 to 32 are 19, 23, 22, 24, 23, 27, 24, 29, 27.
Now, compiled procedures should run much faster. Here is the first try,
a2 := proc(b::integer[4], A::Array(datatype = integer[4]))::
integer[4];
local i::integer[4], j::integer[4], K::integer[4],
s::integer[4], r::integer[4];
    A[1] := 1;
    i := 2;
    K := 1;
    s := 1;
    while 0 < i do
        if s = 1 then
            r := irem(A[1], i);
            for j from 2 to i - 1 do r := irem(r*b + A[j], i)
            end do;
            r := irem(r*b, i);
            if r = 0 then
                A[i] := 0; K := max(K, i); i := i + 1
            elif b - 1 + r < i then i := i - 1; s := 0
            else A[i] := i - r; K := max(K, i); i := i + 1
            end if
        else
            if A[i] + i < b then
                A[i] := A[i] + i; i := i + 1; s := 1
            else i := i - 1
            end if
        end if
    end do;
    K
end proc:

a3:=Compiler:-Compile(a2):
A:=Array(1..100,datatype=integer[4]):
While a2 is slower than a, the compiled procedure a3 is much faster. For example,
tt:=time(): a3(10,A); time()-tt;
                                  25
                                0.016
It should be called as a3(b,A) where b is the base and A is a predefined Array with datatype=integer[4] and length greater than the expected maximal number of digits. It returns the maximal number of digits. In particular, for b from 17 to 21 the maximal number of digits has appeared to be 45, 48, 48, 52, 53.
?type,And _______ Alec Mihailovs http://math.tntech.edu/alec/
?type,And _______ Alec Mihailovs http://math.tntech.edu/alec/
First 176 177 178 179 180 Page 178 of 180