Maple 2024 Questions and Posts

These are Posts and Questions associated with the product, Maple 2024

May be someone could find what causes this new internal error in Maple 2024. 

I did report it already to Maplesoft. It does not happen in Maple 2023. Attached both worksheets.

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1708 and is the same as the version installed in this computer, created 2024, March 27, 16:20 hours Pacific Time.`

integrand:=(d*x)^m/(a+b*arctanh(c*x^n))^2;

(d*x)^m/(a+b*arctanh(c*x^n))^2

int(integrand,x);

Error, (in int/gparse/gmon) too many levels of recursion

 

 

Download int_gparse_gmon_error_maple_2024_march_27_2024.mw
 

130032

interface(version);

`Standard Worksheet Interface, Maple 2023.2, Windows 10, November 24 2023 Build ID 1762575`

integrand:=(d*x)^m/(a+b*arctanh(c*x^n))^2;

(d*x)^m/(a+b*arctanh(c*x^n))^2

int(integrand,x);

2*x*(c*exp(n*ln(x))-1)*(c*exp(n*ln(x))+1)*exp(m*(ln(d)+ln(x)-((1/2)*I)*Pi*csgn(I*d*x)*(-csgn(I*d*x)+csgn(I*d))*(-csgn(I*d*x)+csgn(I*x))))/(b*c*n*exp(n*ln(x))*(-b*ln(1-c*exp(n*ln(x)))+b*ln(c*exp(n*ln(x))+1)+2*a))+int(-2*exp(m*(ln(d)+ln(x)-((1/2)*I)*Pi*csgn(I*d*x)*(-csgn(I*d*x)+csgn(I*d))*(-csgn(I*d*x)+csgn(I*x))))*(c^2*m*(exp(n*ln(x)))^2+c^2*n*(exp(n*ln(x)))^2+(exp(n*ln(x)))^2*c^2-m+n-1)/(b*c*n*exp(n*ln(x))*(-b*ln(1-c*exp(n*ln(x)))+b*ln(c*exp(n*ln(x))+1)+2*a)), x)

 

 

Download int_gparse_gmon_NO_error_maple_2023.mw

I setup my package to display the a message when it is loaded. It is quiet convienent but I don't need it all the time. Obviously I can "#" in the code to hide it premanently. I was wondering if there is away to optionally turn it off/on. Something along the lines.

with(RationalTrigonometry,false) or with(RationalTrigonometry)[false]....

Or put something in the .ini flie to set the default behaviour.

restart:with(RationalTrigonometry):
 "Default global settings:-

     GeomClr = "Blue",

      Prntmsg = true,

       Prjpsn = 3 can be set to 1,

      Normalgpt = 1 or set to 0, 

    Metric is a 3 x3 symmetric matrix defaults to the Identity 

    matrix "


 

Suppose I have, a row vector  R = [R1 , R2  , R] and a column vector C =  [C1 , C2  , C]. I need a multiplication like as follows

RC = [ R1 [C], R2[C], R3 [C]  ], so that RC will be a 3/3 matrix. 

 

Recognizing Handwritten Digits with Machine Learning

Introduction

 

Using the DeepLearning  package, this application trains a neural network to recognize the numbers in images of handwritten digits. The trained neural network is then applied to a number of test images.

 

The training and testing images are a very small subset of the MNIST database of handwritten digits; these consist of 28 x 28 pixel images of a handwritten digit, ranging from 0 to 9. A sample image for the digit zero is .

 

Ultimately, this application generates an vector of weights for each digit; think of weights as a marking grid for a multiple choice exam. When reshaped into a matrix, a weight vector for the digit 0 might look like this.

When attempting to recognize the number in an image

 

• 

If a pixel with a high intensity lands in the red area, the evidence is high that the handwritten digit is zero

• 

Conversely, if a pixel with a high intensity lands in the blue area, the evidence is low that the handwritten digit is zero

 

The DeepLearning package is a partial interface to Tensorflow, an open-source machine learning framework. To learn about the machine learning techniques used in this application, please consult these references (the next section, however, features a brief overview)

 

• 

https://www.tensorflow.org/versions/r1.1/get_started/mnist/beginners

• 

https://www.oreilly.com/learning/not-another-mnist-tutorial-with-tensorflow

Notes

 

Introduction

 

We first build a computational (or dataflow) graph. Then, we create a Tensorflow session to run the graph.

 

Tensorflow computations involve tensors; think of tensors as multidimensional arrays.

Images

 

Each 28 x 28 image is flattened into a list with 784 elements.

 

Once flattened, the training images are stored in a tensor x, with shape of [none, 784]. The first index is the number of training images ("none" means that we can use an arbitrary number of training images).

Labels

 

Each training image is associated with a label.

 

• 

Labels are a 10-element list, where each element is either 0 or 1

• 

All elements apart from one are zero

• 

The location of the non-zero element is the "value" of the image

 

So for an image that displays the digit 5, the label is [ 0,0,0,0,0,1,0,0,0,0]. This is known as a one-hot encoding.

 

All the labels are stored in a tensor y_ with a shape of [none, 10].

Training

 

The neural network is trained via multinomial logistic regression (also known as softmax).

 

Step 1

Calculate the evidence that each image is in a selected class. Do this by performing a weighted sum of the pixel intensity for the flattened image.

 

e__i = sum(`W__i,j`*x__j, j = 1 .. 784)+b__i

 

where

 

• 

Wi,j and bi are the weight and the bias for digit i and pixel j. Think of W as a matrix with 784 rows (one for each pixel) and 10 columns (one for each digit), and b is a vector with 10 columns (one for each digit)

• 

xj is the intensity of pixel j

 

Step 2

Normalize the evidence into a vector of probabilities with softmax.

 

y__i = softmax*e__i and softmax*e__i = e^x__i/(sum(e^x__j, j = 1 .. 784))

 

Step 3

For each image, calculate the cross-entropy of the vector of predicted probabilities and the actual probabilities (i.e the labels)

 

H__y_(y) = -(sum(y_[i]*log(y__i), i = 1 .. 10))

where

• 

y_ is the true distribution of probabilities (i.e. the one-hot encoded label)

• 

y is the predicted distribution of probabilities

 

The smaller the cross entropy, the better the prediction.

 

Step 4

The mean cross-entropy across all training images is then minimized to find the optimum values of W and b

Testing

 

For each test image, we will generate 10 ordered probabilities that sum to 1. The location of the highest probability is the predicted value of the digit.

Miscellaneous

 

This application consists of

 

• 

this worksheet

• 

and a very small subset of images from the MNIST handwritten digit database

 

in a single zip file. The images are stored in folders; the folders should be extracted to the location as this worksheet.

Load Packages and Define Parameters

 

restart:
with(DeepLearning):
with(DocumentTools):
with(DocumentTools:-Layout):
with(ImageTools):

LEARNING_RATE := 0.01:
TRAIN_STEPS   := 40:

 

Number of training images to load for each digit (maximum of 100)

N := 22:


Number of labels (there are 10 digits, so this is always 10)

L := 10:

 

Number of test images

T := 50:

Import Training Images and Generate Labels

 

Import the training images, where images[n] is a list containing the images for digit n.

path := "C:/Users/Wilfried/Documents/Maple/Examples/ML/":
for j from 0 to L - 1 do
    images[j] := [seq(Import(cat(path, j, "/", j, " (", i, ").PNG")), i = 1 .. N)];
end do:

Generate the labels for digit j, where label[n] is the label for image[n].

for j from 0 to L - 1 do
   labels[j] := ListTools:-Rotate~([[1,0,0,0,0,0,0,0,0,0]$N],-j)[]:
end do:

 

Display training images

Embed([seq(images[i-1], i = 1 .. L)]);

Training

 

Flatten and collect images

x_train := convert~([seq(images[i - 1][], i = 1 .. L)], list):

 

Collect labels

y_train := [seq(labels[i - 1], i = 1 .. L)]:

 

Define placeholders x  and y to feed the training images and labels into

SetEagerExecution(false):
x  := Placeholder(float[4], [none, 784]):
y_ := Placeholder(float[4], [none, L]):

Define weights and bias

W := Variable(Array(1 .. 784, 1 .. L), datatype = float[4]):
b := Variable(Array(1 .. L), datatype = float[4]):

 

Define the classifier using multinomial logistic regression

y := SoftMax(x.W + b):

 

Define the cross-entropy (i.e. the cost function)

cross_entropy := ReduceMean(-ReduceSum(y_ * log(y), reduction_indicies = [1])):

 

Get a Tensorflow session

sess := GetDefaultSession():

 

Initialize the variables

init := VariablesInitializer():
sess:-Run(init):

 

Define the optimizer to minimize the cross entropy

optimizer := Optimizer(GradientDescent(LEARNING_RATE)):
training  := optimizer:-Minimize(cross_entropy):

 

Repeat the optimizer many times

for i from 1 to TRAIN_STEPS do

   sess:-Run(training, {x in x_train, y_ in y_train}):

   if i mod 200 = 0 then
      print(cat("loss = ", sess:-Run(cross_entropy, {x in x_train, y_ in y_train})));    
   end if:

end do:

Import Test Images and Predict Numbers

 

Randomize the order of the test images.

i_rand := combinat:-randperm([seq(i, i = 1 .. 100)]);

[13, 71, 67, 52, 81, 37, 46, 6, 39, 77, 36, 21, 49, 95, 62, 26, 44, 65, 90, 72, 70, 5, 4, 54, 31, 23, 63, 18, 22, 38, 27, 53, 50, 17, 47, 51, 78, 79, 92, 20, 28, 34, 60, 80, 58, 87, 86, 93, 84, 12, 59, 98, 97, 56, 75, 10, 29, 61, 7, 66, 100, 42, 91, 43, 89, 76, 11, 74, 8, 96, 64, 94, 68, 48, 33, 24, 40, 30, 57, 73, 99, 15, 19, 1, 3, 41, 85, 83, 35, 14, 45, 2, 88, 9, 16, 32, 69, 25, 55, 82]

(6.1)


Load and flatten test images.

path:= "C:/Users/Wilfried/Documents/Maple/Examples/ML/test_images":
x_test_images := [seq(Import(cat(path,"/","test (", i, ").png")), i in i_rand[1 .. T])]:
x_train:= convert~(x_test_images, list):

 

For each test image, generate 10 probabilities that the digit is a number from 1 to 10

pred := sess:-Run(y, {x in x_train})

_rtable[36893490552617628484]

(6.2)


For each test image, find the predicted digit associated with the greatest probability

predList := seq( max[index]( pred[i, ..] ) - 1, i = 1 .. T )

9, 1, 0, 5, 3, 4, 5, 2, 8, 3, 8, 2, 5, 2, 4, 6, 8, 4, 1, 1, 1, 6, 7, 5, 7, 7, 4, 7, 7, 8, 7, 5, 5, 7, 5, 5, 3, 3, 0, 6, 7, 7, 4, 3, 4, 0, 3, 2, 3, 7

(6.3)

L := []; for i to 50 do L := [op(L), max(pred[i])] end do
:
Val:=Vector(10,0):
Val_mean:=Vector(10,0):
for k from 1 to 10 do:
  L1:=[]:
 for i from 1 to 50 do:
  if predList[i]=k-1 then L1:=[op(L1),L[i]] end if:
 end do:
 Val(k):=evalf(L1,3):
 Val_mean(k):=Statistics:-Mean(Array(L1)):
end do:

Val,Val_mean

 

Vector[column](%id = 36893490552619428548), Vector[column](%id = 36893490552619428668)

(6.4)

Consider the first test image

Embed(x_test_images[1])

The ten probabilities associated with this image are

pred[1, ..]

Vector[row](10, {(1) = 0.1176837849925505e-4, (2) = .3597199022769928, (3) = 0.8788742707110941e-3, (4) = 0.14628235250711441e-1, (5) = .16885940730571747, (6) = 0.10462711565196514e-1, (7) = 0.16997022554278374e-1, (8) = 0.5874206870794296e-1, (9) = 0.20698020234704018e-2, (10) = .3676302134990692})

(6.5)

 

Confirm that the probabilities add up to 1

add(i, i in pred[1, ..])

HFloat(1.0000000058325895)

(6.6)

 

The maximum probability occurs at this index

maxProbInd := max[index](pred[1, ..])

10

(6.7)

Hence the predicted number is

maxProbInd - 1

9

(6.8)

Embed(x_test_images[1 .. 25])

Embed(x_test_images[26 .. 50])

We now display all the predictions

T1 := Table(Row(seq(predList[k],k = 1.. 25)),Row( seq(predList[k],k = 26 .. 50 ))
          ):
InsertContent(Worksheet(T1)):

Visualize Weights


I have problmes running the file with Maple 2024. It runs fine with Maple 2020.2 (execpt the very last part, which is not essential). The problem occurs at the SoftMax command, even if I use Softmax. It seems to be a Python conersion problem in Maple 2024. Please let me know what the remidy is. You need to modify the data path because it is set to my computer.

Wilfried

Download HDR.mw

This is just cosmotics, but it looks ugly for me. For some reason Maple converts exp(2*a) to (exp(a))^2 under certain operations such as expand

expr:=exp(2*a);
expand(%);
simplify(%);
expand(%)

.

This happens in worksheet under typesetting level extends or standard.

Any specific reason why Maple likes to rewrite exp(2*a) as (exp(a))^2  and is there a way to tell it not to do that?

ps. it is little more than cosmotic actually, it affects the Latex generated

 

latex(expr)
{\mathrm e}^{2 a}


latex(expand(expr))
\left({\mathrm e}^{a}\right)^{2}

 

Maple 2024 on windows 10

Hi,

I successfully animated my trigonometric problem on the wheel. Just a few details: 1) The 'gridlines' option deactivates when using the 'tickmarks' option. 2) The animation takes time to compile. Any suggestions? Thank you for your advice on optimizing this animation

RoueAnimation.mw

Is this internal error expected? Why does it happen? Reported to Maplesoft just in case.

``

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

restart;

189352

e:= RootOf(csc(_Z));
simplify(e);

RootOf(csc(_Z))

Error, (in simplify/trig/do/1) expression independent of, _Z

e:= RootOf(csc(x));
simplify(e);

RootOf(csc(_Z))

Error, (in simplify/trig/do/1) expression independent of, _Z

 

 

Download simplify_Z_error_maple_2024_march_22_2024.mw

ps. Reported to Maplesoft just in case.

I do not like this feature at all. called Scrollable Matrices:

https://mapleprimes.com/maplesoftblog/224789-Discover-Whats-New-In-Maple-2024

Is there a way to turn it off? 

In Maple 2024 when I display a wide matrix, it no longer wraps around if the worksheet window width was smaller as it did in Maple 2023. I prefer the 2023 behavior.

A:=Matrix(3,4,{(1, 1) = (y(x) = RootOf(-Intat(1/(_a^(3/2)+1),_a = _Z+x)+x+Intat(1/
(_a^(3/2)+1),_a = 0))), (1, 2) = "explicit", (1, 3) = "", (1, 4) = false, (2, 1
) = (y(x) = -1/2+1/2*I*3^(1/2)-x), (2, 2) = "explicit", (2, 3) = "", (2, 4) = 
false, (3, 1) = (x = -2/3*ln(((y(x)+x)^(3/2))^(1/3)+1)+1/3*ln(((y(x)+x)^(3/2))^
(2/3)-((y(x)+x)^(3/2))^(1/3)+1)+2/3*3^(1/2)*arctan(1/3*(2*((y(x)+x)^(3/2))^(1/3
)-1)*3^(1/2))+1/9*3^(1/2)*Pi), (3, 2) = "implicit", (3, 3) = "", (3, 4) = true}
,datatype = anything,storage = rectangular,order = Fortran_order,shape = []);

 

Screen shot on Maple 2023

 

Screen shot on Maple 2024

I looked at Tools->options->Display and Interface but see nothing there to turn it off.

Maple 2024 on windows 10.

Windows 10 64bit

If I double click on a  file to open it from explorer  i.e. launch Maple, it is 50/50 whether Maple hangs on opening the file and I have to kill it in the Task Manager. This only happens the 1st time I try to open the file. Subsequent clicks on it will open it. If Maple is already open the problem does not happen.  The problem willl also be there after the PC is restarted. Has anyone else noticed this?

Hello,

I'm seeking an efficient solution to a particular problem. To illustrate, I'll provide a simplified example, though in practice, I'm handling lists with millions of elements.

Let's take the list, l: [1, 2, 3, 4, 5, 6, 7, 8]. Each element in this list has a corresponding twin. For instance, 1 has twins [4, 5], and 2 has twins [9, 12] (note that 12 is not in the original list, but that's not problematic). The complete list of twins is represented as t: [[4, 5], [9, 12], [6, 8], [1, 5], [1, 4], [3, 8], [13, 14, 17], [3, 6], [2, 12], [11, 12, 15]], and the twins are made available as they are needed.

The objective is to remove all twins starting from the first element of the list. Once a twin is removed, there's no need to check for twins for that particular element. For example, consider the first element, 1; the twins [4, 5] are removed, and there's no need to find the twins for those elements. The desired outcome would be the list [1, 2, 3, 7,10].

My solution utilizes a combination of a while loop and sets. However, it's painfully slow when dealing with lists larger than a few hundred thousand elements. 

Many thanks.  

I am a new Maple user. I have a system of differential equations and I want Maple to solve the system such that if one of the solutions (dependent variable) is larger than a certain value, one of the differential equation will be described in a different way. I will describe it with an example:

restart;
with(plots);
# imagine we have two differential equations:
eqn1 := diff(T(x), x) = x + T(x)/10 + q(x)/2;
eqn2 := diff(q(x), x) = T(x)^2/10 + 3*q(x);
#The solution is given by:
sol := dsolve({eqn1, eqn2, T(0) = 0, q(0) = 0}, {T(x), q(x)}, numeric, method = mebdfi);
odeplot(sol, [x, T(x)], x = 1 .. 3);

#what I want to do is to write a conditional differential equation that depends on the solution T(x) of the system. For exmaple, if the value of T(x) is larger than 4, the solver sould use a different equation to solve the system. Say for example instead of eqn1 it will use something else like: eqn1:=diff(T(x),x)=x+T(x)^2/200+q(x)/300.

#Internally after each iteration, the solver should check the value of the solution T(x), and depending on it it will choose a different differential equation to use in the next step x.

I tried defining the differential equation as piecewise but I was not successful.

Maple gives solutions that do not satisfy the equation. Wondering what do I need to change.  

restart;
n:=3;m:=2;
eqx:=x^(n/m)=a;
maple_sol:=[PDEtools:-Solve(eqx,x)]; #also tried solve()
F:=map(X->eval(eqx,X),maple_sol);
map(X->evalb(X),F);

 

I always verified in Mathematica

Any thought what is going on and what do I need to change in my Maple code to make it give the solution x=a^(2/3) only?  

It is also possible that Mathematica is the one who is skipping the two complex solutions, but then I need to verify these in Maple, and so far I can't. Only the first solution is verified by Maple.

Even simplification with assuming a>0 do not verify these two extra solution given with complex values. I also tried RealDomain package but this also had no effect. I tired assuming real also and tried simplify with symbolic option.

Anything else I should try?

Maple 2024 on windows 10

update

As I said, I tried RealDomain but with PDEtools:-Solve. With solve it works. Is this a bug? worksheet below

35788

restart;

35788

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1701. The version installed in this computer is 1693 created 2024, March 7, 17:27 hours Pacific Time, found in the directory C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib\`

restart;

35788

n:=3;m:=2;
eqx:=x^(n/m)=a;
use RealDomain in (PDEtools:-Solve(eqx,x)) end use;
F:=map(X->eval(eqx,X),[%]);
map(X->evalb(X),F);

3

2

x^(3/2) = a

x = a^(2/3), x = (1/4)*a^(2/3)*(1+I*3^(1/2))^2, x = (1/4)*a^(2/3)*(I*3^(1/2)-1)^2

[a = a, (1/16)*4^(1/2)*(a^(2/3)*(1+I*3^(1/2))^2)^(3/2) = a, (1/16)*4^(1/2)*(a^(2/3)*(I*3^(1/2)-1)^2)^(3/2) = a]

[true, false, false]

restart;

35788

n:=3;m:=2;
eqx:=x^(n/m)=a;
use RealDomain in (solve(eqx,x)) end use;
F:=map(X->eval(eqx,x=X),[%]);
map(X->evalb(X),F);

3

2

x^(3/2) = a

a^(2/3)

[a = a]

[true]

 

 

Download real_domain_solve_vs_PDEtools_Solve.mw

I have used "colour" as my spelling on optional inputs to procedures in my package.  How can I also handle the alternative spelling "color"?  
 

restart

 

coltest:=proc(c)
  if c="b" then return 1
   elif c="r" then return 2
   elif c="g" then return 3
  end if;
end proc:

 

foo:=proc(a,{colour:="b"})
local COL;
   COL:=coltest(colour);
if COL=1 then return a
  elif COL=2 then return a^2
  elif COL=3 then return a^3
  else error `wrong colour`;
end if ;
end proc:

 

foo(3,colour="r")

9

(1)

foo(2,colour="p")

Error, (in foo) wrong colour

 
 

 

Download 2024-03-21_Q_colour_or_color.mw

May be someone can come up with a way to simplify this ode solution? I used the option useInt but the solution can be written in much simpler way than Maple gives.  Below is worksheet showing Maple's 2024 solution and my hand solution.

(having trouble uploading worksheet, will try again).


 

144036

ode:=diff(y(x),x)^3=y(x)+x

(diff(y(x), x))^3 = y(x)+x

maple_sol:=dsolve(ode,useInt):
maple_sol:=Vector([maple_sol]);

Vector(3, {(1) = x-Intat(3*_a^2/(_a+1), _a = (y(x)+x)^(1/3))-_C1 = 0, (2) = x-Intat(3*_a^2/(_a+1), _a = -(1/2)*(y(x)+x)^(1/3)-((1/2)*I)*sqrt(3)*(y(x)+x)^(1/3))-_C1 = 0, (3) = x-Intat(3*_a^2/(_a+1), _a = -(1/2)*(y(x)+x)^(1/3)+((1/2)*I)*sqrt(3)*(y(x)+x)^(1/3))-_C1 = 0})

mysol1:= Intat(1/(_a^(1/3) + 1), _a = (y(x) + x))=x+_C1:
mysol2:= Intat(1/( -(-1)^(1/3)*_a^(1/3) + 1), _a = (y(x) + x))=x+_C1:
mysol3:= Intat(1/( (-1)^(2/3)*_a^(1/3) + 1), _a = (y(x) + x))=x+_C1:
mysol:=Vector([mysol1,mysol2,mysol3]);

 

Vector(3, {(1) = Intat(1/(1+_a^(1/3)), _a = y(x)+x) = x+_C1, (2) = Intat(1/(-(-1)^(1/3)*_a^(1/3)+1), _a = y(x)+x) = x+_C1, (3) = Intat(1/((-1)^(2/3)*_a^(1/3)+1), _a = y(x)+x) = x+_C1})

map(X->odetest(X,ode),mysol)

 

Vector(3, {(1) = 0, (2) = 0, (3) = 0})

 


 

Download simpler_solution.mw

I keep losing the edits I do. I post screen shot. Click submit, then find all my changes are lost. Will try one more time and give up:

This is Maple solution

This is implified version

 

Both versions are verified correct by odetest. The question is there is a way to obtain the simpler form from Maple.

 

Hi,

I need your insights on two technical questions regarding my BoxPlot:

1) How to adjust the color of the text (Title and caption)

2) How to remove only the y-axis

Thank you

S5StatBoxPlotBtest.mw

First 29 30 31 32 33 Page 31 of 33