Joe Riel

8049 Reputation

22 Badges

15 years, 10 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Rouben Rostamian 

simplify(ln(b/a)) assuming positive;
              ln(b) - ln(a)

Before eliminating the conditional you need to understand why it is there.  Note that the task procedures (both the original and your modified version) are essentially recursive, that is, they call themselves, though not directly but through the Threads Continue/Task mechanism.  The purpose of the conditional is to stop the recursion; for sufficiently small difference values the desired sum is computed directly, otherwise the recursion continues (splitting the big task into smaller tasks). Without the conditional, in your version, the recursion never ends, tasks will be generated indefinitely.

It may very well be that the problem only occurs in Windows.  I recall having the same problem years ago, when attempting to replace an mla using Worksheet command, but that might have been on Windows (which I still use occasionally).  I just tried the following using command-line Maple on linux:

foo := () -> "foo ran":
bar := () -> "bar ran":
LibraryTools:-Save('foo','bar',"tmp.mla"):
restart:
libname := libname, ".":
foo();  # --> "foo ran"
FileTools:-Delete("tmp.mla"): # executed with no issue
foo(); # --> "foo ran"  (continues to work because already loaded from mla)
bar(); # --> bar()     (not defined because not loaded when mla was deleted)

@nm Create a user toolbox and put it there. On linux, user toolboxes go in $HOME/maple/toolbox. I have a lot of custom toolboxes, here's the layout of a typical one
 

$ tree $HOME/maple/toolbox/Find
/home/joe/maple/toolbox/Find
└── lib
    └── Find.mla

Maple will automatically add that mla to libname.

@nm Without it you could do

foo:-bar := 34:  # modify the original object class
foo1 := Object(foo):
foo1:-bar;   # --> 34

Am thinking it might be better if object exports were automatically protected, as is done with package exports (an object cannot be a package). Will mention it to the kernel guys. There are pros and cons.

@nm Hmm.  That makes me realize that my version has a similar flaw; bar is not protected in the original object class.  The solution is to put a protect statement in the class definition. You still need the protect in the ModuleCopy.  So latest is shown below.  I'll edit the answer as well, in case someone only reads it.


foo := module()
option object;
export bar;
export
    ModuleCopy :: static := proc(self :: foo
                                 , proto :: foo
                                )
        protect('self:-bar');
    end proc;

export
    set :: static := proc(self :: foo, val);
        unprotect('self:-bar');
        self:-bar := val;
        protect('self:-bar');
        val;
    end proc;

    protect('bar');  # latest change

end module:

@nm A minor problem with that approach is that p:-name is not protected until it is first assigned via set_name.  So one could directly assign to it.  That's why I put the call to protect in ModuleCopy, which ensures that it is protected when the object is instantiated.

Just make 'name' local (don't export it).

@Preben Alsholm FYI one can also do
 

subs[eval](x=0, exp(x)); # 1

@Carl Love Nice. To get either, just combine the ideas:

Foo := proc()
    thisproc("lastcalled") := foo(args);
end proc:
Foo("lastcalled") := "never called":

foo := proc(x)
option remember;
    thisproc("lastcomputed") := x;
end proc:

foo("lastcomputed") := "never called":

Foo(x):
Foo(y):
Foo(x):
Foo("lastcalled");    # --> x
foo("lastcomputed");  # --> y

@nm z^(-1) has a z in it.  Look closely 8-). 

This is similar to doing

z := x+y: 
subs(z=t, +z); # --> t 
subs(z=t, -z); # --> -x-y

It helps to realize that subs is a syntactical command, not an algebraic command.

@ns523 What, precisely, do you want to display? Show us the literal string that you want to see. For example, do you want 3030?  3030.15? 3030.1501? 3.0301501e3? Previously you complained that the result was not a whole number, which doesn't make sense.

Actually, given that the number you reported seems completely wrong, why not simply upload your worksheet.  Use the green arrow.

@ns523 What do you want to display?

@nm Carl asked what programming feature I'd like to see, so that's why I suggested object inheritance. Your suggestions are library improvements rather than programming features.  I've written several packages that use Maple objects and they could be better written if inheritance were available.

@janhardo I don't understand what you are asking. What is "this" (which you suggest has something to do with object inheritance)? 

By object inheritance I mean the ability to create a new object class from an existing one. The new class inherits the methods of the old, though it may specialize (redefine) them; it can also add new methods.

1 2 3 4 5 6 7 Last Page 1 of 182