nm

11353 Reputation

20 Badges

13 years, 9 days

MaplePrimes Activity


These are replies submitted by nm

which instead of returning current working directory, returns the directory of the file being read

I do not think there is.

I asked about this long time ago. For some reason, this basic functionality is missing in Maple. You are asking for something like this command

NotebookDirectory[];

Using that other software. Which returns the directory where the worksheet/notebook is saved.

I do not know why Maple does not such a basic command. It is very useful command to have.

@acer 

I've had this error on worksheets with no matrices or any rtable. Here is an example of worksheet A.mw I wanted to post in my last question about flushing output.

Maple Worksheet - Error
Failed to load the worksheet /maplenet/convert/a.mw .

Download A.mw

There is no matrices in it. Here is screen shot of the above worksheet.

WHat you show is not what my Maple shows. May be it is a version difference and that was a bug which is fixed now.

@Alfred_F 

How does Maple arrive at the correct result in a flash?

Doing trace on A:=int(1/(1-x*y),x=0..1) followed by trace on int(A,y=0..1) shows it was combination of lookup and something called cook pattern 1c.

For the first it says Cook LookUp Integrator:   returning answer from cook pattern 1c and the second one it said 

"LnOnly: case of integrand containing ln
LookupTable: integral found in the lookup table
Stage1: integral found in the lookup table"

 

Here is full trace

infolevel[int]:=6;
A:=int(1/(1-x*y),x=0..1)


int: Beginning integration with _EnvContinuous=_EnvContinuous, _EnvAllSolutions=_EnvAllSolutions, and _EnvCauchyPrincipalValue=_EnvCauchyPrincipalValue.
Definite Integration:   Integrating expression on x=0..1

Definite Integration:   Using the integrators [distribution, piecewise, series, o, polynomial, ln, lookup, cook, ratpoly, elliptic, elliptictrig, meijergspecial, improper, asymptotic, ftoc, ftocms, meijerg, contour]

Definite Integration:   Trying method distribution.

Definite Integration:   Trying method piecewise.

Definite Integration:   Trying method series.

Definite Integration:   Trying method o.

Definite Integration:   Trying method polynomial.

Definite Integration:   Trying method ln.

Definite Integration:   Trying method lookup.

LookUp Integrator:   unable to find the specified integral in the table

Definite Integration:   Trying method cook.

Cook LookUp Integrator:   returning answer from cook pattern 1c

Definite Integration:   Method cook succeeded.

Definite Integration:   Finished sucessfully.

                               ln(1 - y)
                        A := - ---------

                                   y    

int(A,y=0..1)

int: Beginning integration with _EnvContinuous=_EnvContinuous, _EnvAllSolutions=_EnvAllSolutions, and _EnvCauchyPrincipalValue=_EnvCauchyPrincipalValue.
Definite Integration:   Integrating expression on y=0..1

Definite Integration:   Using the integrators [distribution, piecewise, series, o, polynomial, ln, lookup, cook, ratpoly, elliptic, elliptictrig, meijergspecial, improper, asymptotic, ftoc, ftocms, meijerg, contour]

Definite Integration:   Trying method distribution.

Definite Integration:   Trying method piecewise.

Definite Integration:   Trying method series.

Definite Integration:   Trying method o.

Definite Integration:   Trying method polynomial.

Definite Integration:   Trying method ln.

Definite Integration:   Trying method lookup.

LookUp Integrator:   unable to find the specified integral in the table

Definite Integration:   Trying method cook.

Definite Integration:   Trying method ratpoly.

Definite Integration:   Trying method elliptic.

int/elliptic: trying elliptic integration
int/ellalg/elltype: Checking for an elliptic integral -ln(1-y)/y freeof(y) y
Definite Integration:   Trying method elliptictrig.

Definite Integration:   Trying method meijergspecial.

Definite Integration:   Trying method improper.

Definite Integration:   Trying method asymptotic.

Definite Integration:   Trying method ftoc.

Stage1: first-stage indefinite integration
Stage2:   second-stage indefinite integration

TransformAndApply: -> applying change of variables 1-y = y0
Stage1: first-stage indefinite integration
Stage1: first-stage indefinite integration
Stage2:   second-stage indefinite integration

