Ronan

1267 Reputation

14 Badges

12 years, 279 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are replies submitted by Ronan

@acer Ok that works fine and saves properly as a .mla file. So I am using it.

@Carl Love Well that proved the point.  So could I then save all procedures as *.m files and then read them all into the package? What is/would be the downside? 

@acer  As shown the other night above I converted the 2D to 1D text by saving/exporting as maple.text. Then opened that file so it is 1D. Then corrected the "translation error". The procedure(s) then works fine in the document. Then  I save them out at either .mpl or .mm and rebuild the package AlgCalc the problem still occurs in the package. So I am concluding that the 

`<|>`(cpsub~([op(f)], var)[])

is still being converted to

 <cpsub~([op(f)], var)[]>

I have tried writing a more long hand version of that line but cant get the syntax correct.

Really that is what I need to know.

@acer This line at the end of "getCP"

`<|>`(cpsub~([op(f)], var)[])

gets converted to 

 <cpsub~([op(f)], var)[]>

This produces the column Matrix instead of the two row matrix

What should I convert the 1st line too, to prevent this happening?

@Joe Riel  I translated the two procedures to 1d and used the syntax you suggested. This produces the output problem. On saving

I get this warning message

I don't know much about 1d input to find the issue.

 

elif f :: `^` then ...
    elif f :: `.` then ...

 

restart;

cpsub := proc(t, var := alpha)
 local i, cf, varpwr;
 description "used by getCP";
 if not has(t, var) then
   return <0, t>;
 elif t::`^` then
   return <op(t)[2], 1>;
 else varpwr, cf := selectremove(has, [op(t)], var);
   if op(varpwr) = var then
     return <1, `*`(op(cf))>;
   end if;
  for i to nops(varpwr) do
    if numer(varpwr[i]) = 1 then
      if op(1/varpwr[i]) = alpha then
        varpwr[i] := -1;
      else varpwr[i] := -op(1/varpwr[i])[2];
      end if;
    else varpwr[i] := op(varpwr[i])[2];
    end if;
  end do;
    return <`+`(op(varpwr)), `*`(op(cf))>;
 end if;
 end proc;

 

cpsub := proc (t, var := alpha) local i, cf, varpwr; description "used by getCP"; if not has(t, var) then return `<,>`(0, t) elif t::`^` then return `<,>`(op(t)[2], 1) else varpwr, cf := selectremove(has, [op(t)], var); if op(varpwr) = var then return `<,>`(1, `*`(op(cf))) end if; for i to nops(varpwr) do if numer(varpwr[i]) = 1 then if op(1/varpwr[i]) = alpha then varpwr[i] := -1 else varpwr[i] := -op(1/varpwr[i])[2] end if else varpwr[i] := op(varpwr[i])[2] end if end do; return `<,>`(`+`(op(varpwr)), `*`(op(cf))) end if end proc

(1)

getCP := proc(f, var := alpha)
 local t;
 description "Dissmantles a polynomial into powers and coefficients";
 if not has(f, var) then
    return <0, f>;
 elif f::`^` then
    return <op(f)[2], 1>;
 elif f::`*` then
    return <cpsub~([f], var)[]>;
 else <cpsub~([op(f)], var)[]>;
 end if;
end proc;

getCP := proc (f, var := alpha) local t; description "Dissmantles a polynomial into powers and coefficients"; if not has(f, var) then return `<,>`(0, f) elif f::`^` then return `<,>`(op(f)[2], 1) elif f::`*` then return `<,>`(`~`[cpsub]([f], var)[]) else `<,>`(`~`[cpsub]([op(f)], var)[]) end if end proc

(2)

save cpsub, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/cpsub.mm"

save getCP,"C:/Users/Ronan/Documents/maple/Alibrary/Procedures/getCP.mm"

 

f:=5+2*x-7*x^2+3*x^5

f := 3*x^5-7*x^2+2*x+5

(3)

CP:=getCP(f,x)

Vector(8, {(1) = 5, (2) = 3, (3) = 2, (4) = -7, (5) = 1, (6) = 2, (7) = 0, (8) = 5})

