nm

11353 Reputation

20 Badges

13 years, 9 days

MaplePrimes Activity


These are replies submitted by nm

the debugger ofcourse.

If Maple did not have a debugger, I would not even use Maple.

Even though the debugger is hard to use (line mode, no nice grapical interface like Matlab's debugger) it is for me indispensable. 

Too bad Maplesoft seems to have abandoned making any improvements to it any more.

 

Trace shows that `is/solve` fail, but could not find why.

Here is another strange result from coulditbe (cousin of is ?)

coulditbe(cos(x)=sqrt(1-sin(x)^2));

   #true

coulditbe(cos(x)=sqrt(1-sin(x)^2)) assuming x::real;

   #FAIL

@mmcdara 

I tend to use patmatch more. Main uses for me is to check if an ode has certain form to find what type it is.

I find pattern matching easier to use and more intuitive. After all, alot of math is about recognizing patterns and transformation.  But in Maple, pattern matching is somewhat more limited than it could be. But still, one can do alot with it.

@janhardo 

But the way you used `Or` is the same as using alternatives {  }

type(1+"s",`Or`(`&+`(integer,string),`&+`(string,integer) ) )

is same as

type(1+"s",{ `&+`(integer,string),`&+`(string,integer) } )

I was trying to use `Or` to tell type something like

type(1+"s", `&+`( `Or`(integer,string)))

Which ofcourse does not work. i.e. a way to avoid having to tell it the order.

So your `Or` at top level or using {} is same thing. One is forced to enumerate all possibles cases. 

With Pattern matching this is not needed.

@mmcdara 

          "stuff but it seems impossible to go further."

You could always step through the code in the debugger. You could open a text file on the side and using the debugger get the listing of each step or proc from the debugger, and stitch it into the text file you have open as you step through. Eventually, you can get all the code this way.

A := Statistics:-Sample('Beta'(3, 5), 10^5):
stopat(Statistics:-Mean);
Statistics:-Mean(A);

Here is some of the code processing the above

Statistics:-Mean:-ModuleApply:
   1*  try
       catch :
           ...
       end try

DBG> showstat

Statistics:-Mean:-ModuleApply := proc(X::{algebraic, {array, list, rtable, DataFrame, DataSeries}})
   1*! try
   2       return Quantities:-Dispatch('Statistics:-Mean',X,[NULL],_rest)
       catch :
   3       error
       end try
end proc

Statistics:-Quantities:-Dispatch := proc(qname::name, X::{algebraic, {array, list, rtable, DataFrame, DataSeries}}, parms::list)
   1 ! if type(X,'{array, list, rtable, DataFrame, DataSeries}') then
   2       return GetValueTab[':-DescriptiveStatistics'](qname,X,parms,_rest)
       else
   3       return GetValueTab[':-RandomVariables'](qname,X,parms,_rest)
       end if
end proc

Statistics:-Quantities:-Dispatch:
   2       return GetValueTab[':-DescriptiveStatistics'](qname,X,parms,_rest)

Statistics:-Quantities:-GetValueTab[DescriptiveStatistics] := proc(qname::name, X::{array, list, rtable, DataFrame, DataSeries}, parms::list, {matrixbycolumn::truefalse := true, weights::{array, list, rtable, DataFrame, DataSeries} := NULL})
local x, xx, w, ww, mbc_marker, answ;
   1   answ := Statistics:-DescriptiveStatistics:-CreateOutputRecord();
   2 ! if matrixbycolumn then
   3       mbc_marker := NULL
       else
   4       mbc_marker := 1
       end if;
   5   x, xx := PreProcessData(X,mbc_marker,':-reconstruct' = ':-summarize');
   6   if weights = NULL then
   7       Statistics:-DescriptiveStatistics:-GetValue(qname,[x, op(parms)],
             answ,_options['matrixbycolumn'],_rest)
       else
   8       w, ww := PreProcessData(weights,mbc_marker,':-reconstruct' = [':-
             summarize', xx]);
   9       Statistics:-DescriptiveStatistics:-GetValue(qname,[x, op(parms)],
             answ,_options['matrixbycolumn'],':-weights' = w,_rest)
       end if;
  10   return Statistics:-DescriptiveStatistics:-BuildOutput(answ,':-
         reconstruct' = xx)
end proc


Statistics:-Quantities:-GetValueTab[DescriptiveStatistics]:
   7       Statistics:-DescriptiveStatistics:-GetValue(qname,[x, op(parms)],
             answ,_options['matrixbycolumn'],_rest)



Statistics:-DescriptiveStatistics:-GetValue := proc(quantity::name, plist::list, answ::record, {matrixbycolumn::truefalse := true, weights::{array, list, rtable, DataFrame, DataSeries} := Vector(0)})
local columns, dtype, i, m, parms, rest, rows, weightsset, V;
   1 ! if type(weights,{array, list}) then
   2       weightsset := Vector(weights)
       else
   3       weightsset := weights
       end if;
   4   if type(plist[1],':-list'(':-Vector')) then
   5       parms := plist
       elif type(plist[1],{'array', 'list'}) then
   6       parms := subsop(1 = Array(plist[1]),plist)
       elif type(plist[1],':-rtable') and rtable_num_dims(plist[1]) = 2
         and matrixbycolumn then
   7       m := plist[1];
   8       rows := upperbound(m,1)-lowerbound(m,1)+1;
   9       columns := upperbound(m,2)-lowerbound(m,2)+1;
  10       rest := op(2 .. (NULL),plist), _rest, ':-weights' = weightsset;
  11       if convert(quantity,':-`global`') = ':-Mode' then
  12           dtype := NULL
           else
  13           dtype := ':-datatype = :-float'
           end if;
  14       answ:-value := Vector[':-row'](columns,dtype);
  15       if [rtable_options(m,':-storage',':-order')] = [':-rectangular
             ', ':-Fortran_order'] then
  16           for i to columns do
  17               V := ArrayTools:-Alias(m,(i-1)*rows,[rows]);
  18               answ:-value[i] := GetValueWorker(quantity,V,rest)
               end do
           else
  19           for i to columns do
  20               V := m[(NULL) .. (NULL),i-lowerbound(m,2)+1];
  21               answ:-value[i] := GetValueWorker(quantity,V,rest)
               end do
           end if;
  22       return
       else
  23       parms := plist
       end if;
  24   answ:-value := GetValueWorker(quantity,op(parms),_rest,':-weights' = 
         weightsset)
end proc

And so on...

It seems Statistics:-Mean is routed via some dispatch mechanism called Quantities:-Dispatch to the actual code of the implementation. Hard to see how to access and see that dispatch code.

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

restart

showstat(Statistics:-Mean);


Statistics:-Mean := proc(X::{algebraic, {array, list, rtable, DataFrame, DataSeries}})
   1   try
   2       return Quantities:-Dispatch('Statistics:-Mean',X,[NULL],_rest)
       catch :
   3       error
       end try
end proc
 

 

print(Statistics)

module Statistics () description "a package for mathematical statistics and data analysis"; local DataManipulation, DataSmoothing, DescriptiveStatistics, Distributions, Estimation, Quantities, RandomVariables, Regression, Simulation, SummaryAndTabulation, Tests, Visualization, ExciseRepPts, ExciseRangeSearch, ExternalSupport, ParseRelative, PostProcessData, PreProcessData, ProcessDistribution, RealIntervals, Summarize, Warnings, Initialize, Terminate, PrintInfo, PrintRegressionInfo, CentralMomentDimensions, SplitDataPerm, AverageLeastSquares, doPredictiveLeastSquares; export _pexports, Distribution, RandomVariable, Specialize, MakeProcedure, AbsoluteDeviation, Bootstrap, CentralMoment, Cumulant, Decile, ExpectedValue, GeometricMean, HarmonicMean, HodgesLehmann, InterquartileRange, Kurtosis, Mean, MeanDeviation, Median, MedianDeviation, Mode, Moment, OrderStatistic, QuadraticMean, Percentile, Quantile, Quartile, RousseeuwCrouxQn, RousseeuwCrouxSn, Skewness, StandardDeviation, StandardError, StandardizedMoment, Variance, Variation, CDF, CGF, CharacteristicFunction, CumulantGeneratingFunction, CumulativeDistributionFunction, DiscreteValueMap, FailureRate, HazardRate, InverseSurvivalFunction, MillsRatio, MGF, MomentGeneratingFunction, PDF, Probability, ProbabilityDensityFunction, ProbabilityFunction, Support, SurvivalFunction, Correlation, CorrelationMatrix, Covariance, CovarianceMatrix, PCA, PrincipalComponentAnalysis, AutoCorrelation, CrossCorrelation, EvaluateToFloat, Count, CountMissing, CumulativeProduct, CumulativeSum, Detrend, Difference, Excise, Join, OrderByRank, Rank, Remove, RemoveInRange, RemoveNonNumeric, Scale, Select, SelectInRange, SelectNonNumeric, Shuffle, Sort, SplitByColumn, Tally, TallyInto, Trim, Winsorize, ExponentialSmoothing, KernelDensity, LinearFilter, MovingAverage, MovingMedian, MovingStatistic, WeightedMovingAverage, Range, TrimmedMean, WinsorizedMean, DataSummary, FivePointSummary, FrequencyTable, FisherInformation, Information, Likelihood, LikelihoodRatioStatistic, LogLikelihood, MaximumLikelihoodEstimate, MLE, Score, KernelDensitySample, Sample, InteractiveDataAnalysis, Fit, NonlinearFit, LinearFit, PolynomialFit, ExponentialFit, LeastTrimmedSquares, LogarithmicFit, Lowess, PowerFit, OneWayANOVA, PredictiveLeastSquares, RepeatedMedianEstimator, OneSampleZTest, OneSampleTTest, OneSampleChiSquareTest, TwoSampleZTest, TwoSampleTTest, TwoSamplePairedTTest, TwoSampleFTest, ShapiroWilkWTest, ChiSquareIndependenceTest, ChiSquareGoodnessOfFitTest, ChiSquareSuitableModelTest, AgglomeratedPlot, AreaChart, AutoCorrelationPlot, BarChart, Biplot, BoxPlot, BubblePlot, ColumnGraph, Correlogram, CumulativeSumChart, DensityPlot, ErrorPlot, FrequencyPlot, HeatMap, GridPlot, Histogram, KernelDensityPlot, LineChart, NormalPlot, ParetoChart, PieChart, PointPlot, ProbabilityPlot, ProfileLikelihood, ProfileLogLikelihood, RadarChart, QuantilePlot, ScatterPlot, ScatterPlot3D, ScreePlot, SunflowerPlot, SurfacePlot, SymmetryPlot, TreeMap, VennDiagram, ViolinPlot, WeibullPlot, FiniteNumericSupport, ListKnownDistributions, TaskTemplates; option package, load = Initialize, unload = Terminate, `Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2005`; end module

 

 

Download mean_print.mw

You can not integrate    z(x)*y'(x)  or z(x)*y''(x) if z(x) is not known.

How would you do this by hand? Even if you use integration by parts, since z'(x) is not known.

If you know what z(x) is, then it should be possible.

integrand:=diff(y(x),x$2)

diff(diff(y(x), x), x)

int(integrand,x)

diff(y(x), x)

integrand:=z(x)*diff(y(x),x$2);

z(x)*(diff(diff(y(x), x), x))

int(integrand,x)

int(z(x)*(diff(diff(y(x), x), x)), x)

IntegrationTools:-Parts(Int(integrand,x),z(x),diff(y(x),x$2))

z(x)*(diff(diff(y(x), x), x))-(Int((diff(z(x), x))*(diff(diff(y(x), x), x)), x))

 

 

Download int_feb_4_2025.mw

Your 2D code does not seem to be valid Maple code.

I convert it to 1D input and this is what Maple gave me

0 < solve(%, Cv)*Assuming*d, 0 < Am, 0 < R0er, 0 < Clm, 0 < s1, 0 < Ce, 0 < s2, 0 < Clr, 0 < l, 0 < g1, 0 < g2, 0 < Aer, 0 < Rer;

This is your last line

First of all, it is assuming and not Assuming. You also have multiplication signs in wrong places.

Use 1D Maple language instead of the 2D one.

Did not look at your work, but try moving eveything to one side first and then call simplify. Like this

restart;

eq:=x+y*d+h*x=g*f+h*x;

d*y+h*x+x = f*g+h*x

simplify(eq);

d*y+h*x+x = f*g+h*x

simplify((lhs-rhs)(eq)=0)

d*y-f*g+x = 0

Download one_side.mw

@salim-barzani 

 

               i didn't delete it i don't know why they do that

Maybe then forum manager deleted it. Any way, here is my answer I was going to post. I was going to delete the worksheet. I do not if this is what you wanted. I assumed you wanted each b[i,j] be replaced by (k[i] - k[j] + (k[i] - k[j])^2)/(k[i] - k[j])
 

restart;

 

f := 1 + exp(eta[1]) + b[1, 2]*exp(eta[1] + eta[2]) + exp(eta[2]) + b[2, 3]*exp(eta[2] + eta[3]) + b[1, 2]*b[1, 3]*b[2, 3]*exp(eta[1] + eta[2] + eta[3]) + b[1, 3]*exp(eta[1] + eta[3]) + exp(eta[3])

1+exp(eta[1])+b[1, 2]*exp(eta[1]+eta[2])+exp(eta[2])+b[2, 3]*exp(eta[2]+eta[3])+b[1, 2]*b[1, 3]*b[2, 3]*exp(eta[1]+eta[2]+eta[3])+b[1, 3]*exp(eta[1]+eta[3])+exp(eta[3])

C :=(i,j)->(k[i] - k[j] + (k[i] - k[j])^2)/(k[i] - k[j])

proc (i, j) options operator, arrow; (k[i]-k[j]+(k[i]-k[j])^2)/(k[i]-k[j]) end proc

fix:=proc(F)
   local i,j;
   i:=op(1,F); j:=op(2,F);
   if i<j then
      C(i,j);
   else
      F;
   fi;
end proc:

evalindets(f,b[anything,anything],F->fix(F));

1+exp(eta[1])+(k[1]-k[2]+(k[1]-k[2])^2)*exp(eta[1]+eta[2])/(k[1]-k[2])+exp(eta[2])+(k[2]-k[3]+(k[2]-k[3])^2)*exp(eta[2]+eta[3])/(k[2]-k[3])+(k[1]-k[2]+(k[1]-k[2])^2)*(k[1]-k[3]+(k[1]-k[3])^2)*(k[2]-k[3]+(k[2]-k[3])^2)*exp(eta[1]+eta[2]+eta[3])/((k[1]-k[2])*(k[1]-k[3])*(k[2]-k[3]))+(k[1]-k[3]+(k[1]-k[3])^2)*exp(eta[1]+eta[3])/(k[1]-k[3])+exp(eta[3])

simplify(%);

(k[2]-k[3]+1)*(k[1]-k[3]+1)*(k[1]-k[2]+1)*exp(eta[1]+eta[2]+eta[3])+(k[1]-k[2]+1)*exp(eta[1]+eta[2])+(k[1]-k[3]+1)*exp(eta[1]+eta[3])+(k[2]-k[3]+1)*exp(eta[2]+eta[3])+exp(eta[1])+exp(eta[2])+exp(eta[3])+1

 


 

Download fix_b.mw

 

@salim-barzani 

Why your questions gets deleted after posting? You posted this question not long ago and I was about to give you an answer but it is gone. Do you delete them or the forum manager deletes them? It seems it was a good question.

 

 

@mmcdara 

Sure. After the fact, it seems to make sense that Set() should be used only after Setup().

But one would think help will say that. Looking at the help page for Set() there is no mention at all of this.

It will also be nice if calling Set() before calling Setup() would issue a warning to the user to alert them. This would have saved me 2 days of work trying to find what is wrong and why I was not seeing output on the screen.

A simple warning message is all what was needed.

If I was the programmer who wrote Grid, that is what I would have done. I am sure inside the Grid package, it knows if Setup() was called or not before. A simple flag internal and private to the package would do the job.

#somewhere inside Grid package

....
local SETUP_WAS_CALLED::truefalse:=false: #this flag will be set to true by Setup()
.....
export Set:=proc(....)

      if  not SETUP_WAS_CALLED then
           print("WARNING: You are calling Set() before Setup().");
     fi;
....
end proc;

Update 1/29/2025

An important note for those who might read this later:  Set() works if no Setup() is called after it. i.e. using the default numnodes, which for my pc is

Grid:-NumNodes()

           24

Set() does not work if called before doing explicit Setup("local",numnodes=24).  So to be safe, do not call Setup() at all, unless you want for some reason to change numnodes from default value.

So in summary

# OK
Set(....)   


#BAD
Set(...)
Setup(....)   

#OK
Setup(....)   
Set(...)

Using Maple 2024.2 on windows. The above could change in future versions of Maple.

 

 

 

@mmcdara 

Thanks. You did not say why yours worked and mine did not.

I guess you wanted one to find out, right?. But I did :)

The trick is to write

Grid:-Setup("local",numnodes=3);
Grid:-Set(foo):

Instead of what I was doing, which is

Grid:-Set(foo):
Grid:-Setup("local",numnodes=3);

When writing Grid:-Set(foo): after Grid:-Setup("local",numnodes=3); files are created OK now.

Did you find this by trial and error? Or was it by accident? Is this documented anywhere? Or do you think this is a bug I should report it?

Why does the order makes difference?

Btw, I tried your trick on the print() issue I have not showing,

Why-Calling-Proc-Via-Grid-Do-Not-Print-On-Screen

and this also fixed it !

So you hit two birds with one stone. All what is needed is doing Grid:-Set() after Grid:-Setup("local",numnodes=...); May be you can add this as answer to the print() question I have, saying to change the order of Set and Setup and I will be happy to accept it.

I'll add this to my cheat sheet. 

@mmcdara 

I also could not make printer option work with numnodes set.

It works if there is no numnodes option. But once this option is there, it no longer works.

An example in help page would be nice to show how this option can be used. But Maple help is horrible to say the least. Sorry, but it is true.

Very little examples to illustrate things for users.

And what does "line of output available" actually mean in the following? Available how? Available to whom? 

The printer procedure will be called with a string every time there is a line of output available from an external computation.

Instead of saying things in mystery like the above, why not just show an example??

Here is my attempt.
 

restart;

foo:=proc(n)
   local OUTPUT_STRING;

   OUTPUT_STRING:=cat("Entered foo, n=",n);

   print(OUTPUT_STRING);

   OUTPUT_STRING:=cat("leaving foo, n=",n);
   print(OUTPUT_STRING);

end proc;

proc (n) local OUTPUT_STRING; OUTPUT_STRING := cat("Entered foo, n=", n); print(OUTPUT_STRING); OUTPUT_STRING := cat("leaving foo, n=", n); print(OUTPUT_STRING) end proc

my_print_proc:=proc(s::string)
   print("Entered    my_print_proc");
   print(s);
end proc;

proc (s::string) print("Entered    my_print_proc"); print(s) end proc

Grid:-Set(foo):
Grid:-Set(my_print_proc):
Grid:-Setup("local",numnodes=4);

Grid:-Run(0,foo,[0],'printer'='my_print_proc'):
Grid:-Run(1,foo,[1],'printer'='my_print_proc'):
Grid:-Run(2,foo,[2],'printer'='my_print_proc'):
Grid:-Run(3,foo,[3],'printer'='my_print_proc'):
Grid:-Wait();

#nothing is printed from foo

 


 

Download grid_question_jan_27_2025_V3.mw

This below is same thing as above but without numnodes option. Now it works and printer proc is called indeed. This shows that printer proc only works if numnodes is not used.

But printer proc is not really needed if one is not using numnodes, as print() from node shows on the screen on its own and no need to use print proc in first place.

So now I am having hard time debugging my Grid code, since when I print something it does not show on the screen. But I need to use numnodes option, as I found there are problems that go away when I use this option. So I have now to find a way to print debug messages. May be send them to file and look at them later.  

I do not think numnodes is supported well in Grid package.

 

restart;

foo:=proc(n)
   local OUTPUT_STRING;

   OUTPUT_STRING:=cat("Entered foo, n=",n);

   print(OUTPUT_STRING);

   OUTPUT_STRING:=cat("leaving foo, n=",n);
   print(OUTPUT_STRING);

end proc:

my_print_proc:=proc(s::string)
   print("Entered    my_print_proc");
   print(s);
end proc;

proc (s::string) print("Entered    my_print_proc"); print(s) end proc

Grid:-Set(foo):
Grid:-Set(my_print_proc):
Grid:-Setup("local"):#,numnodes=4);

Grid:-Run(0,foo,[0],'printer'='my_print_proc'):
Grid:-Run(1,foo,[1],'printer'='my_print_proc'):
Grid:-Run(2,foo,[2],'printer'='my_print_proc'):
Grid:-Run(3,foo,[3],'printer'='my_print_proc'):
Grid:-Wait();

"Entered    my_print_proc"

"Entered foo, n=0"

"Entered    my_print_proc"

"Entered foo, n=1"

"Entered    my_print_proc"

"leaving foo, n=0"

"Entered    my_print_proc"

"Entered foo, n=2"

"Entered    my_print_proc"

"leaving foo, n=1"

"Entered    my_print_proc"

"leaving foo, n=2"

"Entered    my_print_proc"

"Entered foo, n=3"

"Entered    my_print_proc"

"leaving foo, n=3"

 


 

Download grid_question_jan_27_2025_V4.mw

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