nm

8552 Reputation

19 Badges

12 years, 354 days

MaplePrimes Activity


These are questions asked by nm

I noticed PDEtools:-Solve hangs sometimes on some input where solve does not. When I change the solver for PDEtools:-Solve to use solve, it did not hang.

This means PDEtools:-Solve default solver is something else. I did not see what it is by looking at help.

Here is an example

restart;
eq:=[1/3*(-334*I*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)-2*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)+56978)/(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)*v[1]-20*I*2^(1/2)*v[2] = 0, (-18000*I*2^(1/2)+33400*I-40*(1746675+72116445*2^(1/2))^(1/2)-40*(-167*I*(1746675+72116445*2^(1/2))^(1/2)+75150*2^(1/2)+10*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)+145445)/(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3))/(167*I*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)+(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)-28489)*v[2]-20*I*2^(1/2)*t = 0];

solve(eq,[v[1],v[2]]); #OK
PDEtools:-Solve(eq,[v[1],v[2]],solver=solve); #OK
PDEtools:-Solve(eq,[v[1],v[2]]); #hangs

 

Maple 2021

I am merging two separate modules  B,C to be child modules inside one main A module.

Now, I found the code breaks, because uses does not work any more.

Before merging, C module did uses B. But now this gives an error when both B,C sit inside one parent module.  An example make this easier to explain

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

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()
      uses B; #this cases problem
      export boo:=proc()
           foo();
      end proc;
   end module;
end module;

Error, (in A:-C) no bindings were specified or implied

Changing uses B; to uses A:-B; does not help. I get error Error, (in A:-C) `A` does not evaluate to a module

I also tried uses :-A:-B; , now this does not give error, but it does not work. i.e. when doing  A:-C:-boo() Maple does not end up calling foo() inside module B as expected.

One way to avoid all this, is not to use uses B inside the module and do this instead

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()      
      export boo:=proc()
           B:-foo(); 
      end proc;
   end module;
end module;

But it means I have to now change lots of code inside the C module, and add an explicit B:- everywhere

This is how it was before the merging

B:=module()
   export foo:=proc()
       print("In B:-foo()");
   end proc;
end module;

C:=module()  
  uses B;    #no problem now
  export boo:=proc()
      foo();  #this now uses B:-foo() automatically due to uses.
  end proc;
end module;

The above works. Now I can do C:-boo() and it works as expected.

The question is: How to make it work after moving both C and B inside one parent module so I do not have to change lots of code? I tried many things, but can't get it to work.

Maple 2021 on windows 10

Edit

Thanks for the answers below. I think I have to change my code then either way to add a prefix to the call. I actually always use the long form of the call for everything as in module:-function() but for one function, which I use so much everywhere, using the fully qualified name would make things hard to read.  This function converts Maple expressions to Latex after some filtering. Here is an example

