mmcdara

7891 Reputation

22 Badges

9 years, 52 days

MaplePrimes Activity


These are replies submitted by mmcdara

The first one being "What software does your partner use?"

@Jean-Michel 

For your information there was also a recent question on Mapleprimes asking if  a "black mode" (black background and white text) would be avaliable soon.



Go to Preferences ; in French installation (Maple 2015)

:

In the pop-up window



increase the calue of the field "Default Zoom"
Next select "Apply Globally".

For your Maple version Preferences might be placed somewhere else, but the operations to do should
be more or less the same.
 
Hope it helps

@acer 

I really thought I'd done something stupid

@Aixleft math  @Yuri Zamorano

Thanks @Aixleft math

Just for fun, here is a proof that T(-1)(solution(LM)) <> solution(PM) where T is the one-to-one transformation which maps the power regression model PM into the liearized regression  model LM.

The main result is that even if PM is linear, for instance Y = A*XB with B=1 T(-1)(solution(LM)) is equal to  solution(PM) if and only if the data do not contain any observation error (that is the data exapctly verify the relation  Yn = A*Xn).
As soon it i no longer the case, for  instance  Yn = A*Xn + En. where En denotes an observation error
using a log-log transformation to assess log(A) and going backward to A introduces a bias.

It is worth noting that ExponentialFit suffers the same flaws, see below

PowerFit_Linearize_or_not.mw

First conclusion: "avoid using PowerFit or ExponentialFit and remain very careful as using the Statistics package".
I indeed found myself several errors, that I signaled, but not rnough persons seem to use this package for the core development team yakes time to correct them

Secondly, Maple put aside,  "always remain carefull when using linearization techniques".
Here are two short lectures about pitfalls in linearization of non linear regression models math.duke.edu or mathworks.

Not even saying that some statistics do not make any sense (R_squared, Cook's distance or Atkinson's T, to cite a few, that PowerFit nevertheless computes).

@salim-barzani 

In order to have a smart representation of the factored expression I had to use the neutral operator `` (see help page).

Here is a toy example where I explain how to factor an expression with respect to some other one
 

restart

# A random expression of (a, b, c)

original := randpoly(x, degree=2);

expr := simplify(eval(original, x=a/(b+c)))

-7*x^2+22*x-55

 

-(7*a^2-22*a*b-22*a*c+55*b^2+110*b*c+55*c^2)/(b+c)^2

(1)

# Obviously:

# Starting from expr, how can we get smart_expr
#
# Introduce an auxiliary variable W defineby relation rel

rel := a = (b+c)*W;
CW := map(simplify, collect( subs(rel, expr), W), size);  # nothing but the original expression
                                                          # with x replaced by W


invrel := isolate(rel, W);  # define the reciprocal substitution relation
Z := eval(CW, invrel);      # use it to get something like smart_expr    
 

a = (b+c)*W

 

-7*W^2+22*W-55

 

W = -a/(-b-c)

 

-7*a^2/(-b-c)^2-22*a/(-b-c)-55

(2)

# Not very smart, so "protect" the

isolate(rel, W):
invrel := lhs(%) = ``(simplify(rhs(%)));

lprint(invrel);
Z := eval(CW, invrel);  #smart expresion showing the factorization wrt a/(b+c)

W = ``(a/(b+c))

 

W = ``(a/(b+c))

 

-7*``(a/(b+c))^2+22*``(a/(b+c))-55

(3)

 

 

Download explanation_toy_example.mw

Once this trick understood, look to my find-parameter_2_mmcdara_explains.mw worksheet.

PS: I don't understand the final comment in your last file "NULL" ???

ATTACHED FILE UPDATED APRIL 12 AT 18.11 GMT

For years I use to use the Statistics package and I never pointed this error.

(At my discharge I always found stupid to develop the PowerFit  function [and the PolynomialFit function too] as the regression models they both use are linear under obvious transformations.
So I always use LinearFit (or Fit) after having possibly applied some linearization.
That is why I never payed any attention to PowerFit nor PolynomialFit.)

