nm

11353 Reputation

20 Badges

13 years, 12 days

MaplePrimes Activity


These are replies submitted by nm

I can now reproduce this error in Maple 2021

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
expr:=exp(x)*sin(y)-3*x^2+(exp(x)*cos(y)+1/3/y^(2/3))*Z = 0;
solve(expr,y);
#same problem using  PDEtools:-Solve(expr,y);

Error, (in SolveTools:-CancelInverses) assertion failed, simplify should not leak _Z variables out from RootOfs

The problem is that it is not possible to even catch this exception in a try/catch block, so the whole program/script stops.

Any suggestion for a workaround? if I can catch the exception, it will OK for now until Maple fixes this.,

Removing the assert works also, but I need to keep the assert on.

@Carl Love 

I found the problem. I am still not able to make a MWE due to hard to reproduce all the call flow which leads to it in a small example, but I found how to change the ode_type module to make things now work, such that I can define local variable as   o::ode_type and also keep the assert on.

Before the ode_type module, which is an object had this definition, in file ode_type.mpl

local ode_type:=module()
    option object;
    export ode; 
    #other fields
    local ModuleLoad::static:= ()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()      

end module:

The last part of the code above is one I took from your other answer.   The above module was sitting inside my main root module, like this

A:=module()
$include  "ode_type.mpl"     #types 
#other modules
end module;

And now when I use my other functions inside A module, which uses the type ode_type and pass the Object as we talked about before, into a local variable defined as  o::ode_type I was getting the exception

Error, (in A:-dsolve) assertion failed in assignment to ode_obj, expected ode_type, got _m1657072644000 

I changed ode_type module now to the following

local ode_type:=module()
    option object;
    export ode; 
    local ModuleLoad:=proc() #it also work if I add  ::static, no difference.
           TypeTools:-AddType(':-ode_type', t->type(t,'object'));
    end proc;        
end module:

And now suddenly the exception went away. 

I am able to keep local defintion using o::ode_type and keep the kernelopts('assertlevel'=2): on and no errors and everything is working fine.

I do not know exactly why Maple was not happy with the first version. But the above does what I want for now. This might be considered a work around, and I think there is still a bug inside Maple why it does not like the first version. 

I think the problem is name scoping/name binding.  Why? Because I can use the first version above of ode_type module, if I evaluate it in the worksheet at global level, before invoking my function inside the A module. (And remove the module ode_type from inside A module since now not needed any more).

Like this

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

ode_type:=module() 
   option object; 
   export ode; 
   local ModuleLoad::static:= ()-> TypeTools:-AddType(':-ode_type', ode_type); 
   ModuleLoad() 
end module: 

read "A.mpl"; 

A:-my_proc();

The above now works, no exception raised.   Because ode_type was set in global name space before loading the A module. But ofcourse the above is not a good workaround, as I want to keep all modules inside my main A module. 

Maple 2021

@Carl Love 

You are right, I need to make an actual assignment first to make the MWE I posted work. I was trying to make the simplest example for the problem in my large code to try to find why it fails there.

This means the MWE I posted does not represent the actual problem I have in my main code. Because there I am making an assignment, else nothing would work. I run 1,000 problems tests, and all is working fine, but I had to change local ODE::ode_type;  to local ODE; to avoid the error Maple gives me. 

Error, (in my_module_name:-dsolve) assertion failed in assignment to ode_obj, expected ode_type, got _m1657072644000 

Again, everything works fine when I remove the ::ode_type from the local variable. If the Object was not allocated, nothing would have worked.  

This means I need to work harder to make new MWE which illustrates this problem. Something else is wrong, due to some modules inside others, it makes it hard to reproduce by making a simple MWE. But will try to do that later.

Right now, everything is working fine, once I remove the ::ode_type from the local variable definition and keep the assert there also.

 

 

 

@Carl Love 

As I mentioned in my edit (I seem to have updated it while you are writing?) that if I remove the local from the module definiton, the crash goes away, but the assignment error remain. My question remains the same, why?