LnOnly: case of integrand containing ln
int: Beginning integration with _EnvContinuous=_EnvContinuous, _EnvAllSolutions=false, and _EnvCauchyPrincipalValue=false.
Main: integrand has a bigO
int: Beginning integration with _EnvContinuous=_EnvContinuous, _EnvAllSolutions=false, and _EnvCauchyPrincipalValue=false.
Stage1: first-stage indefinite integration
MapOverSum: mapping int across terms in sum
Stage1: first-stage indefinite integration
Stage2:   second-stage indefinite integration

LnOnly: case of integrand containing ln
LookupTable: integral found in the lookup table
Stage1: integral found in the lookup table
int: Beginning integration with _EnvContinuous=_EnvContinuous, _EnvAllSolutions=false, and _EnvCauchyPrincipalValue=false.
Main: integrand is a polynomial
Definite Integration:   Method ftoc succeeded.

Definite Integration:   Finished sucessfully.


                             1   2
                             - Pi 
                             6    


 

Maple 2024.2 can do it. 

@acer  @Scot Gould  

Help for plot says only these font families are supported

I tried Helvetica and it got close to what acer had but not exact. 

plots[setoptions](font=[Helvetica,14],titlefont=[Helvetica,18]);

This is using DejaVu Serif which looks much closer to what acer had. Notice the letter "y" now looks same.  So will change to DejaVu Serif as I like it more,

plots[setoptions](font=["DejaVu Serif",14],titlefont=["DejaVu Serif",18]);

 

@acer 

But on windows, with default settings I do not get same fonts. Here is your worksheet as is (I convert it to 1D) and then also exported it to PNG and pasted the PNG below the worksheet.

The fonts do not look like the one you have. I like the ones you have. Is there a way to obtain same look as on Linux?

Download plot.mw

@acer 

Your plot fonts and axes labels look nicer than default. Do you have something in your init Maple file where you set plot options to get this effect?

Even with this setting

plots[setoptions](font=[TIMES,12], labelfont=[TIMES,16]);
plots[setoptions3d](font=[TIMES,12], labelfont=[TIMES,24]);

I do not get the same result.  I wonder what setting do you use to try?

@WD0HHU 

use  n in {$1 .. 31} like this

TypeTools[AddType]( my_type_Month, n->evalb(n::integer and n in {$1 .. 31}));

 

my_proc := proc(a::integer, b::my_type_Month) print(b); end proc:

my_proc(3,15);

15

my_proc(3,32);

Error, invalid input: my_proc expects its 2nd argument, b, to be of type my_type_Month, but received 32

Download month_type.mw

or can also write    and n>0 and n<32

@Harry Garst 

google AI review also sometimes gives wrong Maple code. I asked it

             how to find distance between two points in Maple

And it said this

But this code in Maple 2024 does not work

restart;

with(geometry);
pointA := point(2, 3);
pointB := point(5, 7);
distance := Distance(pointA, pointB);

[Apollonius, AreCollinear, AreConcurrent, AreConcyclic, AreConjugate, AreHarmonic, AreOrthogonal, AreParallel, ArePerpendicular, AreSimilar, AreTangent, CircleOfSimilitude, CrossProduct, CrossRatio, DefinedAs, Equation, EulerCircle, EulerLine, ExteriorAngle, ExternalBisector, FindAngle, GergonnePoint, GlideReflection, HorizontalCoord, HorizontalName, InteriorAngle, IsEquilateral, IsOnCircle, IsOnLine, IsRightTriangle, MajorAxis, MakeSquare, MinorAxis, NagelPoint, OnSegment, ParallelLine, PedalTriangle, PerpenBisector, PerpendicularLine, Polar, Pole, RadicalAxis, RadicalCenter, RegularPolygon, RegularStarPolygon, SensedMagnitude, SimsonLine, SpiralRotation, StretchReflection, StretchRotation, TangentLine, VerticalCoord, VerticalName, altitude, apothem, area, asymptotes, bisector, center, centroid, circle, circumcircle, conic, convexhull, coordinates, detail, diagonal, diameter, dilatation, directrix, distance, draw, dsegment, ellipse, excircle, expansion, foci, focus, form, homology, homothety, hyperbola, incircle, inradius, intersection, inversion, line, medial, median, method, midpoint, orthocenter, parabola, perimeter, point, powerpc, projection, radius, randpoint, reciprocation, reflection, rotation, segment, sides, similitude, slope, square, stretch, tangentpc, translation, triangle, vertex, vertices]