The core team made a big mistake here for two reasons:

  • First error: PowerFit asseses the parameters after having linearized the model with a log-log transformation and next deduce the power fit model from the linearized fit model by appying the reciprocal of the log-log transformation.
    It is shown in the attached file (and proved in a separate comment) that the power fit we get this way is wrong.
     
  • Second error: PowerFit and  LinearFit/Fit both provide the same values for all the statistics they assess, which is clearly impossible because some should be the logarithm (or the  exponential) of the others. In fact a lot of those statistices (correctly computed by LinearFit/Fit) are only defined on linear or multilinear models and have no sense on nonlinear, for instance power, models. 
     

About R-squared and Adjusted R-squared:
Googling a few seconds will reveal you that R-squared in intrinsic to LINEAR REGRESSION and cannot (should never) be used to assess the quality of a NON LINEAR REGRESSION model... even if a few authors in some unreliable forums advocate the opposite.
It"s better to kook to what serious statistical tools do say about this:

  • MINITAB
  • SPSS
  • R also proposes a lot of packages to assess a so called "pseudo R-squared"

I advice you to read the seminal paper by Kvalseth where it discusses the weakness of R-squared as a goodness-of-fit criterion in the case of a power model.

restart

with(Statistics):

toy_model := x -> 3*x^2

proc (x) options operator, arrow; 3*x^2 end proc

(1)

N := 10:
X := Sample(Uniform(1, 4), N):
E := Sample(Normal(0, 0.5), N):
Y := toy_model~(X) + E:

convert(X, list);
convert(Y, list)

[HFloat(3.4441710591795367), HFloat(3.717375811226858), HFloat(1.380960448880518), HFloat(3.740127568417058), HFloat(2.8970777386762285), HFloat(1.2926212149982286), HFloat(1.8354946566011452), HFloat(2.6406445576149515), HFloat(3.8725205063028927), HFloat(3.8946656055978295)]

 

[HFloat(35.68887055585523), HFloat(41.40721285367005), HFloat(5.679806235595855), HFloat(41.88160312003919), HFloat(25.260188921734073), HFloat(4.674649461554181), HFloat(9.886723081209801), HFloat(21.367021031614165), HFloat(45.21975669189925), HFloat(46.144249064417046)]

(2)


PowerFit

PF := PowerFit(X, Y, x, output=solutionmodule)

_m4501567232

(3)

exports(PF);
lhs~(PF:-Results())

Results, Settings

 

["residualmeansquare", "residualsumofsquares", "residualstandarddeviation", "degreesoffreedom", "parametervalues", "parametervector", "leastsquaresfunction", "standarderrors", "confidenceintervals", "residuals", "leverages", "variancecovariancematrix", "internallystandardizedresiduals", "externallystandardizedresiduals", "CookDstatistic", "AtkinsonTstatistic"]

(4)


LinearFit  (or Fit)
y = a*x^b ==> y = a*exp(b*log(x)) ==> log(y) = log(a) + b*log(x) ... which is a linear model under the loglog transformation

LF := Fit(a*x+b, log~(X), log~(Y), x, output=solutionmodule)

_m4596516640

(5)

lhs~(LF:-Results())

["residualmeansquare", "residualsumofsquares", "residualstandarddeviation", "degreesoffreedom", "parametervalues", "parametervector", "leastsquaresfunction", "standarderrors", "confidenceintervals", "residuals", "leverages", "variancecovariancematrix", "internallystandardizedresiduals", "externallystandardizedresiduals", "CookDstatistic", "AtkinsonTstatistic"]

(6)

Comparisons

# Check PF and LF have the same members

is(convert(lhs~(LF:-Results()), set) = convert(lhs~(PF:-Results()), set));

# The answer being true, compare the two fitting strategies member by member

for p in lhs~(LF:-Results()) do
  ppf := rhs(op(select(has, PF:-Results(), p))):
  plf := rhs(op(select(has, LF:-Results(), p))):

  printf("\n\n%a\n", p);
  print(
    `if`(ppf::{list, Vector[row]}, convert(ppf, Vector[column]), ppf),
    `if`(plf::{list, Vector[row]}, convert(plf, Vector[column]), plf)
  )