The other proc called is returning back an object of ode_type, and the receiving variable on the caller side is defined as a local variable of type ode_type

But Maple thinks the retunring object is not of type ode_type 

And that is the question. You say you get the error message that you should get. but why?  things work for other types, like integer, string, etc.. but why not for ode_type as defined above?

 

@Joe Riel 

I do get lots of superficial warning messages printed on the screen, which I never could figure how to get rid of. I wonder then if these are the cause of the slow down?

Even if I do     read "A.mpl":   vs  read "A.mpl"; these same warning messages still display on the worksheet screen. 

There are thousands of them. They are all harmless due to how I build the Latex strings inside. They have been there for years. 

It takes about 8 minutes now to finish reading the mpl file.   My computer has very fast intel CPU with 64 GB Ram.

read "A.mpl":
Warning, incomplete string; use " to end the string
Warning, incomplete string; use " to end the string
Warning, incomplete string; use " to end the string
....
after 8 minutes and hundreds of screen pages scrolling, it finishes
....

Would you know a way to turn these off to see if this is why it is slow? I use a worksheet to read the file.

btw, same timing for building .mla file also, since to build .mla, I have to first read the .mpl file to memory.

 

Could you write the ODE using Maple 1D standard math language and not using the Maple 2D langauge? I can't fully understand what you wrote there.  Is this 4th order ode?

Also better to use "insert code snippet" option here to enter the plain text code.

And what is the sinh and cosh method?  My school teacher never mentioned such a method.  Do you have a link to such  a method?   Did you try the dsolve() command on it?

@Carl Love 

Thanks. I understand what you did. You basically created a global typename to use for the local type there.  And now I can make the Object which defines the type as local. This is all fine.

Except, I do not like that Maple forces one to make type names global. if I have many modules and submodules, and may be define other types somewhere else, it would have been better to have typename fully qualified by where it is defined. Similar to names of procs inside modules.

This helps when reading the code instead of having to search the many files to find where this type came from.  Here is what I mean

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

A:=module()

   #define local type to use in child modules
   local module person_type()
       option object;
       export name::string, age::string; 
       local ModuleLoad::static:= ()->
           TypeTools:-AddType(':-person_type', person_type);
       ModuleLoad()
    end module;

   #child module
   export module_A1:=module()
        export boo:=proc()
          local X::':-person_type':=Object(person_type);          

          #something like this below would have been better, but Maple will not allow it
          #local Y::'A:-person_type':=Object(A:-person_type); 
          return 1;
       end proc;
    end module:
   
end module:

 

i.e when adding type using TypeTools:-AddType the type name is global. I'd like to do something like ::A:-B:-type_name which tells me that the type is defined in module B which is inside module A when I look at the code. Now I have to write ::':-type_name' and I lose the information given by a fully qualified name. 

This is the same reason I prefer to write fully qualified names of functions inside packages, instead of using with(package) and just use the name of the function inside the package.

But  your solution allows me to make the module which represent the type now local, which is good.

 

@tomleslie 

    because you were incapable of formulating the question correctly

Now you are being very rude.

 

@acer 

As I mentioned, I tried to make the input a minimal to address the issue of Maple changing "0" to 0 when using Import with CSV format.

My files are very complicated and very large. So I wanted to make the example file as small as possible for the issue of conversion of string to integer, which I did.

I did not know there could be a solution given which uses a comma option to seperate the fields, which will affect how it works on other string fields when used on my actual larger files.

But thanks again for your suggestion.

 

 

 

@acer 

Thanks for the suggestion, but unfortunately ImportMatrix does not work for my data. The example input file  I showed did not include actual data from my file, since I did not know this will be an issue with the comma (did not know about the option you used to anticipate this).

The data files I have, contains strings of Latex code also as fields.

And these strings contain inside them commas. 

Import(file_name,format="CSV",output=Matrix); handles this OK. But ImportMatrix(file_name, source=delimited, delimiter=","); does not, as it will now split the Latex string apart which breaks things. Here is a better input file example

t.txt

