Alec Mihailovs

Dr. Aleksandrs Mihailovs

4435 Reputation

21 Badges

19 years, 99 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 should be assign(a=0,b=1/2,c=0) because assign evaluates the variables.
I am not sure that it is the same example, but I already posted few years ago in MUG an example of doing that with Visual Studio and another example of creating a dll using cygwin gcc. It works with Open Watcom compiler in the following form. Create mulmat.c file with the following code taken from an example in the Application Center,
__declspec(dllexport) void __stdcall multiply
( int *A, int *B, int *C, int I, int J, int K, int p )
{
int i, j, k;
int t;
for( i = 0; i < I; i++ )
for( k = 0; k < K; k++ ) {
t = 0;
for( j = 0; j < J; j++ ) { 

t += A[i*J+j] * B[j*K+k]; 

t %= p; if (t < 0) t += p; 

} 

C[i*K+k] = t;
}
} 
Switch in Maple to folder with it,
currentdir("C:/MyProjects/C/Mulmat");
Produce a dll,
ssystem("wcl386 -c -bd mulmat.c");
ssystem("wlink system nt_dll file mulmat.obj");
Then define in Maple
multiplyMatrixModp := define_external(
'multiply',
'a'::ARRAY(1..i,1..j,integer[4]),
'b'::ARRAY(1..j,1..k,integer[4]),
'c'::REF(ARRAY(1..i,1..k,integer[4]),RETURN_ONLY),
'i'::integer[4],
'j'::integer[4],
'k'::integer[4],
'p'::integer[4],
'LIB'="C:/MyProjects/C/Mulmat/mulmat.dll");
It works as follows,
E:=Matrix([[1,2],[3,4]],datatype=integer[4],order=C_order);

                                 [1    2]
                            E := [      ]
                                 [3    4]

F:=Matrix([[0,1],[2,3]],datatype=integer[4],order=C_order);

                                 [0    1]
                            F := [      ]
                                 [2    3]

G:=Matrix(2,2,datatype=integer[4],order=C_order):

multiplyMatrixModp(E,F,G,2,2,2,5);

G;

                               [4    2]
                               [      ]
                               [3    0]
Seems to be OK.
I am not sure that it is the same example, but I already posted few years ago in MUG an example of doing that with Visual Studio and another example of creating a dll using cygwin gcc. It works with Open Watcom compiler in the following form. Create mulmat.c file with the following code taken from an example in the Application Center,
__declspec(dllexport) void __stdcall multiply
( int *A, int *B, int *C, int I, int J, int K, int p )
{
int i, j, k;
int t;
for( i = 0; i < I; i++ )
for( k = 0; k < K; k++ ) {
t = 0;
for( j = 0; j < J; j++ ) { 

t += A[i*J+j] * B[j*K+k]; 

t %= p; if (t < 0) t += p; 

} 

C[i*K+k] = t;
}
} 
Switch in Maple to folder with it,
currentdir("C:/MyProjects/C/Mulmat");
Produce a dll,
ssystem("wcl386 -c -bd mulmat.c");
ssystem("wlink system nt_dll file mulmat.obj");
Then define in Maple
multiplyMatrixModp := define_external(
'multiply',
'a'::ARRAY(1..i,1..j,integer[4]),
'b'::ARRAY(1..j,1..k,integer[4]),
'c'::REF(ARRAY(1..i,1..k,integer[4]),RETURN_ONLY),
'i'::integer[4],
'j'::integer[4],
'k'::integer[4],
'p'::integer[4],
'LIB'="C:/MyProjects/C/Mulmat/mulmat.dll");
It works as follows,
E:=Matrix([[1,2],[3,4]],datatype=integer[4],order=C_order);

                                 [1    2]
                            E := [      ]
                                 [3    4]

F:=Matrix([[0,1],[2,3]],datatype=integer[4],order=C_order);

                                 [0    1]
                            F := [      ]
                                 [2    3]

G:=Matrix(2,2,datatype=integer[4],order=C_order):

multiplyMatrixModp(E,F,G,2,2,2,5);

G;

                               [4    2]
                               [      ]
                               [3    0]
Seems to be OK.
I am trying to avoid including maplec.h if possible. Mktime should be able to calculate wday without specifying hours, minutes, and seconds. However, different libc versions in Linux have different bugs in mktime. In particular, not being able to calculate wday without specifying min, sec, and hour happens because these values are corrected - so that 25 hours, for example, is changed to 1 hour of the next day, in which case the day of the week also changes. By the way, glibc has 2 additional fields in the tm structure - long tm_gmtoff (seconds east of UTC) and const char *tm_tm_zone (timezone abbreviation) that allows calculating the epoch in different time zones by adding one more parameter to mk (and mktime in Maple). I thought about adding of that additional field initially, but then decided not to do that - because the adjustment can be easily done in Maple if necessary. tm_isdst is a required field. Assigning it to 0 means that the time is standard (not day saving time). Assigning it to a positive value means that the day saving time is in effect. Assigning it to a negative value determines whether the day saving time is in effect or not from the computer time zone settings.
That is the epoch of that time in your time zone. My time zone (CDT) has 2 hour = 7200 sec difference with PDT - that explains the difference between numbers. If tm_isdst is negative, the offset (including day saving time) is determined by computer time zone setting (as through tzset). If you enter the current time in mktime and then compare it with iolib(25), the numbers should coincide (up to few seconds of difference between the times of execution of 2 commands).
TZ has 3 different formats. America/Los_Angeles refers to the data in the corresponding file (it is a path). Another way of doing that is to assign TZ to something like PST8PDT7. Numbers are required (at least one). Letters are ignored (except there should be at least 3 of them).
TZ has 3 different formats. America/Los_Angeles refers to the data in the corresponding file (it is a path). Another way of doing that is to assign TZ to something like PST8PDT7. Numbers are required (at least one). Letters are ignored (except there should be at least 3 of them).
Same in Windows. If I set TZ to whatever, FormatTime("%Z") displays it. Usually it is not set, so it displays question marks (as in the help page).
Same in Windows. If I set TZ to whatever, FormatTime("%Z") displays it. Usually it is not set, so it displays question marks (as in the help page).
Just curious - does the /etc/zoneinfo/localtime file in Irix contain the timezone information? Is TZ environmental variable set in Irix and your Linux?
Just curious - does the /etc/zoneinfo/localtime file in Irix contain the timezone information? Is TZ environmental variable set in Irix and your Linux?
See also this list of free compilers.
See also this list of free compilers.
I must say that this joke is more popular among non-mathematicians than among mathematicians, because most of the mathematicians have no idea what a grape is (what Abelian means is clear though).
Similarly, it is easy to produce a function determining a day of the week. Just add the following code to the mktime.c,
extern __declspec(dllexport) int __stdcall wday(int mon, int mday, int year) {

	struct tm time_str;

    time_str.tm_year       = year - 1900;
    time_str.tm_mon        = mon - 1;
    time_str.tm_mday       = mday;

	mktime(&time_str);

    return( time_str.tm_wday );
}
Produce a dll using the same Maple commands. Now, define wday function in Maple as
wday:=define_external( 
       'wday', 
       'mon'::integer[4], 
       'mday'::integer[4],
       'year'::integer[4],
       'RETURN'::integer[4], 
       'LIB'="C:/MyProjects/C/mktime/mktime.dll" 
);
The following function will calculate the day of the week,
WeekDay:=(mon,day,year)-> 
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
[wday(mon,day,year)+1]:
For example,
WeekDay(8,27,2005);
                              "Saturday"
First 173 174 175 176 177 178 179 Page 175 of 180