end do:

true

 



"residualmeansquare"

 

0.354067426925161e-3, 0.354067426925160e-3

 



"residualsumofsquares"

 

0.283253941540129e-2, 0.283253941540128e-2

 



"residualstandarddeviation"

 

0.188166794872305e-1, 0.188166794872305e-1

 



"degreesoffreedom"

 

8, 8

 



"parametervalues"

 

Vector(2, {(1) = 1.0518326643514408, (2) = 2.042005245357665}, datatype = float[8]), Vector(2, {(1) = a = HFloat(2.042005245357664), (2) = b = HFloat(1.0518326643514415)})

 



"parametervector"

 

Vector(2, {(1) = 1.0518326643514408, (2) = 2.042005245357665}, datatype = float[8]), Vector(2, {(1) = 2.042005245357664, (2) = 1.0518326643514415}, datatype = float[8])

 



"leastsquaresfunction"

 

2.86289303526634*x^2.04200524535766, 2.04200524535766*x+1.05183266435144

 



"standarderrors"

 

Vector(2, {(1) = 0.15438832964026235e-1, (2) = 0.14531145156651886e-1}, datatype = float[8]), Vector(2, {(1) = 0.14531145156651862e-1, (2) = 0.15438832964026213e-1}, datatype = float[8])

 



"confidenceintervals"

 

Vector(2, {(1) = HFloat(1.0162306699455672) .. HFloat(1.0874346587573145), (2) = HFloat(2.0084963817159958) .. HFloat(2.075514108999334)}), Vector(2, {(1) = HFloat(2.0084963817159953) .. HFloat(2.0755141089993328), (2) = HFloat(1.0162306699455679) .. HFloat(1.0874346587573152)})

 



"residuals"

 

Vector(10, {(1) = -0.2307464989606533e-2, (2) = -0.9567202630307964e-2, (3) = 0.25967564327599037e-1, (4) = -0.1063538777974397e-1, (5) = 0.5310739665576262e-2, (6) = -0.33804273446730634e-1, (7) = -0.7783099390716125e-3, (8) = 0.2718185881453115e-1, (9) = -0.4980891821426487e-2, (10) = 0.36133677991807525e-2}, datatype = float[8]), Vector(10, {(1) = -0.23074649896075265e-2, (2) = -0.9567202630307569e-2, (3) = 0.2596756432759904e-1, (4) = -0.10635387779743571e-1, (5) = 0.53107396655762765e-2, (6) = -0.3380427344673065e-1, (7) = -0.7783099390715548e-3, (8) = 0.2718185881453128e-1, (9) = -0.4980891821426256e-2, (10) = 0.36133677991805253e-2}, datatype = float[8])

 



"leverages"

 

Vector(10, {(1) = .1391753933559186, (2) = .16598584709825542, (3) = .35789425770011085, (4) = .16842888485845092, (5) = .10414011535583388, (6) = .4123513344707602, (7) = .1830024505545112, (8) = .1000522418414015, (9) = .18320482979001074, (10) = .18576464497474685}, datatype = float[8]), Vector(10, {(1) = .1391753933559186, (2) = .1659858470982554, (3) = .3578942577001108, (4) = .16842888485845084, (5) = .10414011535583391, (6) = .41235133447076017, (7) = .18300245055451117, (8) = .10005224184140155, (9) = .1832048297900106, (10) = .18576464497474676}, datatype = float[8])

 



"variancecovariancematrix"

 

