Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Alejandro Jakubi I thought I had fixed the Exist problem---guess not.  Thanks.  Not sure about the path issue with Windows, will look into it. I wonder if there is a problem with FileTools:-Copy not working with FAT 8.3 naming conventions.

@afeddersen There are no assumptions you can apply that will affect the sampled output---at least not to make this work.  That is, the probability function of the geometric distribution is p*(1-p)^t, where t is the value.  So the probability of selecting 0 is p*(1-p)^0 = p.  Given that, you won't be able to compute the mean of the ln of the random variable.  You could compute, say, Mean(ln(1+X1)) because 1+x is strictly positive.

You could do something like the following (don't know whether it is meaningful):

f := proc(t)
    if t :: numeric then
        if t <= 0 then 0
        else
            ln(t)
        end if;
    else
        'procname'(t)
    end if;
end proc:
        
ef := evalf(ExpectedValue(f(X1))); 
evalf(eval(ef, infinity=100));   # simple approx

@afeddersen There are no assumptions you can apply that will affect the sampled output---at least not to make this work.  That is, the probability function of the geometric distribution is p*(1-p)^t, where t is the value.  So the probability of selecting 0 is p*(1-p)^0 = p.  Given that, you won't be able to compute the mean of the ln of the random variable.  You could compute, say, Mean(ln(1+X1)) because 1+x is strictly positive.

You could do something like the following (don't know whether it is meaningful):

f := proc(t)
    if t :: numeric then
        if t <= 0 then 0
        else
            ln(t)
        end if;
    else
        'procname'(t)
    end if;
end proc:
        
ef := evalf(ExpectedValue(f(X1))); 
evalf(eval(ef, infinity=100));   # simple approx

@lovinash The assignment to the procedure in the file you uploaded appears to be invalid (though it looks correct in what you posted, however, the rendering is terrible on this site). You are better off using Maple input (rather than 2D input) to enter Maple procedures. Note that I've written up a small package, CompileTools, for copying compiled procedure, it is described here. Here I use it with your example

Gradientcross:=proc(limx1,limx2,limx3,limx4,limx5,y1,y2,y3,y4,y5)
global gradient1,gradient2,gradient3,gradient4,cross1,cross2,cross3,cross4;
    gradient1 := (y2-y1)/(limx2-limx1);
    gradient2 := (y3-y2)/(limx3-limx2);
    gradient3 := (y4-y3)/(limx4-limx3);
    gradient4 := (y5-y4)/(limx5-limx4);
    cross1 := y1-gradient1*limx1;
    cross2 := y2-gradient2*limx2;
    cross3 := y3-gradient3*limx3;
    cross4 := y4-gradient4*limx4;
end proc:

Gradientcross := Compiler:-Compile(Gradientcross):
Gradientcross := CompileTools:-Copy(Gradientcross):
LibraryTools:-Save(Gradientcross, "/home/joe/maple/lib/mygrad.mla"):
# Now restart and execute the procedure
restart;
Gradientcross(seq(1..10));
                               5.

@lovinash The assignment to the procedure in the file you uploaded appears to be invalid (though it looks correct in what you posted, however, the rendering is terrible on this site). You are better off using Maple input (rather than 2D input) to enter Maple procedures. Note that I've written up a small package, CompileTools, for copying compiled procedure, it is described here. Here I use it with your example

Gradientcross:=proc(limx1,limx2,limx3,limx4,limx5,y1,y2,y3,y4,y5)
global gradient1,gradient2,gradient3,gradient4,cross1,cross2,cross3,cross4;
    gradient1 := (y2-y1)/(limx2-limx1);
    gradient2 := (y3-y2)/(limx3-limx2);
    gradient3 := (y4-y3)/(limx4-limx3);
    gradient4 := (y5-y4)/(limx5-limx4);
    cross1 := y1-gradient1*limx1;
    cross2 := y2-gradient2*limx2;
    cross3 := y3-gradient3*limx3;
    cross4 := y4-gradient4*limx4;
end proc:

Gradientcross := Compiler:-Compile(Gradientcross):
Gradientcross := CompileTools:-Copy(Gradientcross):
LibraryTools:-Save(Gradientcross, "/home/joe/maple/lib/mygrad.mla"):
# Now restart and execute the procedure
restart;
Gradientcross(seq(1..10));
                               5.

@acer I was thinking the same thing.  Will also show how it might be more usefully employed.  That is, it is probably better to save the procedures as exports of a module (so there is less an impact on namespace).  Doing so in the compiled form isn't entirely obvious. 

@acer I was thinking the same thing.  Will also show how it might be more usefully employed.  That is, it is probably better to save the procedures as exports of a module (so there is less an impact on namespace).  Doing so in the compiled form isn't entirely obvious. 

@Alejandro Jakubi Good point, I forgot about that. A better solution---because it is straightforward and O/S independent---would be to use FileTools:-Filename. Also, getenv("HOME") might not return anything useful on Windows.

@Alejandro Jakubi Good point, I forgot about that. A better solution---because it is straightforward and O/S independent---would be to use FileTools:-Filename. Also, getenv("HOME") might not return anything useful on Windows.

@lovinash Here's a demonstration of how you might do just that.

# Create a toy procedure
f := proc(x) x^2; end proc:
# Compile it
fc := Compiler:-Compile(f);
fc := proc()
option call_external, define_external(_m4fa7f349fa8b242dec87f5b731cbf23e,
MAPLE, LIB = "/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so");
    call_external(0, 140313356125888, true, false, args)
end proc


# Convert to an inert form
inert := ToInert(eval(fc));
inert := _Inert_PROC(_Inert_PARAMSEQ(), _Inert_LOCALSEQ(), _Inert_OPTIONSEQ(

    _Inert_ASSIGNEDNAME("call_external", "PROC", %1), _Inert_FUNCTION(

    _Inert_ASSIGNEDNAME("define_external", "PROC", %1), _Inert_EXPSEQ(

    _Inert_ASSIGNEDNAME("_m4fa7f349fa8b242dec87f5b731cbf23e", "PROC"),

    _Inert_NAME("MAPLE"), _Inert_EQUATION(_Inert_NAME("LIB"),

    _Inert_STRING("/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so"))))),

    _Inert_EXPSEQ(), _Inert_STATSEQ(_Inert_FUNCTION(

    _Inert_ASSIGNEDNAME("call_external", "PROC", %1), _Inert_EXPSEQ(

    _Inert_INTPOS(0), _Inert_INTPOS(140313356125888), _Inert_NAME("true", %1),

    _Inert_NAME("false", %1), _Inert_ARGS()))), _Inert_DESCRIPTIONSEQ(),

    _Inert_GLOBALSEQ(), _Inert_LEXICALSEQ(), _Inert_EOP(_Inert_EXPSEQ()))

%1 := _Inert_ATTRIBUTE(

    _Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))))