(4)

 

`<|>`(cpsub~([op(f(x))], x)[])

Matrix(2, 4, {(1, 1) = 5, (1, 2) = 2, (1, 3) = x[2], (1, 4) = 0, (2, 1) = 3, (2, 2) = -7, (2, 3) = 2, (2, 4) = 5})

(5)

 

Download getCP_and_cpsub_1d.mws

Attached is the zip file. I just included the two relevant procedures

AlgCals.zip

@Joe Riel  Hello. Appoligies, I had no idea you had answered this question I asked. I came across it again today on a Google search.

I tried adding another test to the package but it is not working.

Edit:- I since made that work. I then made a further modification an imported one of my own procedures "SignedArea.mpl". I dont really know how to approach getting it to work with your methodology.

Could you advise please.


restart

NULL

NULL

NULL Rtestm := module ()

NULL

NULL

NewTest:=module()

NULL

ModuleApply:=proc()

NULL Testx:=module()

NULL

NULL

ModuleApply:=proc()

 

NULL

Import("C:/users/Ronan/Documents/Maple/ALibrary/Procedures/SignedArea.mpl");

"$include "SignedArea.mpl";
SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, 
null} := null)

 local M, A; description 
"signed area of a line segment or 3 points"; if c = null then A := 1/2*a[1]*b[2
]-1/2*a[2]*b[1]; else A := 1/2*(b[2]-c[2])*a[1]+1/2*(-b[1]+c[1])*a[2]+1/2*c[2]*
b[1]-1/2*c[1]*b[2]; end if; return A; end proc;
"

NULL

with(CodeBuilder);

[Build, Directory, Export, File, Import, Mint, Read, Regions, Version]

Build(mint,maplet,prefix="#!");

Error, (in anonymous module instantiated by CodeBuilder:-Read) invalid input: too many and/or wrong type of arguments passed to CodeBuilder:-Import; first unused argument is C:/users/Ronan/Documents/Maple/ALibrary/Procedures/SignedArea.mpl

Error, (in CodeBuilder:-Read) Error: (in anonymous module instantiated by CodeBuilder:-Read) invalid input: too many and/or wrong type of arguments passed to CodeBuilder:-Import; first unused argument is C:/users/Ronan/Documents/Maple/ALibrary/Procedures/SignedArea.mpl

with(Rtestm);

[NewTest, Rtest, SignedArea, Testx]

Rtest();

"this is a test"

NewTest();

NewTest()

Testx();

Testx()

CodeBuilder:-Version

"1.0.9"

Directory()

"C:\Users\Ronan\AppData\Local\Temp\Rtestm"

LibraryTools:-FindLibrary(Rtestm)

Regions()

["Rtestm.mpl", "NewTest.mpl", "NewTest_ModuleApply.mpl", "Testx.mpl", "Testx_ModuleApply.mpl", "SignedArea.mpl"]

restart

Test3()

Test3()

NULL

 

Download Q_4-11-22_CodeBuilder_Pkg_test.mw

 

@acer Thank you. I have all three packages stored properly now. 

On a side note I had asked a question on the CodeBuilder package in 2017. Didn't know it had answered till today. And i see you had some comments to make there. It might be useful for what I wand to do. How do I use the CodeBuilder package? - MaplePrimes I have asked another question on it there.

@acer The LibraryTools make it much easier. So now before I go any futher I an sorting out my RationalTrigonometry and RonanRoutines packages. I am using the AlgCalc package to experiment with.

So I have managed to make the Ratonal trigonometry save out seperately into it's own .mla. I renamed the directsearch.mla extension to mxla to do this. I can always download direct search again.

Problems with the RonanRoutines package deciding to not evaluate to a module. Will come back to that. Though it did work the last time I modified it in september. Moved to 2022.2 at weekend??
 Now the AlgCalc package burried its self inside the CodeBuilder .mla so I deleted that whole package folder set.

