nm

11378 Reputation

20 Badges

13 years, 43 days

MaplePrimes Activity


These are questions asked by nm

Maple uses \begin{array}...\end{array} for the latex of a Matrix, which is all good. But for an empty matrix, it does not generate the column specification c or and so the latex when compiled gives an error. Here is an example

W:=Matrix([[]]);
latex(W)

#which gives

\left[\begin{array}{}
{}
\end{array}\right]

Compare to 

W:=Matrix([[1]]);
latex(W)

#gives

\left[\begin{array}{c}
1 
\end{array}\right]

Because the c is missing in the first example, this generates an error

\documentclass[12pt]{book}
\usepackage{amsmath}

\begin{document}   
\[
\left[\begin{array}{}
{}
\end{array}\right]
\]

\end{document}
>lualatex foo.tex
This is LuaHBTeX, Version 1.13.2 (TeX Live 2021)
 restricted system commands enabled.
(./foo.tex
LaTeX2e <2021-11-15>
 L3 programming layer <2021-11-12>
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/book.cls
Document Class: book 2021/10/04 v1.4n Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/bk12.clo))
(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)
(./foo.aux) (/usr/local/texlive/2021/texmf-dist/tex/latex/base/ts1cmr.fd)
! Missing # inserted in alignment preamble.
<to be read again>
\cr
l.6 \left[\begin{array}{}

?

Adding the `c` fixes the Latex.

This came up with my code generated an empty  matrix from some computation.

May be this could be corrected for future version of Maple?

Thank you.

Maple 2021.2 on windows 10.  

When I convert Maple expression to Latex, before calling Latex, I replace some math names by strings in order to keep them as is in the generated Latex instead of using Maple own shortened name when conversion to latex().

Later on, in the Latex file, I add \DeclareMathOperator on each long name. This way the long math names remain and it is more clear.

This has been working well for years. Same code. No problems. All my Latex was generated this way.

Except just now, I hit a case where Maple's latex() gives an error when the math has WeierstrassP in it. latex() generates exception. 

I will email this also to Maplesoft. But thought to also post it here in case someone can see what the problem is.

interface(version);
Physics:-Version();

`Standard Worksheet Interface, Maple 2021.2, Windows 10, November 23 2021 Build ID 1576349`

`The "Physics Updates" version in the MapleCloud is 1165 and is the same as the version installed in this computer, created 2022, March 7, 23:42 hours Pacific Time.`

restart;

#interface(warnlevel=4);
#kernelopts('assertlevel'=2):
interface(typesetting=standard); #to prevent bug. see https://www.mapleprimes.com/questions/232450-Why-Maple-Writes-The-Equation-Like-This
 

extended

r:=11/("\\WeierstrassPPrime"(x,a,b)+"\\WeierstrassP"(x,a,b)^2)*"\\WeierstrassP"(x,a,b)*"\\WeierstrassPPrime"(x,a,b)-6/("\\WeierstrassPPrime"(x,a,b)+"\\WeierstrassP"(x,a,b)^2)*"\\WeierstrassP"(x,a,b)^2+1/2*a/("\\WeierstrassPPrime"(x,a,b)+"\\WeierstrassP"(x,a,b)^2)

11*("\WeierstrassP")(x, a, b)*("\WeierstrassPPrime")(x, a, b)/(("\WeierstrassPPrime")(x, a, b)+("\WeierstrassP")(x, a, b)^2)-6*("\WeierstrassP")(x, a, b)^2/(("\WeierstrassPPrime")(x, a, b)+("\WeierstrassP")(x, a, b)^2)+(1/2)*a/(("\WeierstrassPPrime")(x, a, b)+("\WeierstrassP")(x, a, b)^2)

latex(r)

Error, (in latex) unable to proceed; could you please report this problem at physics@maplesoft.com

interface(typesetting=extended);

standard

latex(r)

Error, (in TypeTools/nc_var_local) invalid input: member received MathematicalFunctionsNames, which is not valid for its 2nd argument, s

 

Download march_8_2021_latex.mw

I am getting an exception divide by zero using solve. The problem is that when using kernelopts('assertlevel'=2):  I am no longer able to catch the exception in a catch try.

Removing kernelopts('assertlevel'=2):  I can catch the exception.

But I need to use kernelopts('assertlevel'=2): in my program.   

Is there a way to keep kernelopts('assertlevel'=2): and still catch exception thrown by solve?

Is this a bug in solve? And why using kernelopts('assertlevel'=2): prevents catching the exception?

Using Maple 2021.2 on windows 10. Worksheet attached.

 exception generated

 

 

restart;

trial_solution_constants:=[A[1]];
eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
solve(identity(eq,x),trial_solution_constants)

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

Error, (in unknown) numeric exception: division by zero

Using assertlevel, now unable to catch exception

 

restart;

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

3

try
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
   solve(identity(eq,x),trial_solution_constants)
catch:
   print("error happend ",lastexception);
end try;
print(" I am here");

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

Error, (in unknown) assertion failed

" I am here"

Not Using assertlevel now can catch exception

 

restart;

interface(warnlevel=4);

3

try
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
   solve(identity(eq,x),trial_solution_constants)
catch:
   print("error happend ",lastexception);
end try;
print(" I am here");

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

"error happend ", unknown, "numeric exception: division by zero"

" I am here"

 

Download march_8_2021_solve.mw

 

Update Sept 7,2022

FYI, here is another internal exception generated by solve which shows only when kernelopts('assertlevel'=2): is set, and which can not be trapped using try/catch. May be this could be fixed in future version of Maple. 

Worksheet attached.


 

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1314 and is the same as the version installed in this computer, created 2022, September 2, 15:54 hours Pacific Time.`

restart;

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

3

eq:=1 = -X*(-(Y^2*exp(X*Y)*exp(X*y0)*exp(x0*Y)*exp(x0*y0)+2*exp(X*Y)*y0*exp(X*y0)*exp(x0*Y)*exp(x0*y0)*Y+exp(X*Y)*y0^2*exp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(X*y0)*exp(x0*Y)*exp(x0*y0)+2*exp(X*Y)*exp(X*y0)*x0*exp(x0*Y)*exp(x0*y0)*X+exp(X*Y)*exp(X*y0)*x0^2*exp(x0*Y)*exp(x0*y0)+2)):


try
     sol:=solve(identity(eq,X),[x0, y0]);
catch:
     print("exception");
end try;

Error, (in unknown) assertion failed

 


 

Download solve_exception.mw

 

 

 

I was wondering if it is possible to write Maple code in 2D notation inside .mpl and have it converted automatically to standard Maple 1D math.

For example, suppose I have A.mpl file with the content


#--- this is inside A.mpl file

ode:=y''(x)+y'(x)=sin(x);
ic:=y(0)=1,y'(0)=0;
dsolve([ode,ic],y(x));

Right now, reading this file in worksheet or even in document mode gives error:

        read "A.mpl"

Error, on line 1, syntax error, unexpected single forward quote:
ode:=y''(x)+y'(x)=sin(x);

But in document mode, one can type this in, and Maple will accept it. 

Since I do not use document mode and most of my code is in mpl files, I was wondering if one can write y'(x) instead of diff(y(x),x) and have maple automatically convert the code as it reads it somehow?

I find it much easier and more natural to write   y''(0)=1  than (D@@2)(y)(0)=1  for example.

I do understand the technical problems parsing this as has special meaning in Maple. But Maple does handle this input OK if typed in by hand in document 2D mode. It just needs to extend this to reading it from mpl files.

May be a future release of Maple will support this (using some switches or option when reading the file?)

I have my code in mla. Using try/catch, I am able to capture an error that happend deep in some call chain. But it is hard to know the exact location where this error happened.

I use StringTools:-FormatMessage( lastexception[2..-1] inside the catch clause to print the exception. But this only prints the message. It does not tell me exactly which line/function/module this happened.

Is there a way to display these information?  Using debugger and stoperror all did not help at all. It does not stop at the line where the error happened. not sure why. I tried it many times. may be I am not using it correctly?

Is it possible to display may be the trace of the calls inside the catch of the try? To know the actual statement that generated the error? Now each time I get an exception, I have to step into the debugger line by line until  I get to the place where the error was which is time consuming. Here is a MWE

 

restart;
A:=module()  
  local B:=module()
     export foo:=proc(n)
         1/n;
     end proc;
  end module;

  export main:=proc()
    try
       B:-foo(0);
    catch:
      print("error happened", StringTools:-FormatMessage( lastexception[2..-1] ));
    end try;
  end proc;

end module;

And now

    A:-main()

                "error happened", "numeric exception: division by zero"

I'd like to get more information than the above as I said. Line number/proc name/module name or stacktrace showing the calls made up to where the exception started (similar to output from where command in debugger).

The above was done in worksheet. My actual code in inside .mla build from lots of .mpl files.

Maple 2021.2 on windows

First 73 74 75 76 77 78 79 Last Page 75 of 200