cat(",toX(y),"' = f_0(",toX(f),")",toX(y),"+f_1(",toX(x),")",toX(g),"^n \\tag{2}, etc.....")

Now the function toX comes from one module, the one I had uses for it. Now I have to change the above to becomes

",module_name:-toX(f),"' = f_0(",module_name:-toX(x),")",module_name:-toX(y),"+f_1(",module_name:-toX(x),")",module_name:-toX(g),"^n \\tag{2}

Since my strings are very long as it is, (program generates Latex on the fly as it runs), this will make them even longer and harder to read.

But I can change all this in the editor, using global search and replace.

I was just hoping I do not have to just because I moved the modules all into one main module. I still do not understand why Maple does not allow uses when moving the modules inside one bigger module, but I guess this is by design.

Edit

I found the problem. Let me rephrase it. I keep original question below. 

This causes an error

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=module()
   export module_A1;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;  #THIS LINE CAUSES ERROR
          #local X::person_type;    #THIS LINE ALSO CAUSES ERROR
          #local X;                 #THIS WORKS. No error
          X:=Object(person_type);
          return X;
       end proc;
    end module:
end module:

A:-module_A1:-boo();
           Error, (in boo) module does not export `person_type`

If I change  local X::person_type;  to just local X;  then no error is generated:

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

A:=module()
   export module_A1;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X;  
          X:=Object(person_type);  #now this works
          return X;
       end proc;
    end module:

end module:

A:-module_A1:-boo();

              `Object<<person_type,1822742359104>>`

So the problem was in the variable declaration. Maple for some reason does not like   local X::A:-person_type;  and does not like local X::person_type; but things seem to work by just removing the ::type altogother. 

So this solves this problem for me for now, I can keep person module local, and still use it in other child modules. Even though I do not understand why Maple complains about it when I use ::

original question. Can be ignored now.

I have one main module, with 2 submodules (child modules) A1 and A2. The child modules are all exported so they can be called from outside the main module.

But I want to have one additional module X as object, to share among the child modules A1 and A2, but without having to also export module X.

But Maple wants me to also export module X in order to use it inside the child modules A1, and A2.

Is there a way to share X  among child modules, without exporting it? I only want X be visible to child modules (i.e. modules inside the main module)

The module X has option object and I want to use it as just a type basically (instead of using Record).

Here is an example

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=module()
   export module_A1,module_A2;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;
          X:=Object(A:-person_type);
          return 1;
       end proc;
    end module:

   module_A2:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;
          X:=Object(A:-person_type);
          return 1;
       end proc;
    end module:

end module:

Now the call A:-module_A1:-boo(); fail with Error, (in boo) module does not export `person_type`

This can be fixed by changing local person_type;  to export person_type;  but this means person_type can now be seen from outside the main package.

In Ada, it is possible to have private data type shared among child packages. How to do the same in Maple?

 

 

I have plain text files with comma delimited fields. Some fileds are strings and some are numeric.

When importing the file using

data:=Import(file_name,format="CSV",output=Matrix);

Maple changes any field which is string but contains a number inside it, as in "1"  to number 

And this causes all sorts of problems for me when processing the matrix data, since the program expects some fields to be strings. 

I looked at all options, but do not see how to tell Maple to keep a string as string, even if what is inside it is a number.

Here is an example file  "t.txt"

1,2,"0",4
1,2,"1",4
1,2,"A",4

I read it as follows

restart;
file_name:="C:/TMP/t.txt";
data:=Import(file_name,format="CSV",output=Matrix);

And Maple returns 

You see it changed "0" to 0 and "1" to 1.

This might be how CSV is supposed to work?. Does Maple have any option to override this default behavior in order to keep strings as strings, even though there is a number inside the string. I'll try to see if there is another format other than CSV to try which might behave better.

Maple 2021 on windows 10.

I could not find a function in StringTools package which removes all substrings (not single characters) from one long string directly. 

For example given a Latex string 

s:=" \\left \\int x \\,dx \\left";

And I want to remove all "\\left"  from it, which results in "  \\int x \\,dx "

In Mathematica, there is a function called StringDelete which removes all occurances of the substring in one call. Like this

s = " \\left \\int x \\,dx \\left";
StringDelete[s, "\\left"]

In Maple, I tried StringTools:-Remove(x->evalb(x="\\left"),s) and this did not work.Also tried

s:=" \\left \\int x \\,dx \\left";
StringTools:-Remove(x->StringTools:-Compare(x,"\\left"),s)

But this returned "leftintxdxleft"

And StringTools:-Delete needs a range, which one then has to first find.

I found this:

s:=" \\left \\int x \\,dx \\left";
idx:=[StringTools:-SearchAll("\\left",s)]; #returns index of first character in the string
StringTools:-Delete(s,idx[1]..idx[1]+4); #this only remove the first one. Need to loop to remove all.

Which returns the first substring. So one has to make a loop and keep removing all substrings found from the call to StringTools:-SearchAll

This is all too much work. But can be done.

The question is: What is the simplist way to remove all substrings from one string? All substrings are the same and the substrings can be more than one character.

Here is another example

s:="1234566X6Y67890A6BC66DEFGH";

And want to remove all "66" substrings, so the result will be

"12345X6Y67890A6BCDEFGH";

I am sure there must be an easier way to do this in Maple than having to call 2 or 3 functions and using a loop, but I could not find it so far. 

What would be the closest function in Maple to Mathematica's StringDelete? 

 

First 52 53 54 55 56 57 58 Last Page 54 of 164