The problem I am having now is the AlgCalc package not saving correctly. This document has screen shots to show what I have done.

 Yes I watched the package part of the conference. A bit too brief but I have screen shots I can go through at the weekend.

restart

Date()

_m2295771860928

dr := cat(kernelopts(homedir), "/Documents/maple/Alibrary/Procedures")

"C:\Users\Ronan/Documents/maple/Alibrary/Procedures"

SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then M := Matrix([a, b]); A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then M := Matrix([a, b]); A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

NULL

save SignedArea, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/SignedArea.mm"

NULL

NULL

`&oplus;` := proc (a, b) (a+b)/(1-a*b) end proc

proc (a, b) (a+b)/(1-b*a) end proc

NULL

save `&oplus;`, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/&oplus;.mm"

 

This Part I did in Standard Notepad

 

AlgCalc := module ()
export SignedArea,
       `&oplus;`;
 option package;

$include "SignedArea.mm"
$include "`&oplus;`.mm"

 end module;

NULL

 

restart

with(LibraryTools)

[ActivationModule, AddFromDirectory, Author, Browse, BuildFromDirectory, ConvertVersion, Create, Delete, FindLibrary, PrefixMatch, Priority, Save, ShowContents, Timestamp, UpdateFromDirectory, WriteMode]

NULL

NULL

dr := cat(kernelopts(homedir), "/Documents/maple/Alibrary/Procedures")

"C:\Users\Ronan/Documents/maple/Alibrary/Procedures"

NULL

currentdir(dr)

"C:\Users\Ronan\Documents\MAPLE\A & Q Maple primes"

currentdir()

"C:\Users\Ronan\Documents\maple\Alibrary\Procedures"

read "AlgCalc.mpl"

_m2295817165792

LibLocation := "C:/Users/Ronan/maple/toolbox/personal/AlgCalc/AlgCalc.mla"

"C:/Users/Ronan/maple/toolbox/personal/AlgCalc/AlgCalc.mla"

Save('AlgCalc', LibLocation)

NULL

 

NULL

restart

NULLLibraryTools:-FindLibrary(AlgCalc)

NULLNULL

LibraryTools:-FindLibrary(RationalTrigonometry)

"C:\Users\Ronan\maple\toolbox\personal\lib\RationalTrigonometry.mla"

with(AlgCalc)

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received AlgCalc

SignedArea([9, 1], [-5, 8], [7, 9])

SignedArea([9, 1], [-5, 8], [7, 9])

`&oplus;`(-3, 4)

`&oplus;`(-3, 4)

`&oplus;`(-3, 4)

`&oplus;`(-3, 4)

NULL

Download 4-11-22_Q_$include_Alg_Calc_Routines.mw

@acer Hello, I have managed to get some of your advice to work. So I haven't used a code editor. I codnloaded Sublime Text by didn't know what to do with it. So read through the Programming Guide Ch 11 I got something to work.

1. I had to save the procedures as *.mm files     Why is this so. *.mpl files would not work.

2. Using Notepad I made made the module/package incorporating $include

3. I saved this as an *.mpl file

4 restart and set the folder path. then read in the .mpl file

5 used savelib('AlgCalc', "AlgCalc.mla")

6 restart with(AlgCalc) both procecures in the package worked

I am having a problem saving the AlgCalc.mla to "C:UsersRonanmaple\toolboxpersonal\lib"  I found the command LibraryTools:-FindLibrary(AlgCalc)It is burried inside the CodeBuilder package. Something I downloaded about 4 years ago but never got anywhere with. Wonder if it would help now?
  My two other pagkages are also inside other packages.  
1. How do I properly save my packages to "C:UsersRonanmaple\toolboxpersonal\lib"?

2. How do I remove my packages from the other packages?

It is all shown in the attached document. 

restart

Date()

_m1493333135424

dr := cat(kernelopts(homedir), "/Documents/maple/Alibrary/Procedures")

"C:\Users\Ronan/Documents/maple/Alibrary/Procedures"

SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then M := Matrix([a, b]); A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then M := Matrix([a, b]); A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

NULL