1,2,"0",4
1,2,"1",4
1,2,"A",4
1,2,"\int \frac{(a+b x)^2 (A+B x)}{\sqrt{c+d x} \sqrt{e+f x} \sqrt{g+h x}} \, dx",4

Here is to compare

data1:=ImportMatrix(file_name, source=delimited, delimiter=",");
LinearAlgebra:-Dimension(data1);
data2:=Import(file_name,format="CSV",output=Matrix);
LinearAlgebra:-Dimension(data2);

This is the output

 

why do you care what method Maple uses to solve the PDE? 

Maple just gives final solution anyway. Not step-by-step solution. At least not for pde's.

Would you have a concrete example of an input vector field, and what is the expected output from the gradient of this field?

From what I found, the gradient of vector field is the Jacobian matrix.

https://towardsdatascience.com/step-by-step-the-math-behind-neural-networks-d002440227fb

And

https://www.quora.com/Does-gradient-of-vector-field-exist

In this case, one can use VectorCalculus:-Jacobian  and change the coordinates systems using VectorCalculus:-SetCoordinates

Here is an example

restart;
VectorCalculus:-SetCoordinates( 'cartesian'[x,y,z] );
F:=VectorCalculus:-VectorField(<3*x^2*y,2*x+y^8,z>);
VectorCalculus:-Jacobian(F,[x,y,z]);

VectorCalculus:-SetCoordinates( 'cylindrical'[rho,phi,z] );
F:=VectorCalculus:-VectorField(<3*(rho*cos(phi))^2*(rho*sin(phi)),2*(rho*cos(phi))+(rho*sin(phi))^8,z>);
VectorCalculus:-Jacobian(F,[rho,phi,z]);

VectorCalculus:-SetCoordinates( 'spherical'[rho,theta,phi] );
F:=VectorCalculus:-VectorField(<3*(rho*sin(theta)*cos(phi))^2*(rho*sin(theta)*sin(phi)),2*(rho*sin(theta)*cos(phi))+(rho*sin(theta)*sin(phi))^8,rho*cos(theta)>);
VectorCalculus:-Jacobian(F,[rho,theta,phi]);

 

If you had in mind a different definition of what gradient of vector field other than the Jacobian matrix, may be it will be useful if you could post a link to such definition and an example to make it more clear.

Maple 2021

 

@Carl Love 

Thanks for checking.

The only difference in setting, is that you had interface(prettyprint) set to 2, while my default is 3. But I change it to 2, and it made no difference.

The other non setting difference, is that I have Latest Physics package and you do not?
 

