Joe Riel

9660 Reputation

23 Badges

20 years, 2 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Ali Hassani Here's the answer to your first question.  The Grid nodes don't automatically know the values of local assignments; you can use Grid:-Set to inform them. Note that the use of x in dummy is a bit questionable; better to make it a formal parameter.

dummy := proc(expr,num)
    coeftayl(expr,x=0,num);
end proc:

Grid:-Set('dummy'):
Grid:-Run(0,dummy,[sin(x),9]);
Grid:-GetLastResult(0);

 

@nm Consider storing your mla's in a toolbox, as I described in another thread. That eliminates much of the need to fool with libname.

@nm If you get a chance, see if you can reproduce it with a minimal code source.  If so, then upload that.

Another possibility, maybe the most likely, is that you rewrote the mla without removing the original.  That can and will cause weird problems similar to what you are seeing.  I've been bitten by it a few times and it takes a while to figure it out (the new mla mostly behaves as expected, but not quite).

As acer suggests, it is hard to debug this without seeing the code.  One possibility is that the mla you think you are using is different from what Maple is actually using.  Execute LibraryTools:-FindLibrary('bar'), where bar is the name of the module in question, to see what file Maple is using.

@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.

First 12 13 14 15 16 17 18 Last Page 14 of 195