save SignedArea, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/SignedArea.mm"

NULL

NULL

`&oplus;` := proc (a, b) (a+b)/(1-a*b) end proc

proc (a, b) (a+b)/(1-b*a) end proc

NULL

save `&oplus;`, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/&oplus;.mm"

NULL

NULL

NULL

NULL

NULL

NULL

NULL

NULL

NULL

NULL

NULL

NULL

This Part I did in Standard Notepad

 

AlgCalc := module ()
export SignedArea,
       `&oplus;`;
 option package;

$include "SignedArea.mm"
$include "`&oplus;`.mm"

 end module;

NULL

restart

dr := cat(kernelopts(homedir), "/Documents/maple/Alibrary/Procedures")

"C:\Users\Ronan/Documents/maple/Alibrary/Procedures"

NULL

currentdir(dr)

"C:\Users\Ronan\Documents\MAPLE\A & Q Maple primes"

currentdir()

"C:\Users\Ronan\Documents\maple\Alibrary\Procedures"

read "AlgCalc.mpl"

_m1493380928384

mylibdir := cat(kernelopts(homedir), kernelopts(dirsep), "maple", kernelopts(dirsep), "toolbox", kernelopts(dirsep), "personal", kernelopts(dirsep), "lib")

"C:\Users\Ronan\maple\toolbox\personal\lib"

savelib('AlgCalc', "AlgCalc.mla")

restart

LibraryTools:-FindLibrary(AlgCalc)

"C:\Users\Ronan\maple\toolbox\CodeBuilder\lib\CodeBuilder.maple"

LibraryTools:-FindLibrary(RonanRoutines)

"C:\Users\Ronan\maple\toolbox\personal\lib\DirectSearch.mla"

LibraryTools:-FindLibrary(RationalTrigonometry)

"C:\Users\Ronan\maple\toolbox\personal\lib\DirectSearch.mla"

with(AlgCalc)

[`&oplus;`, SignedArea]

SignedArea([9, 1], [-5, 8], [7, 9])

-49

`&oplus;`(-3, 4)

1/13

`&oplus;`(-3, 4)

1/13

NULL


 

Download 1-11-22_Q_$include_Alg_Calc_Routines.mw

@Deeshani   Instead of typing one very long hard to read equation into solve, break it down into smaller pieces.  Makes it much easier to debug.

for example.

a:=.....

b:=....

c:=...

eqn:= a+b+c

solve(eqn,rho[1])

 

@acer 

Ist question. Where do I put the $include directive? Is it placed in the SignedArea.mpl file, another file, the module/package? This doesnt work

$include<SignedArea.mpl>;
SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, 
null} := null) local M, A; description 
"signed area of a line segment or 3 points"; if c = null then A := 1/2*a[1]*b[2
]-1/2*a[2]*b[1]; else A := 1/2*(b[2]-c[2])*a[1]+1/2*(-b[1]+c[1])*a[2]+1/2*c[2]*
b[1]-1/2*c[1]*b[2]; end if; return A; end proc;

2nd question. Why use a code editor and which/what one? Ok, I see the nice highlighting bracket matching and line indenting.  If I write a procedure in an external code editor, I would have no idea whether it works or not. Would have to save it and then read it into Maple. Then go back around that loop getting it to work. Also a read in .mpl file seems to loose all its nice formatting.
  revision control is not really required at my home use level. Though I understand it's importance in comerical use applications.

 Would the Maple Code Edit region that can be inserted into a document suffice. Or even the start up code edit region as that make it east to load and save files?

 I realise I may have to use notepad to add the $include directive.

I am coming from a level of having no background knowledge on what you are advising me to do.
If we take the following my comments in red.
“ I'd rather write my source in plaintext files to begin with, so that I could use decent revision control, a code editor of my choice, etc. Ok I see that. I could read them into any session as I wanted What read method are you using? The start up code edit region or read “ C: …….SignedArea.mpl; while prototyping functionality. Once satisfied I could write a module (again: itself authored in a plaintext file, with $include directives I really need to see how the $include directives are actually used and pointed to where the procedure.mpl files are stored. for its member procedures) and either read that in or store it all in a .mla as in a package? archive. 

