Ronan

762 Reputation

14 Badges

10 years, 265 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are replies submitted by Ronan

   @Carl Love

The overloaded routine Spreadw has one procedure that is being skipped. I can't figure out why?   Section highlighted in blue.

The apparently same concept works in routine f2 highlighted in green.

Any insights here?

restart


rt:=module()
option package;
export f2,Spreadw;
local MyModule;
MyModule:= module()
uses TT= TypeTools;
global _T1, _T2L, _T2V, _T3L, _T3V, _MyType;
local 
     MyTypes:= {_T1, _T2L, _T2V, _T3L, _T3V},
     AllMyTypes:= MyTypes union {_MyType},
     ModuleLoad,
      ModuleUnload:= proc()
     local T;
          for T in AllMyTypes do if TT:-Exists(T) then TT:-RemoveType(T) end if; end do;
          return
     end proc;

     ModuleLoad:= proc()
     local
          g, #iterator over module globals
          e
     ;
          ModuleUnload();
          #op([2,6], ...) of a module is its globals.
          for g in op([2,6], thismodule) do
               e:= eval(g);
               #print("e",e);
               if g <> e and e in AllMyTypes then
                    error "The name %1 must be globally available.", g
               end if
          end do;
          TT:-AddType(_T1, algebraic);
          TT:-AddType(_T2V, 'Vector(2, algebraic)');
          TT:-AddType(_T2L, [algebraic $ 2]);
          TT:-AddType(_T3V, 'Vector(3, algebraic)');
          TT:-AddType(_T3L, [algebraic $ 3]);
          TT:-AddType(_MyType, MyTypes);
          return
     end proc;
export
     WhichMyType:= proc(X)
     local S:= select(T-> X::T, MyTypes), n:= nops(S);
         printf("%a is ", X);
         if n=0 then printf("not any of the special types.\n")
         else printf("type %a.\n", `if`(n=1, S[], Amd(S[])))
         fi
      end proc;
     
     ModuleLoad()    
     end module;
#Proceduews for export
     
    

     f2:=overload([
          proc(A::_T2L,B::_T1)
               option overload;
               local s;
               MyModule:-WhichMyType~([A,B]);
               s:=A*B^2;
          end proc,

          proc(A::_T3L,B::_T1,C::_T1,E::_T1,clr)
               option overload;
               local s,t;
               MyModule:-WhichMyType~([A,B,C,E]);
               s:=A*B^3;
               t:=2*B+sqrt(C)-sin(E);
               s-t;
          end proc,

          proc(A::_T2L)
               option overload;
               local s;
               MyModule:-WhichMyType(A);
               s:=A*6;
          end proc
     ]);

     Spreadw :=overload([
         
          # s0 from 3 Quadrances
          
          proc(p0::_T1,p1::_T1,p2::_T1)
           option overload;
               1/4*((p0 + p1 + p2)^2 - 2*p0^2 - 2*p1^2 - 2*p2^2)/(p2*p1),  "3 Quadrances";
          end proc,

          # 2 Points wrt origin
          proc(p0::_T2L,p1::_T2L,clr := GeomClr)
           option overload;
           if clr=b or clr=B or clr=blue or clr=Blue then
                1 - LinearAlgebra:-BilinearForm(p0, p1, conjugate = false)^2/(LinearAlgebra:-BilinearForm(p0, p0, conjugate = false)*LinearAlgebra:-BilinearForm(p1, p1, conjugate = false)), "2 Points Blue";
           elif clr=g or clr=G or clr=green or clr=Green then
               -1/4*(p0[1]*p1[2] - p0[2]*p1[1])^2/(p0[1]*p0[2]*p1[1]*p1[2]), "2 Points Green";
           elif clr=r or clr=R or clr=red or clr=Red then
               -(p0[1]*p1[2] - p0[2]*p1[1])^2/((p0[1]^2 - p0[2]^2)*(p1[1]^2 - p1[2]^2)), "2 Points Red";
          end if;
          end proc,

          #3 Points wrt p0 
          proc(p0::_T2L, p1::_T2L, p2::_T2L, clr:=GeomClr)
           option overload;
               local P0,P1; 
               P0 := p0 - p2; 
               P1 := p1 - p2; 
               print(P0,P1);
               if clr=b or clr=B or clr=blue or clr=Blue then
                   1 - LinearAlgebra:-BilinearForm(P0, P1, conjugate = false)^2/(LinearAlgebra:-BilinearForm(P0, P0, conjugate = false)*LinearAlgebra:-BilinearForm(P1, P1, conjugate = false)), "3 Points Blue";
                elif clr=g or clr=G or clr=green or clr=Green then
                   -1/4*(P0[1]*P1[2] - P0[2]*P1[1])^2/(P0[1]*P0[2]*P1[1]*P1[2]), "3 Points Green";
                elif clr=r or clr=R or clr=red or clr=Red then
                   -(P0[1]*P1[2] - P0[2]*P1[1])^2/((P0[1]^2 - P0[2]^2)*(P1[1]^2 - P1[2]^2)), "3 Points Red";
               end if;
               end proc,

          # 2 Vectors
          proc(p0::_T2V,p1::_T2V,clr:=GeomClr)
               if clr=b or clr=B or clr=blue or clr=Blue then
                    1 - LinearAlgebra:-BilinearForm(p0, p1, conjugate = false)^2/(LinearAlgebra:-BilinearForm(p0, p0, conjugate = false)*LinearAlgebra:-BilinearForm(p1, p1, conjugate = false)), "Vectors Blue";
               elif clr=g or clr=G or clr=green or clr=Green then
                    -1/4*(p0[1]*p1[2] - p0[2]*p1[1])^2/(p0[1]*p0[2]*p1[1]*p1[2]), "Vectors Green";
               elif clr=r or clr=R or clr=red or clr=Red then
                    -(p0[1]*p1[2] - p0[2]*p1[1])^2/((p0[1]^2 - p0[2]^2)*(p1[1]^2 - p1[2]^2)), "Vectors Red";
               end if;
          end proc

]);
end module:
#maplemint(rt)
#GeomClr:=Blue