# Extract the temporary filename
tmpfile := op([1,1], indets(inert, _Inert_STRING(string)));
       tmpfile := "/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so"


# Extract the basename
StringTools:-RegMatch("[^/]*$", tmpfile, 'base');
                                     true


# Assign a directory where the temporary file and a Maple library will
# go (they don't have to go to the same directory).  The Maple library
# should be in libname.

libdir := sprintf("%s/maple/lib", getenv("HOME"));
                        libdir := "/home/joe/maple/lib"

lib := sprintf("%s/%s", libdir, base);
      lib := "/home/joe/maple/lib/_m4fa7f349fa8b242dec87f5b731cbf23e.so"


# Copy the temporary file to its new location
FileTools:-Copy(tmpfile, lib, 'force'=true):

# Replace f with the compiled version, with the new location.
f := subs(tmpfile=lib, eval(fc)):

# Save f to a Maple archive
LibraryTools:-Save('f', sprintf("%s/f.mla", libdir));

# Restart Maple and see that 'f' works.
restart;
f(23.0);
                                     529.

@lovinash Here's a demonstration of how you might do just that.

# Create a toy procedure
f := proc(x) x^2; end proc:
# Compile it
fc := Compiler:-Compile(f);
fc := proc()
option call_external, define_external(_m4fa7f349fa8b242dec87f5b731cbf23e,
MAPLE, LIB = "/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so");
    call_external(0, 140313356125888, true, false, args)