restart:
Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 972 and is the same as the version installed in this computer, created 2021, April 30, 20:23 hours Pacific Time.`

interface(version);

`Standard Worksheet Interface, Maple 2021.0, Windows 10, March 5 2021 Build ID 1523359`

interface(typesetting);

extended

interface(prettyprint);

3

latex:-Settings();

[cacheresults = true, commabetweentensorindices = false, copyaslatexinput = false, invisibletimes = " ", leavespaceafterfunctionname = false, linelength = 66, powersoftrigonometricfunctions = mixed, spaceaftersqrt = true, usecolor = true, usedisplaystyleinput = true, useimaginaryunit = I, useinputlineprompt = true, userestrictedtypesetting = false, usespecialfunctionrules = true, usetypesettingcurrentsettings = false]

sol:= u(r,t) =
    invlaplace(
        BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))*s/(s^2+1),
        s, t
     )
     - invlaplace(
           BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))/s,
           s, t
     )
     - cos(t) + 1
:
latex(sol);

u \! \left(r , t\right) =
\mathit{Typesetting}\mcoloneq \mathit{msup}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mi}\! \left(\text{``$\mathcal\{L\}$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mrow}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mo}\! \left(\text{``$-$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mn}\! \left(``1"\right)\right), \mathit{Typesetting}\mcoloneq \mathit{msemantics}=\text{``atomic"}\right)\! \left(\frac{J_{0}\! \left(10 \sqrt{-s}\, r \right) s}{J_{0}\! \left(20 \sqrt{-s}\right) \left(s^{2}+1\right)}, s , t\right)-\mathit{Typesetting}\mcoloneq \mathit{msup}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mi}\! \left(\text{``$\mathcal\{L\}$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mrow}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mo}\! \left(\text{``$-$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mn}\! \left(``1"\right)\right), \mathit{Typesetting}\mcoloneq \mathit{msemantics}=\text{``atomic"}\right)\! \left(\frac{J_{0}\! \left(10 \sqrt{-s}\, r \right)}{J_{0}\! \left(20 \sqrt{-s}\right) s}, s , t\right)-\cos \! \left(t \right)+1

interface(prettyprint=2);

3

interface(prettyprint);

2

latex(sol);

u \! \left(r , t\right) =
\mathit{Typesetting}\mcoloneq \mathit{msup}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mi}\! \left(\text{``$\mathcal\{L\}$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mrow}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mo}\! \left(\text{``$-$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mn}\! \left(``1"\right)\right), \mathit{Typesetting}\mcoloneq \mathit{msemantics}=\text{``atomic"}\right)\! \left(\frac{J_{0}\! \left(10 \sqrt{-s}\, r \right) s}{J_{0}\! \left(20 \sqrt{-s}\right) \left(s^{2}+1\right)}, s , t\right)-\mathit{Typesetting}\mcoloneq \mathit{msup}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mi}\! \left(\text{``$\mathcal\{L\}$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mrow}\! \left(\mathit{Typesetting}\mcoloneq \mathit{mo}\! \left(\text{``$-$"}\right), \mathit{Typesetting}\mcoloneq \mathit{mn}\! \left(``1"\right)\right), \mathit{Typesetting}\mcoloneq \mathit{msemantics}=\text{``atomic"}\right)\! \left(\frac{J_{0}\! \left(10 \sqrt{-s}\, r \right)}{J_{0}\! \left(20 \sqrt{-s}\right) s}, s , t\right)-\cos \! \left(t \right)+1

 


 

Download may_3.mw

@ecterrab 

THanks. I included the packages that I thought I needed. After all, I am only exporting some math and text, so I thought that is what needed is. 

\usepackage{amsmath}
\usepackage{array}
\usepackage{maple}

But now I exported the latex file itself. i.e. I typed in new worksheet the following

restart;
Student:-Calculus1:-ShowSolution(Int(x^3,x=0..1));

Then did file->export as->Latex after evaluating the above.    

Two issues:  The latex file does not compile. it gives error

>pdflatex t.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./t.tex
.............
! Undefined control sequence.
<argument> \[\begin {array}{ccc} & & \textrm {Integration Steps} \\ & & \int _{0}^{1}x^{3}dx \\ \textrm {▫} & & \textrm {1. Apply the}\boldsymbol {\textrm {power}}\textrm {rule to the term}\intx
                                                                                                                                                                                                     ^{3}dx \\ & \textrm {◦} & \textrm {Recall the defini...
l.75 \end{array}\]}

?

I am using current texlive.  

Second issue: Maple generates \usepackage{breqn}

This package breqn is known to cause massive problems as it redfined many things. I stopped using it long time ago as it could break latex compilation due to conflict with other package. There are many post about this in tex forum. It will be best if Maple latex export does not use this package at all.

Please see worksheet attached.  I wonder if the above latex file generated compiles OK for others. Here is the latex file generated by Maple. 

 

%% Created by Maple 2021.0, Windows 10
%% Source Worksheet: t
%% Generated: Sun Mar 28 15:07:48 CDT 2021
\documentclass{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{mathtools}
\usepackage{maple}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{amsmath}
\usepackage{breqn}
\usepackage{textcomp}
\begin{document}
\lstset{basicstyle=\ttfamily,breaklines=true,columns=flexible}
\pagestyle{empty}
\DefineParaStyle{Maple Bullet Item}
\DefineParaStyle{Maple Heading 1}
\DefineParaStyle{Maple Warning}
\DefineParaStyle{Maple Heading 4}
\DefineParaStyle{Maple Heading 2}
\DefineParaStyle{Maple Heading 3}
\DefineParaStyle{Maple Dash Item}
\DefineParaStyle{Maple Error}
\DefineParaStyle{Maple Title}
\DefineParaStyle{Maple Ordered List 1}
\DefineParaStyle{Maple Text Output}
\DefineParaStyle{Maple Ordered List 2}
\DefineParaStyle{Maple Ordered List 3}
\DefineParaStyle{Maple Normal}
\DefineParaStyle{Maple Ordered List 4}
\DefineParaStyle{Maple Ordered List 5}
\DefineCharStyle{Maple 2D Output}
\DefineCharStyle{Maple 2D Input}
\DefineCharStyle{Maple Maple Input}
\DefineCharStyle{Maple 2D Math}
\DefineCharStyle{Maple Hyperlink}
\begin{lstlisting}
> interface(version);
Physics:-Version();
\end{lstlisting}
% \mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{}
{\[\mathit{Standard\,Worksheet\,Interface,\,Maple\,2021.0,\,Windows\,10,\,March\,5\,2021\,Build\,ID\,1523359\,} \]}
\end{maplelatex}
% \mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{}
{\[\mathit{The\,``Physics\,Updates"\,version\,in\,the\,MapleCloud\,is\,938\,and\,is\,the\,same\,as\,the\,version\,installed\,in\,this\,computer,\,created\,2021,\,March\,27,\,12:39\,hours\,Pacific\,Time.\,} \]}
\end{maplelatex}
\begin{lstlisting}
> restart;

\end{lstlisting}
\begin{lstlisting}
> Student:-Calculus1:-ShowSolution(Int(x^3,x=0..1));
\end{lstlisting}
% \mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{}
{\[\begin{array}{ccc}
 &  & \textrm{Integration Steps} 
\\
  &  & \int_{0}^{1}x^{3}dx  
\\
 \textrm{▫} &  & \textrm{1. Apply the}\boldsymbol{\textrm{power}}\textrm{rule to the term}\intx^{3}dx  
\\
  & \textrm{◦} & \textrm{Recall the definition of the}\boldsymbol{\textrm{power}}\textrm{rule, for n}\textrm{≠}
\\
\textrm{-1} 
\\
  &  & \intx^{n}dx =\frac{x^{n +1}}{n +1} 
\\
  & \textrm{◦} & \textrm{This means:} 
\\
  &  & \intx^{3}dx =\frac{x^{3+1}}{3+1} 
\\
  & \textrm{◦} & \textrm{So,} 
\\
  &  & \intx^{3}dx =\frac{x^{4}}{4} 
\\
  & \textrm{◦} & \textrm{Apply limits of definite integral} 
\\
  &  & \frac{x^{4}}{4}{\raisebox{-0.36em}{$\Big |$}}{\mstack{}{_{x \hiderel{=}1}}}-\left(\frac{x^{4}}{4}{\raisebox{-0.36em}{$\Big |$}}{\mstack{}{_{x \hiderel{=}0}}}\right) 
\\
  &  & \textrm{We can rewrite the integral as:} 
\\
  &  & \frac{1}{4} 
\end{array}\]}
\end{maplelatex}
\begin{lstlisting}
> 
\end{lstlisting}
\begin{lstlisting}
> 
\end{lstlisting}
\end{document}

t.mw

 

@KiviKnuuti 

where when you type a bracket, it creates a grey closing bracket and the cursor stays between them.

Ok, this explains it a little more clearly.

But this is trivial to do.  I do this all the time. I always type () myself to start with, then go back to fill the stuff in between the brackets. I guess it is by habit I do this all the time.   

So what you are asking for, is for maple to automatically add   )  when you first type  ( but leaving the mouse after the first (

The difference between this and manually typing () first yourself, is that you do not need to move the mouse back to the front of the first (

I myself do not like this. I've seen it in other text editors. I turn this feature off in every editor I use which does this automatically.

Since I like to add () explicitly myself each time, I find I get   (  ))  if I keep this feature on. But this a preference ofcourse.

 

 

 

First 38 39 40 41 42 43 44 Last Page 40 of 91