rt:-Spreadw(1,1,1);

rt:-Spreadw([1,1],[1,0],b);
rt:-Spreadw([1,2],[1,0],r);
rt:-Spreadw([1,1],[1,2],g);


rt:-Spreadw([0,0],[1,1],[1,0],b);
rt:-Spreadw([0,0],[1,2],[1,0],r);
rt:-Spreadw([0,0],[1,1],[1,2],g);


rt:-Spreadw(<1,1>,<1,0>,b);
rt:-Spreadw(<1,2>,<1,0>,r);
rt:-Spreadw(<1,1>,<1,2>,g);
rt:-f2([2,3],5);
rt:-f2([2,3,8],19);#should produce an exception
rt:-f2([2,3,8],19,7,3,g);
rt:-f2([2,3]);

@Carl Love 

A follow up question. Why does a:: [algebraic $ 3]  not work on a procedure input usless it is added to Types?

It works for  is(a:: [algebraic $ 3])  and if.....then without having been addet to Types.

restart

 

a:=[2,5,2]

[2, 5, 2]

 
 

is(a:: [algebraic $ 3]) ;

is(a:: [algebraic $ 2])

true

FAIL

tst:=proc(A:: [algebraic $ 3])   
 local r:= "A is T3L";


   print(r);
       
end proc;

proc (A::[`$`(algebraic, 3)]) local r; r := "A is T3L"; print(r) end proc

 

tst(a)

is(a:: [algebraic $ 3]) ;

 

 

Error, invalid input: tst expects its 1st argument, A, to be of type [algebraic $ 3], but received [2, 5, 2]

 

tst1:=proc(A)   
 local r:= "A is T3L";
if   is(a:: [algebraic $ 3])then

   print(r);
end if;        
end proc;

proc (A) local r; r := "A is T3L"; if is(a::[`$`(algebraic, 3)]) then print(r) end if end proc

tst1(a)

"A is T3L"

 


 

Download Q_24-11-2022_Type_Test_on_input.mw

@Carl Love I have it working probable on a crude basis. Ichanged your MyDispatch to f1 The exports are now f1 and f2. Both run.  I have moved the code around to make things clearer.
Q1. if A :=[2,3] how do I get the procedure to detect and print that it is _T2L etc?  See f2

Edit

Q2. why does it need ? Highlighted in green.

ModuleLoad()    

     end module;

restart

 

rt:=module()
option package;
export f1,f2;
local MyModule;

MyModule:= module()
uses TT= TypeTools;
global _T1, _T2L, _T2V, _T3L, _T3V, _MyType;
local
     MyTypes:= {_T1, _T2L, _T2V, _T3L, _T3V},
     AllMyTypes:= MyTypes union {_MyType},

     ModuleLoad:= proc()
     local
          g, #iterator over module globals
          e
     ;
          #op([2,6], ...) of a module is its globals.
          for g in op([2,6], thismodule) do
               e:= eval(g);
               #print("e",e);
               if g <> e and e in AllMyTypes then
                    error "The name %1 must be globally available.", g
               end if
          end do;
          TT:-AddType(_T1, algebraic);
          TT:-AddType(_T2V, 'Vector(2, algebraic)');
          TT:-AddType(_T2L, [algebraic $ 2]);
          TT:-AddType(_T3V, 'Vector(3, algebraic)');
          TT:-AddType(_T3L, [algebraic $ 3]);
          TT:-AddType(_MyType, MyTypes)
     end proc,

     ModuleUnload:= proc()
     local T;
          for T in AllMyTypes do TT:-RemoveType(T) end do
     end proc;
      ModuleLoad()   # ???? 
      end module;