end proc


# Convert to an inert form
inert := ToInert(eval(fc));
inert := _Inert_PROC(_Inert_PARAMSEQ(), _Inert_LOCALSEQ(), _Inert_OPTIONSEQ(

    _Inert_ASSIGNEDNAME("call_external", "PROC", %1), _Inert_FUNCTION(

    _Inert_ASSIGNEDNAME("define_external", "PROC", %1), _Inert_EXPSEQ(

    _Inert_ASSIGNEDNAME("_m4fa7f349fa8b242dec87f5b731cbf23e", "PROC"),

    _Inert_NAME("MAPLE"), _Inert_EQUATION(_Inert_NAME("LIB"),

    _Inert_STRING("/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so"))))),

    _Inert_EXPSEQ(), _Inert_STATSEQ(_Inert_FUNCTION(

    _Inert_ASSIGNEDNAME("call_external", "PROC", %1), _Inert_EXPSEQ(

    _Inert_INTPOS(0), _Inert_INTPOS(140313356125888), _Inert_NAME("true", %1),

    _Inert_NAME("false", %1), _Inert_ARGS()))), _Inert_DESCRIPTIONSEQ(),

    _Inert_GLOBALSEQ(), _Inert_LEXICALSEQ(), _Inert_EOP(_Inert_EXPSEQ()))

%1 := _Inert_ATTRIBUTE(

    _Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))))


# Extract the temporary filename
tmpfile := op([1,1], indets(inert, _Inert_STRING(string)));
       tmpfile := "/tmp/joe-2622/_m4fa7f349fa8b242dec87f5b731cbf23e.so"


# Extract the basename
StringTools:-RegMatch("[^/]*$", tmpfile, 'base');
                                     true


# Assign a directory where the temporary file and a Maple library will
# go (they don't have to go to the same directory).  The Maple library
# should be in libname.

libdir := sprintf("%s/maple/lib", getenv("HOME"));
                        libdir := "/home/joe/maple/lib"

lib := sprintf("%s/%s", libdir, base);
      lib := "/home/joe/maple/lib/_m4fa7f349fa8b242dec87f5b731cbf23e.so"


# Copy the temporary file to its new location
FileTools:-Copy(tmpfile, lib, 'force'=true):

# Replace f with the compiled version, with the new location.
f := subs(tmpfile=lib, eval(fc)):

# Save f to a Maple archive
LibraryTools:-Save('f', sprintf("%s/f.mla", libdir));

# Restart Maple and see that 'f' works.
restart;
f(23.0);
                                     529.

What is megold? There are a few problems with your approach.  Note that int does not accept differential equations, which is what you are currently passing to it. Also, as I mentioned before, square brackets do not work as arithmetic parentheses in Maple.  They can be used to form lists or as index operators.

What is megold? There are a few problems with your approach.  Note that int does not accept differential equations, which is what you are currently passing to it. Also, as I mentioned before, square brackets do not work as arithmetic parentheses in Maple.  They can be used to form lists or as index operators.

@acer  Your technique is certainly useful.  I should have been clearer; my point wasn't to object to the method but rather to point out a limitation to its application, albeit one that probably rarely occurs. 

@acer  Your technique is certainly useful.  I should have been clearer; my point wasn't to object to the method but rather to point out a limitation to its application, albeit one that probably rarely occurs. 

First 86 87 88 89 90 91 92 Last Page 88 of 195