Error, (in geometry:-point) wrong type of arguments

Error, (in geometry:-point) wrong type of arguments

Error, attempting to assign to `geometry:-distance` which is protected

 

 

Download wrong_AI_code.mw

Second example

Asked google "how to generate random integer in Maple" and google AI said

 

But when running the code Maple gives

restart;

random_number := rand(1, 10);

print(random_number);

Error, invalid input: too many and/or wrong type of arguments passed to rand; first unused argument is 10

random_number

 


 

Download ex2.mw

 

 

In these two cases, the solution obtained is formal, without analysing the cases when the coefficient of a variable is zero

isn't this how CAS systems work? They give generic solution. Here is Mathematica's answer for your first examples, same as what Maple gives

 

@acer 

Thanks, I did not know I can use $define. Will try that. 

I know I can put uses toX=some_very_long_name:-toX inside a proc like you did. But as I said, this toX is used in almost every proc in every module, and I did not want to put this in each proc and in each module.

I found I can use it at the top of the module and now each proc inside the module sees this short hand.

This saved me having to type uses toX=some_very_long_name:-toX as many times as there are proc's in the module.

As to your question about why I had to change all my modules to local, well, it is because your code which collects all names inside the main module, only collects ones that are local.

My set up was this

export A := module()
 
    export A0 := module()
       ...
    end module;

    export A2 := module()
       ...
    end module;

etc...

end module
     

But the above does not work in Grid, unless I manually pass/type all the names of each module inside the top level level module and pass them to Grid using the Set command. I am not oging to type in 100 names or so each time I call Grid.

So your code you wrote to my other question automatically finds all these names, which is nice, but it only works only when I changed all exports to local, like this

export A := module() 

    local A0 := module() 
            ... 
    end module; 

     local A2 := module() 
             ... 
      end module; 

etc... 

end module

Now I can use the above with Grid. Below is work sheet to show this.
 

restart;

A := module()
    export main:=proc()
       print("i am in A:-main");
       B:-foo();
    end proc;

    export B :=module()
       export foo:=proc()
          print("in B:-foo()");
       end proc;
    end module;
end module:

kernelopts(opaquemodules=false): #see @acer code
S := subsindets({op(3,eval(A))}, `::`, (L)->convert(lhs(L),`global`)):
S := map(u->parse(cat("A:-",u)), eval(S,1));

{}

Grid:-Set(0, A:-main, op(eval(S,1)));
Grid:-Run(0, A:-main,[  ]);
Grid:-Wait();

"i am in A:-main"

Error, (in main) `%1` does not evaluate to a module

############ CHNAGE TO LOCAL, it works

restart;

 A := module()
    export main:=proc()
       print("i am in A:-main");
       B:-foo();
    end proc;

    local B :=module()
       export foo:=proc()
          print("in B:-foo()");
       end proc;
    end module;
end module:

kernelopts(opaquemodules=false): #see @acer code
S := subsindets({op(3,eval(A))}, `::`, (L)->convert(lhs(L),`global`)):
S := map(u->parse(cat("A:-",u)), eval(S,1));

{B}

Grid:-Set(0, A:-main, op(eval(S,1)));
Grid:-Run(0, A:-main,[  ]);
Grid:-Wait();

"i am in A:-main"

"in B:-foo()"

 


 

Download why_changing_to_local.mw

Too many problems to use Grid. But if this works, it is worth it, as it should be much faster than sequential.

Is there a way to fix that? 

 

try the maple export command and export to .ps, then convert .ps to pdf using ps2pdf command.

@acer 

Thanks, will try this and see if it works on my main setup.

@acer 

You are right. I had export there instead of local of the module variables. What I did only works if the variables have export on them.

I see now you used kernelopts(opaquemodules=false):  but this requires one to pass each individual variable name to be accessed if I want to keep the module variables local. I will try it and see.

First 6 7 8 9 10 11 12 Last Page 8 of 91