#Proceduews for export
     f1:= overload([
          proc(A::_T1, B::_T1, C::_T1)
          option overload;
          local r:= "A, B, C are T1."; #unnecessary; just an example.
               #statements to process this type
          end proc,

          proc(A::_T2L, B::_T2L, C::_T2L)
          option overload;
          local r:= "A, B, C are T2L.";
               #
          end proc,

          proc(A::_T2V, B::_T2V, C::_T2V)
          option overload;
          local r:= "A, B, C are T2V.";
               #
          end proc,

          proc(A::_T3L, B::_T3L, C::_T3L)
          option overload;
          local r:= "A, B, C are T3L.";
               #         
          end proc,

          proc(A::_T3V, B::_T3V, C::_T3V)
          option overload;
          local r:= "A, B, C are T3V.";
               #
          end proc,

          proc(A::_T2L, B::_T3L,$)
          option overload;
          local r:= "A, B, are mixed.";#I added this
               #
          end proc
     ]);

     
     f2:=overload([
          proc(A::_T2L,B::_T1)
               option overload;
               local s;
               print(AllMyTypes(A));#should be_T2L
               s:=A*B^2;
          end proc,

          proc(A::_T3L,B::_T1)
               option overload;
               local s;
               print(AllMyTypes(A));#should be_T3L
               s:=A*B^3-2*B;
          end proc
     ]);
          
end module;

#maplemint(rt);
#Example usage:
 

Warning, previous type for `_T1` has been overwritten.

Warning, previous type for `_T2V` has been overwritten.

Warning, previous type for `_T2L` has been overwritten.

Warning, previous type for `_T3V` has been overwritten.

Warning, previous type for `_T3L` has been overwritten.

Warning, previous type for `_MyType` has been overwritten.

_m2590059755904

x:=[9,4]:
y:=[5,67]:
z:=[1,2]:                                 

rt:-f1(x,y,z);
rt:-f1(2,y,s);  #should produce an exception
x:=<9,4,r>:
y:=<5,6,r>:
z:=<1,2,w>:                                 
rt:-f1(x,y,z);
x:=[9,4]:
y:=[5,6,7]:
z:=[1,2]:
rt:-f1(x,y);
rt:-f2([2,3],5);
rt:-f2([2,3,8],19);

"A, B, C are T2L."

Error, invalid input: no implementation of f1 matches the arguments in call, 'f1(2,y,s)'

"A, B, C are T3V."

"A, B, are mixed."

AllMyTypes([2, 3])

[50, 75]

AllMyTypes([2, 3, 8])

[13718, 20577, 54872]-38

Download Q_22-11-22_rev_1_Module_Test_Types_and_Exports.mw

@Carl Love 

The above works nicely. Yes I had noticed the $ as a terminator. I was already experimenting with how to use this as a package with exports. I have highlighted the code below. Exported MyModule anf f1 as a test. f1 not working

restart

 

rt:=module()
option package;
export MyModule,f1;# I don't actually want to export MyModule . Just it works for the demonstrastion of an export


MyModule:= module()
uses TT= TypeTools;
global _T1, _T2L, _T2V, _T3L, _T3V, _MyType;
local
     MyTypes:= {_T1, _T2L, _T2V, _T3L, _T3V},
     AllMyTypes:= MyTypes union {_MyType},

     ModuleLoad:= proc()
     local
          g, #iterator over module globals
          e
     ;
          #op([2,6], ...) of a module is its globals.
          for g in op([2,6], thismodule) do
               e:= eval(g);
               #print("e",e);
               if g <> e and e in AllMyTypes then
                    error "The name %1 must be globally available.", g
               end if
          end do;
          TT:-AddType(_T1, algebraic);
          TT:-AddType(_T2V, 'Vector(2, algebraic)');
          TT:-AddType(_T2L, [algebraic $ 2]);
          TT:-AddType(_T3V, 'Vector(3, algebraic)');
          TT:-AddType(_T3L, [algebraic $ 3]);
          TT:-AddType(_MyType, MyTypes)
     end proc,

     ModuleUnload:= proc()
     local T;
          for T in AllMyTypes do TT:-RemoveType(T) end do
     end proc,
