## 400 Reputation

7 years, 241 days

## How to make (if possible) this procedure...

Maple 2024

Hello

I have the following procedure that uses the Lie Derivatives of a vector field to build a set of equations.

```LieDerList:=proc(h::symbol,f::list,vars::list)
description "This function returns the system of equations based on the Lie derivative.":
local i,n:=numelems(vars),L:=Array(0..n):
L[0]:=h:
for i from 1 to n do
L[i]:=inner(f,map((a,b) -> diff(b,a),vars,L[i-1])):
end do:
return(zip((w,v)->simplify(w-v),[seq(L)],[seq](cat(h,i),i=0..n))):
end proc:
```

Below it is an example on how to call the procedure.

I used CodeTools:-ThreadSafetyCheck to check all the procedures used within LieDerList and LieDerList itself, but nothing wrong came out. However when I try to run

`LieEq4:=Threads:-Map(w->LieDerList(x,w,[x,y,z]),models4):`

where models4 is a list of 1765 elements, maple returns "Error, (in factors) attempting to assign to `LinearAlgebra:-Modular:-Create` which is protected". If I change Threads to Grid, there is no problem at all.

What am I overlooking? Is there a method to ensure the procedure is thread-safe?

Many thanks.

PS.  I found one problem - inner, which is related to LinearAlgebra package, is not thread-safe.

## How can I efficiently remove all twins a...

Maple 2024

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.

## How can I create a well-formatted PDF wh...

Maple 2023

Hello

I need to share some results with a colleague who is not a user of Maple, and a way to do this is by using the Tabulate (plain command and not from DocumentTools) function to format them. In the worksheet, the output looks good, but when I try to print it or save it as a PDF, only a few lines are printed. It appears that Maple is not able to break the tables into multiple pages for printing.

The output is a table with 77 rows and 30 columns.

I welcome alternative solutions to the problem of displaying the results.

Many thanks

## How to efficiently implement the additio...

Maple 2023

Hello

I could not come up with a better title, so I apologize for that.  Let me explain what I am trying to implement using an example.

Consider the following list of monomials (a 3D model,  4 monomials altogether):

`model := [x^2*y*alpha[1, 11], x*z^2*alpha[2, 15], y^2*z*alpha[3, 17] + y*z*alpha[3, 8]]`

The idea is to generate the set of all models by adding a non-repetitive monomial from the following list to model.

`[alpha[i, 0], alpha[i, 1]*x, alpha[i, 2]*y, alpha[i, 3]*z, alpha[i, 4]*x^2, alpha[i, 5]*y*x, alpha[i, 6]*z*x, alpha[i, 7]*y^2, alpha[i, 8]*z*y, alpha[i, 9]*z^2, alpha[i, 10]*x^3, alpha[i, 11]*y*x^2, alpha[i, 12]*z*x^2, alpha[i, 13]*y^2*x, alpha[i, 14]*z*y*x, alpha[i, 15]*z^2*x, alpha[i, 16]*y^3, alpha[i, 17]*z*y^2, alpha[i, 18]*z^2*y, alpha[i, 19]*z^3]`

where i indicates the coordinate where the monomial will be included.  Example: if alpha[i, 2]*y is to be added to the second coordinate of model it goes as alpha[2,2]*y. Note that alpha[i, 15]*z^2*x cannot be added to coordinate 2 since it is already there.

The result will be a list of 56 models with 5 monomials.

How can I do that efficiently?

Many thanks

Ed.

PS. I have implemented something similar to the problem above, but I have used too many 'for' loops.

## How to save a long list of variables exc...

Maple 2023

Hello

In a previous question I asked "How to save all user varibles except for the procedures", now I wonder how to extend that to a procedure that saves all user variables except the user procedures and a list of unwanted variables.     The following procedure

```SaveAllVariablesExcept := proc(notsave::set, fileName :: string )
subs(_NAMES = (remove(type, {anames}(user) minus {anames}(procedure), suffixed(notsave)))[],
proc() save _NAMES, fileName end proc)()
end proc:```

does what I need in a small scale.   For instance

```SaveAllVariablesExcept({'exceptvars','jerkmodel','jerksmon','modelaux','modelname','aaa','allsys','aux','j','s','sys'},s):
```

does not save the variables listed in the first argument. All other variables, except procedures, are saved.

Suppose that instead of { 'exceptvars',...} I saved a list of variables using the command exceptvars:={anames}(user) minus {anames}(procedure) in a certain part of the worksheet and issued SaveAllVariablesExcept(exceptvars,s).  SaveAllVariablesExcept no longer works (a suffixed problem) meaning that I don't know how to build a set from {anames}(user) that has the right syntax to be accepted in SaveAllVariablesExcept.

Of course, alternative solutions are welcome but I wonder if someone out there could explain me how to build the proper exceptvars including exceptvars as well.

Many thanks.

 1 2 3 4 5 6 7 Last Page 1 of 13
﻿