Thank you for the link to the conference I have now regestered for it.

Edit:- So $include can't be used in a Maple document. Slowely starting to see why you advocate your approach. 


 

@acer I am interested in $include usage in a package. That may solve a long term problem of storing all the procedures inside the package. Now this question from @mmcdara referencing module members within the module - MaplePrimes was linked in my email notification. I tried to copy what was done by @Joe Riel but could not get it to work. He states " To build the mla you would use a shell command". I do not know what that it or how to impliment it.
Basically I have copied an old package and cut it down to experiment with using two procedures I often use.

restart

Date()

_m2615960902368

cat(kernelopts(homedir), "/Documents/maple/Alibrary/Procedures")

"C:\Users\Ronan/Documents/maple/Alibrary/Procedures"

SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; description "signed area of a line segment or 3 points"; if c = null then A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := (1/2)*(b[2]-c[2])*a[1]+(1/2)*(-b[1]+c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

save SignedArea, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/SignedArea.mpl"

NULL

NULL

`&oplus;` := proc (a, b) (a+b)/(1-a*b) end proc

proc (a, b) (a+b)/(1-b*a) end proc

NULL

save `&oplus;`, "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/&oplus;.mpl"

NULL

NULL

NULL

NULL

NULL

NULL

restart
mylibdir := cat(kernelopts(homedir), kernelopts(dirsep), "maple", kernelopts(dirsep), "toolbox", kernelopts(dirsep), "personal", kernelopts(dirsep), "lib")

"C:\Users\Ronan\maple\toolbox\personal\lib"

NULL

libname := mylibdir, libname

"C:\Users\Ronan\maple\toolbox\personal\lib", "C:\Users\Ronan\maple\toolbox\2022\Physics Updates\lib", "C:\Program Files\Maple 2022\lib", "C:\Users\Ronan\maple\toolbox\CodeBuilder\lib", "C:\Users\Ronan\maple\toolbox\DirectSearch\lib", "C:\Users\Ronan\maple\toolbox\OEIS\lib", "C:\Users\Ronan\maple\toolbox\personal\lib", "C:\Users\Ronan\maple\toolbox\UTF8\lib"

libname

"C:\Users\Ronan\maple\toolbox\personal\lib", "C:\Users\Ronan\maple\toolbox\2022\Physics Updates\lib", "C:\Program Files\Maple 2022\lib", "C:\Users\Ronan\maple\toolbox\CodeBuilder\lib", "C:\Users\Ronan\maple\toolbox\DirectSearch\lib", "C:\Users\Ronan\maple\toolbox\OEIS\lib", "C:\Users\Ronan\maple\toolbox\personal\lib", "C:\Users\Ronan\maple\toolbox\UTF8\lib"

"AlgCalc:=module()  option  package;  export   `&oplus;`,                  SignedArea ;    local ModuleLoad ;  #` ModuleLoad := proc`()       #`end proc;`    $include  "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/SignedArea.mpl";  $include  "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/&oplus;.mpl";                     end module:"

Error, invalid `$` operator

"AlgCalc:=module() option package;  export `&oplus;`,  SignedArea ;   local ModuleLoad ;  #` ModuleLoad := proc`()       $include  "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/SignedArea.mpl";  $include  "C:/Users/Ronan/Documents/maple/Alibrary/Procedures/`&oplus;`.mpl";            end module:"

savelib('AlgCalc')

NULL

NULL

restart

with(AlgCalc)

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received AlgCalc

NULL

NULL


 

Download 29-10-22_Q_$include_Alg_Calc_Routines.mw

@acer I am away till next Thursday. I will look at your advice when I'm back.

@acer Thank you.  I am surprised I haven't been caught out by that before. For me I will use

gnrpoly:=proc(M::Matrix,var:=n)
.
.
.

return  p  

 end proc

 

First 11 12 13 14 15 16 17 Last Page 13 of 30