#All of the MyDispatch procedures is what I would have had as one procedure of the #package
#containing a very complicated set of "if   then" statements

     MyDispatch:= overload([
          proc(A::_T1, B::_T1, C::_T1)
          option overload;
          local r:= "A, B, C are T1."; #unnecessary; just an example.
               #statements to process this type
          end proc,

          proc(A::_T2L, B::_T2L, C::_T2L)
          option overload;
          local r:= "A, B, C are T2L.";
               #
          end proc,

          proc(A::_T2V, B::_T2V, C::_T2V)
          option overload;
          local r:= "A, B, C are T2V.";
               #
          end proc,

          proc(A::_T3L, B::_T3L, C::_T3L)
          option overload;
          local r:= "A, B, C are T3L.";
               #         
          end proc,

          proc(A::_T3V, B::_T3V, C::_T3V)
          option overload;
          local r:= "A, B, C are T3V.";
               #
          end proc,

          proc(A::_T2L, B::_T3L,$)
          option overload;
          local r:= "A, B, are mixed.";#I added this
               #
          end proc

     ]),

     ModuleApply:= proc(
          #A::And(
             #  _MyType,
            #   satisfies(A-> andmap(T-> A::T implies B::T and C::T, MyTypes) )
          #),
          #B::_MyType, C::_MyType
     )
          MyDispatch(args)
     end proc
;
     ModuleLoad()    
end module;

f1:=module()
     proc(A::_T2L,B::_T1)

     option overload;
     local s;
     print(AllMyTypes(A));#should be_T2L
     s:=A*B^2;
     end proc;

     proc(A::_T3L,B::_T1)

     option overload;
     local s;
     print(AllMyTypes(A));#should be_T3L
     s:=A*B^3-2*B;
     end proc;

   end module;  

end module;

#maplemint(rt);

_m2186886803680

#Example usage:

 

x:=[9,4]:
y:=[5,67]:
z:=[1,2]:                                 

rt:-MyModule(x,y,z);
x:=<9,4,r>:
y:=<5,6,r>:
z:=<1,2,w>:                                 
rt:-MyModule(x,y,z);
x:=[9,4];
y:=[5,6,7];

rt:-MyModule(x,y);

"A, B, C are T2L."

"A, B, C are T3V."

[9, 4]

[5, 6, 7]

"A, B, are mixed."

rt:-f1([2,3],5);

 

f1([2, 3], 5)

Download Q_22-11-22_Module_Test_Types_and_Exports.mw

@zenterix I installed this last night. IMO it seems much better that jEdit Sublime and Notepad++. I interface is much more professional. Though I have'nt figured out how to launch Maple from it yet.

Some of the nice features are 

if.....then

end if 

inserts automatically. same for   For...do ...end do and other loops. Also nested parenthesis are auto coloured differently

@zenterix I am new to code editors. Had tried about 5 years ago. Sublime Text:- I had difficulty installing the Maple plugin because I didnt know what I was doing. Somehow it installed. GitHub - johnpmay/SublimeTextMaple: Sublime Text syntax and configuration files for Maplesoft's Maple language. It is straight forward to use. I saved a couple of procedures and a module/package with $include <xyadsddd.mpl> commands all as .mpl files. Then read in the module from Maple. That worked fine. I dont know anything about how to do code error checking in Sublime or it it can be done.  Don't know it Maple can be launched from it.

I found Notepad ++ easier to set up. To me it is much the same as Sublime. BTW I am on windows.

jEdit. Has native maple support. and the Project manager plugin is good. Irrating trying to download the plugins though and the mirror sites often fail.  Might be possible to launch Maple from it but I lack programming education.

That VScode for Maple looks really good. Will have to try it.

@ecterrab Is there a Komodo addon for Maple? have been investigating a few Code editors over the past week or so. Looked at Sublime text, Notepad++  and jEdit which does have a default Maple package. I so far like jEdit. I would like something that could flash up bugs in the code as it's hard to tell what is wrong when Maple reads in an *.mpl and doesn't like it.

@mmcdara @one man @dharr All good answers. You all got a vote up. The question was not the best idea at all because long equations could be returned in the actual situation. Then the message would get lost.

@Carl Love @acer Well good news. I have Sublime Text working now. Produced a few procs and a little package as a test.

Thank You. 

@Carl Love @acer I appreciate all your good advice. What has been explained here on why you use code editors makes good sense. The translation bug helped convince me of that, so I presume there would be a fair few others. I have been looking at some of the code editors.

 Eclipse looked good with the Maple IDE but that seems to have been discontinued. Saw a Youtube video on it.

Downloaded EMACS last night Way out gradient for my limited knowledge.

Sublime text might be a way forward. I will ask a programmer at work to show me how it is used. I see there is this https://github.com/johnpmay/SublimeTextMaple available. The instructions are 

Installation instructions:

  • Copy all files to Packages/User directory

    So I did this C:\Program Files\Sublime Text\Packages\Ronan          and placed the 3 files there. Not sure if that is correct though.

As of yet no idea what next to do.

Why don't Maple make the Code Editor work externally to save the text files?

@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

1 2 3 4 5 6 7 Last Page 1 of 19