nm

11353 Reputation

20 Badges

13 years, 19 days

MaplePrimes Activity


These are questions asked by nm

Maple mint checks for errors in one file only at a time. But not across mutliple files for correctness of calls between them. (As is done in statically complied langauges, where the compiler has access to all files and can do this).

One has to run the code to find such errors. For example, given

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2);

foo:=proc(n::integer,m::string,$)
 print("in foo, n=",n, "m = ",m );
end proc;

boo:=proc()
#How to make Maple check this call is wrong using mint? 
#before running the code? It has wrong type, and also
#missing one argument.

 foo(0.1);   
end proc;

Doing 

maplemint(boo)
maplemint(foo)

shows no errors. 

In a large program, with many calls between many procs in different packages, it will be nice if one can detect such errors before running the program if possible, than having to run the program, making sure all possible paths are taken each time.

Such an error could be hidden in the code for  sometime without one noticing it (For example, if one changes the API to a proc, but not change each call to the changed proc in order to update the call to the new API), and the code path for the now wrong call is not invoked in the current test since testing does not do 100% coverage all the time.

Is there any option in mint I might overlooked to do this?  if not, how hard would it be for Maple to add such a feature? i.e. give mint, either a set of files, or .mla library, and have it check all calls between all functions, for correctness.
 

This is an issue I had for long time. Though to ask about it.

Any one who used Database[SQLite] in Maple probably know this.  I'd like to do kernelopts('assertlevel'=2): but this does not work when using Database[SQLite] as it raises assertion failed, due to the way data is read from database and converted to Maple variable.

It happens at the statement 

         variable_to_read := Database[SQLite]:-FetchAll(stmt); 

For an example, the table I have in sql, has many fields. some are strings and some are integers. Lets say I want to read field called run_it corresponding to rowid I enter. So I do this in Maple

local run_it::integer;
.....
counter :=1;

stmt := Database[SQLite]:-Prepare(conn, cat("SELECT run_it FROM PROBLEMS WHERE rowid=",convert(counter,string),";"));    

run_it := Database[SQLite]:-FetchAll(stmt); 

The assetion error happens at the second call above. 

Error, (in dsolver_test:-MAIN_STEP) assertion failed in assignment, expected integer, got Matrix(1, 1, {(1, 1) = 1}, order = C_order, attributes = [source_rtable = (Array(1..1, {(1) = 1}, order = C_order))]) 
 

Once I remove kernelopts('assertlevel'=2): everything works fine with no problems at all. So I been running my program for more than a year now without the assert set.

Since I have hundreds of  such calls, and I do not think try/catch will work here, any one knows of a way to handle this, so I can turn on assertlevel to help catch any other problems some where else in the program, and still use SQLite ?

I could make an example if needed. I would need to create new database file and so on. This will take time.

Maple 2020.2

ps. Database[SQLite] works very well and very fast. I am surprised how fast it reads the data. few thousands records, each is 25 fields, and it does it in few seconds. Good implementation.

Edit

I found that by removing all the type specification on my Maple variables, that I read the SQL data into using FetchAll(stmt);  it now works!

So I am able to now use kernelopts('assertlevel'=2):

So intead of doing  

local local run_it::integer;  and then call SQL, I just now do  local run_it; with no type.  I had to remove the type on many such variables I had.  Now no assertion error any more during the SQL calls.

This works for me for now. I should have done this long time ago, I just did not think about it before. I would have liked to keep the type here.

Edit: I see answer below that allows me to do this by changing assert level just for the call to SQL which is good solution.

 

 

 

 

In Maple 2020.2, and after I changed to interface(warnlevel=4); then once in a while, I now see this message 

                                  Warning, persistent store makes readlib obsolete

followed by name of the file and the line number. It always happen at calls to timelimit(the_time_limit,:-dsolve(....

It seems harmless so far, as I have not seen any side effect.

 

I googled and the above, and see few places where it shows up, but no clear explanation what it is and what it means. But the messages I saw at google are a little different. They look like this

               WARNING: persistent store makes one-argument readlib obsolete

While the one I get is a little different as you can see. (no one-argument in it)

I am using my own package in .mla file during running the code if this makes any difference.

Is there any place where it explains what this means and why it happens sometimes? Sorry, can't make MWE, since it seems to happen at random. But I noticed it always happens at call to dsolve when I saw it.

Maple 2020.2

Physics 884

Windows 10
 

This seems like a serious limitation of Maple module, unless I am missing something.

I am trying to refactor one of my module, putting some code in separate .mpl file, say B.mpl,  and then do, from the main module

   $include  "B.mpl"; 

 But Maple complain now that, since B.mpl has export in it, that I can't do that. 

But the code inside B.mpl works fine if I copy it back and paste it inside the module, in the same location where the $include  "B.mpl";  is

Here is an example. (Since I can't use $include  "B.mpl";  in worksheet, Maple does not like it, I replaced it in this example by read "B.mpl";

(btw, both the syntax  module A()   and A:=module() seem to be equivalent), the problem shows up with either form)

I also tried with ";" and witout ";" at the end of the $include , it still gives same error.

 

restart;

currentdir("....."); #set directory to where the folder is


module A()

read "B.mpl";

 export foo:=proc()
  0;
 end proc;
end module;

Where the file B.mpl is

export boo:=proc()
return 0;
end proc; 

How is one supposed to refactor long file to separate files if can't leave export on those proc's?  

If I put everything in one .mpl file, it works

module A()

#read "B.mpl";  

export boo:=proc()  #this proc was in B.mpl
return 0;
end proc; 

 export foo:=proc()
  0;
 end proc;
end module;

I did more testing, and found that this seems to be an issue in Maple 2020.2. Because I just tried the same thing in Maple 2019 and it worked there ! i.e. no error.

Any one knows what is going on? 

Maple 2020.2, Physics 884.   Windows 10.

Here is screen shot. Same code. Works OK in Maple 2019.2 but gives error in 2020.2

 

 

 

I'd like to define a proc, which takes first argument to be either an ode (i.e. type `=`) or set of ode's, or list of ode's.

However, I do not know how to tell Maple that the list or set, if that is the type, to be a list of `=` and no other type.

Here is what I tried to make it more clear

If I do this

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2): 


foo:=proc(ode::{`=`, set,list},func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

Then Maple will check that the first argument is ANY one of `=`, set or list. 

But does not check if the list or set contains only equations of type `=`.  So I am able to call the above like this

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:
foo(ode1,y(x));  #this is OK
foo([ode1,a],y(x))  #this is wrong

Which is wrong, since `a` is not of type `=`.

Next I tried this (I also wanted to check that if first argument is list or set, that it is not empty, so added extra check)

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  )),
                   And(list,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  ))
                   },
                   func::`function`,$                                   
                   )

  print("ode=",ode);
  print("func=",func);
end proc;

But the above gives an error

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:

foo([ode1,a],y(x))  

I also tried

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> type(x,`=`)  )),
                   And(list,satisfies(x-> type(x,`=`) ))
                   },
                   func::`function`,$                                   
                   )

   print("ode=",ode);
   print("func=",func);

end proc;

Also gives erorr when called 

foo([ode1,ode2],y(x))

Ofcourse, I can just leave the check as in first case above, and in the proc itself, do the check myself manually by going over each entry in the list or set to make sure each entry is of type `=`. 

But I wanted Maple to do this work for me, if possible.

What is the correct syntax for doing so?

Maple 2020.2

 

First 102 103 104 105 106 107 108 Last Page 104 of 199