Typesetting:-mrow(Typesetting:-mverbatim("-I'RTABLEG6"6%"5!R+Y>uSuY%=-I'MATRIXG6"6#7$7$$"0.6HjvNQ#!#=$!0<=Ep=,2#!#=7$$!0<=Ep=,2#!#=$"0)oj&zT:6#!#=I'MatrixG6$%*protectedGI(_syslibG6""), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mverbatim("-I'RTABLEG6"6%"5U0g%>uSuY%=-I'MATRIXG6"6#7$7$$"0(oj&zT:6#!#=$!0<=Ep=,2#!#=7$$!0<=Ep=,2#!#=$"0-6HjvNQ#!#=I'MatrixG6$%*protectedGI(_syslibG6""))

 



"internallystandardizedresiduals"

 

Vector(10, {(1) = -.1321705802127725, (2) = -.5567436528686329, (3) = 1.722205420486634, (4) = -.6198129476248265, (5) = .29818924833800703, (6) = -2.343525813363909, (7) = -0.4576139046466226e-1, (8) = 1.5227461677821912, (9) = -.2928920215412854, (10) = .21281106471290148}, datatype = float[8]), Vector(10, {(1) = -.13217058021282957, (2) = -.5567436528686106, (3) = 1.7222054204866362, (4) = -.6198129476248041, (5) = .2981892483380082, (6) = -2.343525813363913, (7) = -0.45761390464658935e-1, (8) = 1.5227461677822005, (9) = -.29289202154127214, (10) = .21281106471288833}, datatype = float[8])

 



"externallystandardizedresiduals"

 

Vector(10, {(1) = -.12376946432297567, (2) = -.5311780177110058, (3) = 2.0308460378337085, (4) = -.5942250955803445, (5) = .2804936443085557, (6) = -3.915297796974264, (7) = -0.4281146476303449e-1, (8) = 1.6902650444064873, (9) = -.2754562682767506, (10) = .19963239139610178}, datatype = float[8]), Vector(10, {(1) = -.12376946432302922, (2) = -.5311780177109837, (3) = 2.0308460378337125, (4) = -.5942250955803219, (5) = .28049364430855683, (6) = -3.915297796974285, (7) = -0.4281146476303138e-1, (8) = 1.6902650444065013, (9) = -.275456268276738, (10) = .19963239139608938}, datatype = float[8])

 



"CookDstatistic"

 

Vector(10, {(1) = 0.14121713033917345e-2, (2) = 0.308445324996484e-1, (3) = .8265860745464597, (4) = 0.38905273298960596e-1, (5) = 0.516811214868959e-2, (6) = 1.9268998259991237, (7) = 0.23453333541615653e-3, (8) = .12889455144694204, (9) = 0.9620748130778692e-2, (10) = 0.5166203618873634e-2}, datatype = float[8]), Vector(10, {(1) = 0.14121713033929538e-2, (2) = 0.30844532499645923e-1, (3) = .8265860745464616, (4) = 0.3890527329895774e-1, (5) = 0.51681121486896325e-2, (6) = 1.926899825999129, (7) = 0.23453333541612238e-3, (8) = .12889455144694364, (9) = 0.9620748130777812e-2, (10) = 0.5166203618872993e-2}, datatype = float[8])

 



"AtkinsonTstatistic"

 

Vector(10, {(1) = -0.9953306991598417e-1, (2) = -.47393513797812875, (3) = 3.0323622672481867, (4) = -.5348593271795067, (5) = .1912678618320319, (6) = -6.559483149432607, (7) = -0.4052361293932548e-1, (8) = 1.1271703809836735, (9) = -.2609122885164463, (10) = .19070740551601817}, datatype = float[8]), Vector(10, {(1) = -0.9953306991602724e-1, (2) = -.473935137978109, (3) = 3.0323622672481925, (4) = -.534859327179486, (5) = .1912678618320327, (6) = -6.559483149432641, (7) = -0.4052361293932254e-1, (8) = 1.127170380983683, (9) = -.2609122885164343, (10) = .1907074055160063}, datatype = float[8])

(7)

# As you can see all the statistics are the same, which is indeed stupid.
# Let's take the residuals case.
#
# Assuming the linearized fit is correct, the residuals are:
# (check they correspond to what LinearFit computed)

LF_fit := unapply( rhs(op(select(has, LF:-Results(), "leastsquaresfunction"))), x);
LF_res := log~(Y) -~ LF_fit~(log~(X))
 

LF_fit := proc (x) options operator, arrow; 2.042005245357664*x+1.0518326643514415 end proc

 

LF_res := Vector[row](10, {(1) = HFloat(-0.0023074649896051014), (2) = HFloat(-0.009567202630307303), (3) = HFloat(0.025967564327599613), (4) = HFloat(-0.010635387779743155), (5) = HFloat(0.005310739665576936), (6) = HFloat(-0.03380427344673009), (7) = HFloat(-7.783099390707982e-4), (8) = HFloat(0.027181858814532056), (9) = HFloat(-0.0049808918214253595), (10) = HFloat(0.003613367799181866)})

(8)

# From this linear fit one may think to deduce the "power fit" model this
# way (it will be shown later that this is not correct because the log-log
# transformation is obviously not a bilinear transformation).             

PF_fit := unapply( expand(solve(log(y) = LF_fit(log(x)), y)), x)

proc (x) options operator, arrow; 2.862893034*x^2.042005245 end proc

(9)

# You can verify that PowerFit gave this same result

rhs(op(select(has, PF:-Results(), "leastsquaresfunction")))

HFloat(2.862893035266338)*x^HFloat(2.042005245357665)

(10)

# But the parameter values are OBVIOUSLY WRONG in PowerFit: they should be

PF_params := indets((10), constant);

# but PowerFit returns

rhs(op(select(has, PF:-Results(), "parametervalues")))

PF_params := {2.04200524535766, 2.86289303526634}

 

Vector[column]([[1.05183266435144], [2.04200524535766]])

(11)

# My guess
#
# PowerFit linearizes the model y = a*x^b into log(y) = log(a) + b*log(x) and
# uses LinearFit on the backstage
#
# Next PowerFit provides the expression of the power model by using the same
# reciprocal transformation I used to get relation (10).
# (which I said above gives a wrong result)
#
# But in doing so PowerFit forgets to recompute all statistics.
# For instance the residuals on the true power model are

PF_res = convert(Y -~ PF_fit~(X), Vector[column])

PF_res = (Vector(10, {(1) = HFloat(-0.08244587161767924), (2) = HFloat(-0.39805224484291557), (3) = HFloat(0.1455922181212852), (4) = HFloat(-0.4478041157659902), (5) = HFloat(0.1337947190726254), (6) = HFloat(-0.160724406950445), (7) = HFloat(-0.00769792361232291), (8) = HFloat(0.5729728538568466), (9) = HFloat(-0.22579654152254847), (10) = HFloat(0.1664353093782438)}))

(12)

# Compare this to what PowerFit computes

convert( rhs(op(select(has, PF:-Results(), "residuals"))), Vector[column])

Vector[column]([[-0.230746498960653e-2], [-0.956720263030796e-2], [0.259675643275990e-1], [-0.106353877797440e-1], [0.531073966557626e-2], [-0.338042734467306e-1], [-0.778309939071612e-3], [0.271818588145312e-1], [-0.498089182142649e-2], [0.361336779918075e-2]])

(13)

# Graphic verification of the order of magnitude of the residuals

dataplot(Y -~ PF_fit~(X))

 


  NEW    NEW    NEW    NEW     

# Sometimes it's better to use Optimization to fit a non linear model.
# Doing so provides correct estimations of the parameters.
#
# Note that they differ (slightly, but there remain differences) from
# the parameter values deduced from the linearized model.
MODEL := x -> a*x^b;

J := add((Y -~ MODEL~(X))^~2):

opt := Optimization:-NLPSolve(J);

dof := rhs(op(select(has, LF:-Results(), "degreesoffreedom")));

Residual_Standard_error := sqrt(opt[1]/dof);  # aka RMSE

proc (x) options operator, arrow; a*x^b end proc

 

[.613598341609467912, [a = HFloat(2.959735339291367), b = HFloat(2.0140324022813765)]]

 

8

 

.2769472742

(14)

# For information here is the results provided by R on the same (X, Y) data.
# Observe they correspond to esults above.



# R applied to the linearized model gives



# In order to compare these values to Maple's I rewrote the linearized model
# a little bit differently.
# The introduction of "log(a)" instead of "a" enables a direct comparison
# to the power fit model.

LinModel := (a, b) -> log(a)+b*x;

LF2 := Fit(LinModel(a, b), log~(X), log~(Y), x, output=solutionmodule):

ab := rhs(op(select(has, LF2:-Results(), "parametervalues")));
rhs(op(select(has, LF2:-Results(), "residualstandarddeviation")));

proc (a, b) options operator, arrow; log(a)+b*x end proc

 

[a = HFloat(2.862893035583528), b = HFloat(2.0420052773126733)]

 

0.1881667949e-1

(15)

# What you see is that the power fit model cannot be obtained directly from
# the linearized fit model.
#
# Indeed:

log(y) = subs(op(ab), eval(LinModel(a, b), log=``(log)));

# but

y = subs(op(opt[2]), MODEL(x))

ln(y) = ln(HFloat(2.862893035583528))+HFloat(2.0420052773126733)*x

 

y = HFloat(2.959735339291367)*x^HFloat(2.0140324022813765)

(16)

# To understand why the power fit model is not a simpletransformation of the
# linearized fit model, observe how different are the objective functions computed
# on the linearized model and on the power model.
# (Big green points correspond to the their minimizers in (a, b) coordinates.)

LinearObjectiveFunction := add((log~(Y) -~ (log(a) +~ b*~log~(X)))^~2):
PowerObjectiveFunction  := add((Y -~ a*~X^~b)^~2):

DocumentTools:-Tabulate(
  [
    plots:-display(
      plots:-contourplot(LinearObjectiveFunction, a=2.8..3.2, b=1.8..2.2, contours=50, gridlines=true)
      , plot([rhs~(ab)], style=point, symbol=solidcircle, symbolsize=20, color=green)
      , title="Objective function after log-log linearization"
    )
    ,
    plots:-display(
      plots:-contourplot(PowerObjectiveFunction , a=2.8..3.2, b=1.8..2.2, contours=50, gridlines=true)
      , plot([rhs~(opt[2])], style=point, symbol=solidcircle, symbolsize=20, color=green)
      , title="True Objective function"
    )
  ]
  , width=60
);


R-squared

# By definition, for the linearized model

'R_squared' = ':-Variance'(explained) / ':-Variance'(data);
':-Variance'(data) = ':-Variance'(log~('Y'));
':-Variance'(explained) = ':-Variance'('LF_fit(log(X))');

print():

# Thus:
R_squared_LF := Variance(LF_fit~(log~(X))) / Variance(log~(Y));

# Visual checking


plots:-display(
  plots:-pointplot(log~(X), log~(Y))
  , plot(LF_fit(x), x=(min..max)(log~(X)))
  , gridlines=true
);

R_squared = Variance(explained)/Variance(data)

 

Variance(data) = Variance(ln(Y))

 

Variance(explained) = Variance(LF_fit(log(X)))

 

 

HFloat(0.9995950512526113)

 

 

# Direct transposition to the powerfit model


'R_squared' = ':-Variance'(explained) / ':-Variance'(data);
':-Variance'(data) = ':-Variance'('Y');
':-Variance'(explained) = ':-Variance'('PF_fit(X)');

print():
# Thus:

R_squared_PF := Variance(PF_fit~(X)) / Variance(Y);
 

R_squared = Variance(explained)/Variance(data)

 

Variance(data) = Variance(Y)

 

Variance(explained) = Variance(PF_fit(X))

 

 

HFloat(1.0137852676630892)

(17)

# A stupid result as 0 <= R-squared <= 1
#
# Where does the hell this come from?
# Basically from the fact that R-squared is only valid for linear regression.
#
# Indeed R-squared is based on the assumption that
#       Total Variance = Explained Variance + Error Variance
# (where Error Variance is the variance of the residues)
#
# But his relation in wrong for a non linear model (as model a*x^b is, despite
# the fact it can be made linear under a log-log transformation... which is of
# course a non linear transformation itself).
#
# Then one can compute R-squared on the linearized model, and this makes sense,
# in particular 0 <= R-squared <= 1, but it makes no sense in trying to compute
# a value for the non-linearized model from the linearized model value.
#
# So if you really want to guve a RT-squared value you have to work on the
# linearized model only.
#
# Note that for "true" non linear models, such as y = a+b*exp(c*x), the R-squared
# is not defined.
 


Adjusted R-squared

# By definition, for the linearized model

'R_squared_adjusted' = 1 - (1-'R_squared')*(n-1)/(n-k-1);
'n' = `number of observations`;
'k' = `number of parameters in the regression model`;

print();

'n-k' = `degrees of freedom`;

R_squared_adjusted = 1-(1-R_squared)*(n-1)/(n-k-1)

 

n = `number of observations`

 

k = `number of parameters in the regression model`

 

 

n-k = `degrees of freedom`

(18)

# As for R-squares, the adjusted R-squared is only defined for linear models.
# So, workink on the linerized model gibes:

R_squared_adjusted := 1 - (1-R_squared)*(N-1)/(dof-1);

8

 

-2/7+(9/7)*R_squared

(19)
 

 

Download PowerFit_vs_LinearFit.mw

@acer 

Strange, isn't it? 
Do you have any idea of what might be going on? 
Is this a situation worth investigating by submitting an SCR or something like that?  Or should it be considered a marginal defect (using @C_R 's idea seems indeed to avoid the issue)?

@C_R I'm going to see what I can do about this driver thing and verify I don't have problems with `2`^n (good idea by the way).

@Andiguys 

For instance, the expression:

1/((w+Ce)2⋅(−δ+w+Ce)2⋅λ−16⋅U[0]2)

is common in g1,g2, g3,  pi1,pi2 and it also appears in g_1, g_2, g_3,pi_1,pi_2. though in the latter it includes an additional term 't'

Which means that

is common in g1,g2, g3,  pi1,pi2 but NOT to g_1, g_2, g_3,pi_1,pi_2. as it contains "t".
Indeed these latters both  both contain instead 


Then one can consider as common to the 10 quantities unless t=0.

The only common sub-expressions amid g1, g2 and g3 are (a+Cm), (a-Cm) and .
The only common sub-expressions amid g1, g2, g3 and pi1 are (a+Cm) and (a-Cm).

I didn't investigate g_1, g_2, g_3 but it is visualy clear that the only subexpressions they will shar withe g1, g2, g3, pi1 are again  (a+Cm) and (a-Cm).

Look common_term_mmcdara_2.mw

Maybe simplifying the expressions otherwise could reveal more common sub-expresisons, but it is like looking for a needle in a haystack.
Mybe you could find some idea in observing the outputs of things like this:

CodeGeneration:-Python(g1, optimize)
Warning, the following variable name replacements were made: lambda -> cg
t1 = w + Ce
t2 = t1 ** 2
t4 = (-delta + w + Ce) ** 2
t7 = U[-1] ** 2
t11 = Ce ** 2
t14 = a * delta
t15 = 2 * t14
t20 = w ** 2
t27 = delta ** 2
t28 = a * t27
t30 = 2 * U * delta
t32 = U[-1] * (a - Cm)
t33 = 2 * t32
t54 = 1 / (t2 * t4 * cg - 16 * t7) * (-t1 * (-a * t11 * Ce + (-3 * a * w + U + t15) * t11 + (-3 * a * t20 + (4 * t14 + 2 * U) * w - t28 - t30 - t33) * Ce - a * t20 * w + (t15 + U) * t20 + (-t28 - t30 - t33) * w + U * t27 + 2 * t32 * delta - 4 * U[-1] * k) * cg - 8 * t7 * (a + Cm))

Sub-expressions are t1, ...t33.
Next compare this output to the one of CodeGeneration:-Python(g2, optimize) for instance

CodeGeneration:-Python(g2, optimize)
Warning, the following variable name replacements were made: lambda -> cg
t2 = (w + Ce) ** 2
t3 = -delta + w + Ce
t11 = -a + Cm
t12 = Ce ** 2
t15 = -t11 * delta / 2
t18 = w ** 2
t30 = t3 ** 2
t33 = U[-1] ** 2
t37 = (t2 * t3 * (a * Ce - a * delta + a * w + k) * cg - 4 * (t11 * t12 / 2 + (t11 * w + U + t15) * Ce + t18 * t11 / 2 + (t15 + U) * w - U * delta + 2 * U[-1] * (a + Cm)) * U[-1]) / (t2 * t30 * cg - 16 * t33)

(You can redirect the ouputs to different files using writeto and use any file comparator after)

REMARK:
As I replied here to slim Barzani, "It's never a good strategy to complexify unnecessarily an expression before trying to solve it.".
Transpose to your problem I would say "It's never a good strategy to complexify unnecessarily several expressions and try to extract some common features after that.".

Let me be clear: your 10 equations do not come out from your mind but are more likely the results of some prelminary computations (what you name "scenarios").
I suspect that in those scenarios you have several assignments of form

a := F(x, y)
b := G(u, v, w):
...
c := H(a, b, p);
d := J(p, a, c);
...
e := K(c, d, k, m)
f := L(c, d, t, z)
...

final_expressions := {A(e, f), B(e, f, a, d), C(e, f, p, b)}

That is a succession of declarations that depend on the preceding declarations. I can't imagine another coding which can leads to the complex expressions final_expressions contains.

Now what you want is to identify common sub-expressions in final_expressions.
But they are clearly e and f, and at a deeper level c and d, and at an even deeper level a.
What I'm saying is that the way you get   final_expressions gives you directly the answer you are looking for.

Read carefully the question/answer/comments to this Question.

And, ann advice, share the worksheet where your scenarios are coded dor us to see if there is not a simple way to answer your question instad of working blindly on your 10 final_expressions.

Here is a very simple code based on two build-in Maple functions.
It enables getting the result you present and, potentially, the same kind of results for any value of n....

decompose := proc(n)
  remove(has, combinat:-partition(n, n), {1, n})
end proc:
decompose(8)
  [[2, 2, 2, 2], [2, 3, 3], [2, 2, 4], [4, 4], [3, 5], [2, 6]]

.... But your requirement "The program should be able to calculate these partitions for n=1..10000 in reasonable time" seems to me completely unrealistic for the reasons exposed in the attached file.
Indeed the number of partitions for n=1000 (including those containing "1") is about 10^31.

A_solution.mw

"Pr" is the conventional name for the Prandtl number: this is thus a numeric parameter that the OP most likely forgot to assign it a value (the same way C[p] denotes the Heat capacity for an isobaric process).

My bet is that the OP works on a some fluid dynamics problem with heat exange (aerodynamics?) problem (phi would then be a number called "potential velocity"... or a scalar function...), and I agree some explanations are necessary to state definitely if  a "*" is missing after phi[2] in these equations

   phi[2](1-phi[1]+phi[1]*rho[s1]/rho[fl])
   phi[2](1-phi[1]+phi[1]*rho[s1]*beta[s1]/(rho[fl]*beta[fl]))
   phi[1](k[fl]-k[s1]), phi[2](k[fl]-k[s2]),
   phi[2](1-phi[1]+phi[1]*rho[s1]*C[p][s1]/(rho[fl]*C[p][fl]))

@acer 

I agree, I was focused on the arguments of U and didn't payed attention to that point.
I woud have use  unapply if I had written the code myself.

Thanks for your correction

@salim-barzani 

In almost all the case a plotting error comes from the fact you want to plot something which is not plotable.
For instance, if plot(F, x=..) returns an error, it is almost always the case that F contains other names than x.

You can use indets(F, name) to check that, but its not enough, because F can also contains functions, for instance
F = s*g(a), or simply F = s*g(1),  and that will be revealed using indets(F, function).

In your case:

F := eval(U(x, y, a, b, alpha, beta, lambda__1, lambda__2, w__1, w__2), t = -50):

indets(F, name);
indets(F, function);
                             {x, y}
                          {Bij(1, 2)}

The plot can't be done as F contains this undeterminate function Bij(1, 2).

If you don'y want to use indets whar whatever reason, simply display F, examine carefully the output ans see by yourself what does wrong.
As a rule, as soon as you get a plotting error, display what you want to plot.

Personnaly I always display the function I want to plot before trying to plot it, self-overconfidence is never a good councelor and I know for sure that I do mistakes.

3 4 5 6 7 8 9 Last Page 5 of 154