dharr

Dr. David Harrington

8205 Reputation

22 Badges

20 years, 337 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are answers submitted by dharr

Zeckendorf's theorem in the title of your post is about a unique sum of Fibonacci's, not all sums. @mmcdara has just given a version of all sums; here is an efficient implementation of the unique version.

Zeckendorf's theorem. There is a unique sequence of distinct fibonacci numbers adding to F if we exclude consecutive fibonacci numbers.

restart

Golden ratio

phi := (1+sqrt(5))*(1/2)

1/2+(1/2)*5^(1/2)

n for largest fibonacci not greater than F - see wikipedia

nlarge := unapply(floor(log[phi](sqrt(5)*(F+1/2))), F)

proc (F) options operator, arrow; floor(ln(5^(1/2)*(F+1/2))/ln(1/2+(1/2)*5^(1/2))) end proc

Largest fibonacci not greater than 100.

combinat:-fibonacci(nlarge(100))

89

Greedy algorithm - successively find largest fibonacci's f not greater than the remainder r.
Example: Adding to 100

"r:=100:  do    f:=combinat:-fibonacci(nlarge(r));    print(f);    r:=r-f;  until r=0:"

89

8

3

zeck := proc(n::posint)
  local nlarge, r, f, i;
  nlarge := F -> floor(log[(1 + sqrt(5))/2](sqrt(5)*(F + 1/2)));
  r := n;
  f := table();
  for i do
    f[i] := combinat:-fibonacci(nlarge(r));
    r := r - f[i];
  until r = 0;
  convert(f, list);
end proc:

zeck(100)

[89, 8, 3]

zeck(10^12); add(%)

[956722026041, 32951280099, 7778742049, 1836311903, 701408733, 9227465, 832040, 121393, 46368, 2584, 987, 233, 89, 13, 3]

1000000000000

NULL

Download Zeckendorf.mw

Using trace and showstat shows that this doesn't go through GAMMA, despite the help page. Hope I've traced this correctly; I haven't given all the details. (For positive integers, binomial(a,b) = 0 for b>a is consistent with no ways to choose b out of a.)

restart;

trace(binomial);

[binomial:-ModuleApply]

Consider first integers outside the range 0<=k<=n; the result is just zero

binomial(4, 6);

execute binomial:-ModuleApply, args = 4, 6

{--> enter binomial:-ModuleApply, args = 4, 6

6

-2

4

0

<-- exit binomial:-ModuleApply (now at top level) = 0}

0

The code is just:
elif type(A,'integer') and type(B,'integer') then
            if 0 < A then
                if B < 0 or A < B then
                    res := 0 (result)

Now consider

binomial(n, n + 2) assuming n::posint;

execute binomial:-ModuleApply, args = \`n~\`, n+2

{--> enter binomial:-ModuleApply, args = \`n~\`, n+2

n+2

-2

n

1

1

0

<-- exit binomial:-ModuleApply (now in \`assuming\`) = 0}

0

So what happens here:

B:=normal(b) -> n+2;
Work out AmB: = a-B -> -2
A:=normal(a) -> n;
s: = signum(A)  -> 1

If s = 1 or -1 and AmB::negint (yes)

then

i := signum(0,B,0) -> 1 (sign of B treating 0 as 0)
if i is 1 or -1 then
               if s = 1 or s = i then
                      res := 0

So result is zero.

 

In other words, since A and B are positive and A-B is a negative integer the result is zero

 

binomial(n, n+1) uses  `tool/type` which makes it a bit more obscure but seems to be a similar argument.

 

Download binomial.mw

This is not as systematic as @mmcdara's method, but answers the question for your second example containing sigma__d3. You could use the approximate form for Lambda instead.

restart

local gamma:with(plots):

 # Define the assumptions - or Maple wouldn't know

assume(0 < gamma, 0 < sigma__d, 0 < sigma__d3, 0 < sigma__v);
interface(showassumed=0);

1

# Input lambda parameters

Lambda := RootOf(8*_Z^4 + 12*Gamma*_Z^3 + (5*Gamma^2 - 4)*_Z^2 - 4*Gamma*_Z - Gamma^2);
f__1 := Lambda*(sigma__v/sigma__d):
f__2 := f__1:
f__3 := sqrt(2)*sigma__v/sigma__d3:

RootOf(8*_Z^4+12*Gamma*_Z^3+(5*Gamma^2-4)*_Z^2-4*Gamma*_Z-Gamma^2)

 Let's scale these. If we divide f__1 by sqrt(2)*(sigma__v/sigma__d) we get Lambda/sqrt(2); we divide f__2 and f__3 by the same.

f__1sc := f__1/(sqrt(2)*(sigma__v/sigma__d));
f__2sc := f__2/(sqrt(2)*(sigma__v/sigma__d));
f__3sc := f__3/(sqrt(2)*(sigma__v/sigma__d));

 

(1/2)*RootOf(8*_Z^4+12*Gamma*_Z^3+(5*Gamma^2-4)*_Z^2-4*Gamma*_Z-Gamma^2)*2^(1/2)

(1/2)*RootOf(8*_Z^4+12*Gamma*_Z^3+(5*Gamma^2-4)*_Z^2-4*Gamma*_Z-Gamma^2)*2^(1/2)

sigma__d/sigma__d3

Now Gamma = gamma*sigma__v*sigma__d = gamma*sigma__v*sigma__d3*f3sc = a*f3sc, where a = gamma*sigma__v*sigma__d3.

We want to know when f3sc = f1sc, or Gamma/a = Lambda/sqrt(2), which will only depend on the combined parameter a = gamma* sigma__v*sigma__d3

Gamma/a=f__1sc;
aval:=solve(%,a);

Gamma/a = (1/2)*RootOf(8*_Z^4+12*Gamma*_Z^3+(5*Gamma^2-4)*_Z^2-4*Gamma*_Z-Gamma^2)*2^(1/2)

Gamma*2^(1/2)/RootOf(8*_Z^4+12*Gamma*_Z^3+(5*Gamma^2-4)*_Z^2-4*Gamma*_Z-Gamma^2)

Plot f__1sc = f__3sc = sigma__d/sigma__d3 vs a = gamma*sigma__v*sigma__d3

pp:=plot([aval,f__1sc,Gamma=0..2],labels=[gamma*sigma__v*sigma__d3,sigma__d/sigma__d3]):

display(pp,textplot([3,0.3,typeset('f__3' < 'f__1')]),textplot([3,0.45,typeset('f__3' > 'f__1')]));

Test for some parameters

params:={gamma = 1, sigma__v = 1, sigma__d3 =3, sigma__d = 1};
evalf(eval([gamma*sigma__v*sigma__d3, sigma__d/sigma__d3], params));

{gamma = 1, sigma__d3 = 3, sigma__d = 1, sigma__v = 1}

[3., .3333333333]

This point is below the line, so we expect f3 < f1

evalf(eval(f__1sc, Gamma=eval(gamma*sigma__v*sigma__d,params)));
evalf(eval(f__3sc, params));

.3975956314

.3333333333

NULL

Download complicated_comparison2.mw

The documentation for IsFrobeniusGroup gives an example where IsFrobeniusGroup is true but IsFrobeniusPermGroup is false, so I think this result is OK. The documentation you referred to (for FrobeniusGroup) refers to the situation where  IsFrobeniusPermGroup is true, and so IsFrobeniusGroup will be true.

The small group (8,3) is expressed as a permutation group on 1,2,..8, but DihedralGroup(4) is expressed as a permutation group on 1,2,3,4. So the domain [1,2,3,4] is only half the points for (8,3) but it is all the points for D4. ReducedDegreePermGroup will convert (8,3) to the form you need.

restart

with(GroupTheory)

G1 := DihedralGroup(4)

_m2189854788256

G2 := SmallGroup(IdentifySmallGroup(G1))

_m2189934002208

AreIsomorphic(G1, G2)

true

IsTransitive(G1); IsTransitive(G2)

true

true

Elements(G1)

{_m2189853538880, _m2189854757216, _m2189854758688, _m2189854759104, _m2189854759616, _m2189854760000, _m2189854787040, _m2189854788096}

Elements(G2)

{_m2189840564448, _m2189840564832, _m2189840565216, _m2189840565600, _m2189854757216, _m2189934009088, _m2189934009312, _m2189934009504}

MinimumPermutationRepresentationDegree(G2)

4

G3 := ReducedDegreePermGroup(G2)

_m2189866943712

AreIsomorphic(G1, G3)

true

IsTransitive(G3, [1, 2, 3, 4])

true

NULL

Download Groups.mw

You have missed the fact that the algorithm is only for squarefree integers. For example 20 should give true, but to decide this you need to divide by the largest square factor 4 and apply the algorithm to the quotient 5. You also missed 6, which is squarefree, for some reason that wasn't clear to me. 

(I used @Ronan's version replacing print("True") with return true etc, but have my own working version if you are interested.)

As @C_R and @Rouben Rostamian have pointed out, the function is not specified accurately enough.

restart;

with(plots):

F:=phi->3.924999 - 0.024999/sqrt(1 - 2*phi) - 3.900/(1 - phi/6)^(3/2) - 1.648094618*10^(-14)*sqrt(3)*sqrt(1836)*(((1.3972 + sqrt(3)*sqrt(1836))^2 + 3672*phi)^(3/2) - (1.3972 + sqrt(3)*sqrt(1836))^3 - ((1.3972 - sqrt(3)*sqrt(1836))^2 + 3672*phi)^(3/2) + ((1.3972 - sqrt(3)*sqrt(1836))^2)^(3/2))-(1/18)*(sqrt(3)*sqrt(300)*(((1.4472 + sqrt(3)*sqrt(300)/300)^2 - 2*phi)^(3/2) - (1.4472 + sqrt(3)*sqrt(300)/300)^3 - ((1.4472 - sqrt(3)*sqrt(300)/300)^2 - 2*phi)^(3/2) + (1.4472 - sqrt(3)*sqrt(300)/300)^3)):

Problem seems numerically poorly posed: value at zero  (intended to be zero?) depends on floatng point 3.924999 - 0.024999 = 3.900, and then has term with coefficient 1.648e-14; large values also (3672)

Function goes to (close to?) zero at 0 and near 0.095

plot(F(phi),phi=-0.2..0.2,-0.00001..0.00001);

So the integrand goes to infinity/large value at these points.

integrand:=1/sqrt(-2*F(phi)):

Unreliable evaluation at default digits (see Roubens plot)

evalf(eval(integrand,phi=1e-9));
evalf(eval(integrand,phi=1e-8));

-10000.00012*I

18257.41710

plot(integrand,phi=-1..1);

plot(integrand,phi=-1.8..-0.4);

Complex

evalf(eval(integrand,phi=-1.6));

2.939542034-0.3641126258e-6*I

Rather than repeatedly solving integrals in a plot, can pose it as an ode, Arbitrarily integrate from -1.2

ode:=diff(x(phi),phi)=integrand:

ans1:=dsolve({ode,x(-1.2)=0.},numeric);

proc (x_rkf45) local _res, _dat, _vars, _solnproc, _xout, _ndsol, _pars, _n, _i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; if 1 < nargs then error "invalid input: too many arguments" end if; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then _xout := evalf[_EnvDSNumericSaveDigits](x_rkf45) else _xout := evalf(x_rkf45) end if; _dat := Array(1..4, {(1) = proc (_xin) local _xout, _dtbl, _dat, _vmap, _x0, _y0, _val, _dig, _n, _ne, _nd, _nv, _pars, _ini, _par, _i, _j, _k, _src; option `Copyright (c) 2002 by Waterloo Maple Inc. All rights reserved.`; table( [( "complex" ) = false ] ) _xout := _xin; _pars := []; _dtbl := array( 1 .. 4, [( 1 ) = (array( 1 .. 28, [( 1 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 2 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 3 ) = ([0, 0, 0, Array(1..0, 1..2, {}, datatype = float[8], order = C_order)]), ( 4 ) = (Array(1..65, {(1) = 1, (2) = 1, (3) = 0, (4) = 0, (5) = 0, (6) = 0, (7) = 1, (8) = 0, (9) = 0, (10) = 0, (11) = 0, (12) = 0, (13) = 0, (14) = 0, (15) = 0, (16) = 0, (17) = 0, (18) = 1, (19) = 30000, (20) = 0, (21) = 0, (22) = 1, (23) = 4, (24) = 0, (25) = 1, (26) = 15, (27) = 1, (28) = 0, (29) = 1, (30) = 3, (31) = 3, (32) = 0, (33) = 1, (34) = 0, (35) = 0, (36) = 0, (37) = 0, (38) = 0, (39) = 0, (40) = 0, (41) = 0, (42) = 0, (43) = 1, (44) = 0, (45) = 0, (46) = 0, (47) = 0, (48) = 0, (49) = 0, (50) = 50, (51) = 1, (52) = 0, (53) = 0, (54) = 0, (55) = 0, (56) = 0, (57) = 0, (58) = 0, (59) = 10000, (60) = 0, (61) = 1000, (62) = 0, (63) = 0, (64) = -1, (65) = 0}, datatype = integer[8])), ( 5 ) = (Array(1..28, {(1) = -1.2, (2) = 0.10e-5, (3) = .0, (4) = 0.500001e-14, (5) = -1.2, (6) = 0.12074408808982716e-2, (7) = .0, (8) = 0.10e-5, (9) = .0, (10) = .0, (11) = .0, (12) = .0, (13) = 1.0, (14) = .0, (15) = .49999999999999, (16) = .0, (17) = 1.0, (18) = 1.0, (19) = .0, (20) = .0, (21) = 1.0, (22) = 1.0, (23) = .0, (24) = .0, (25) = 0.10e-14, (26) = .0, (27) = .0, (28) = .0}, datatype = float[8], order = C_order)), ( 6 ) = (Array(1..1, {(1) = .0}, datatype = float[8], order = C_order)), ( 7 ) = ([Array(1..4, 1..7, {(1, 1) = .0, (1, 2) = .203125, (1, 3) = .3046875, (1, 4) = .75, (1, 5) = .8125, (1, 6) = .40625, (1, 7) = .8125, (2, 1) = 0.6378173828125e-1, (2, 2) = .0, (2, 3) = .279296875, (2, 4) = .27237892150878906, (2, 5) = -0.9686851501464844e-1, (2, 6) = 0.1956939697265625e-1, (2, 7) = .5381584167480469, (3, 1) = 0.31890869140625e-1, (3, 2) = .0, (3, 3) = -.34375, (3, 4) = -.335235595703125, (3, 5) = .2296142578125, (3, 6) = .41748046875, (3, 7) = 11.480712890625, (4, 1) = 0.9710520505905151e-1, (4, 2) = .0, (4, 3) = .40350341796875, (4, 4) = 0.20297467708587646e-1, (4, 5) = -0.6054282188415527e-2, (4, 6) = -0.4770040512084961e-1, (4, 7) = .77858567237854}, datatype = float[8], order = C_order), Array(1..6, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = 1.0, (2, 1) = .25, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (2, 6) = 1.0, (3, 1) = .1875, (3, 2) = .5625, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (3, 6) = 2.0, (4, 1) = .23583984375, (4, 2) = -.87890625, (4, 3) = .890625, (4, 4) = .0, (4, 5) = .0, (4, 6) = .2681884765625, (5, 1) = .1272735595703125, (5, 2) = -.5009765625, (5, 3) = .44921875, (5, 4) = -0.128936767578125e-1, (5, 5) = .0, (5, 6) = 0.626220703125e-1, (6, 1) = -0.927734375e-1, (6, 2) = .626220703125, (6, 3) = -.4326171875, (6, 4) = .1418304443359375, (6, 5) = -0.861053466796875e-1, (6, 6) = .3131103515625}, datatype = float[8], order = C_order), Array(1..6, {(1) = .0, (2) = .386, (3) = .21, (4) = .63, (5) = 1.0, (6) = 1.0}, datatype = float[8], order = C_order), Array(1..6, {(1) = .25, (2) = -.1043, (3) = .1035, (4) = -0.362e-1, (5) = .0, (6) = .0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 1.544, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = .9466785280815533, (3, 2) = .25570116989825814, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = 3.3148251870684886, (4, 2) = 2.896124015972123, (4, 3) = .9986419139977808, (4, 4) = .0, (4, 5) = .0, (5, 1) = 1.2212245092262748, (5, 2) = 6.019134481287752, (5, 3) = 12.537083329320874, (5, 4) = -.687886036105895, (5, 5) = .0, (6, 1) = 1.2212245092262748, (6, 2) = 6.019134481287752, (6, 3) = 12.537083329320874, (6, 4) = -.687886036105895, (6, 5) = 1.0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = -5.6688, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = -2.4300933568337584, (3, 2) = -.20635991570891224, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = -.10735290581452621, (4, 2) = -9.594562251021896, (4, 3) = -20.470286148096154, (4, 4) = .0, (4, 5) = .0, (5, 1) = 7.496443313968615, (5, 2) = -10.246804314641219, (5, 3) = -33.99990352819906, (5, 4) = 11.708908932061595, (5, 5) = .0, (6, 1) = 8.083246795922411, (6, 2) = -7.981132988062785, (6, 3) = -31.52159432874373, (6, 4) = 16.319305431231363, (6, 5) = -6.0588182388340535}, datatype = float[8], order = C_order), Array(1..3, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 10.126235083446911, (2, 2) = -7.487995877607633, (2, 3) = -34.800918615557414, (2, 4) = -7.9927717075687275, (2, 5) = 1.0251377232956207, (3, 1) = -.6762803392806898, (3, 2) = 6.087714651678606, (3, 3) = 16.43084320892463, (3, 4) = 24.767225114183653, (3, 5) = -6.5943891257167815}, datatype = float[8], order = C_order)]), ( 9 ) = ([Array(1..1, {(1) = .1}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 0}, datatype = integer[8]), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 0}, datatype = integer[8])]), ( 8 ) = ([Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 4.180460373419158}, datatype = float[8], order = C_order), 0, 0]), ( 11 ) = (Array(1..6, 0..1, {(1, 1) = .0, (2, 0) = .0, (2, 1) = .0, (3, 0) = .0, (3, 1) = .0, (4, 0) = .0, (4, 1) = .0, (5, 0) = .0, (5, 1) = .0, (6, 0) = .0, (6, 1) = .0}, datatype = float[8], order = C_order)), ( 10 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(phi)]`; if 0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)) < 12.0454404629703 then YP[1] := undefined; return 0 end if; if 3672*X < -5717.34108232408 then YP[1] := undefined; return 0 end if; if 3672*X < -5302.56325335595 then YP[1] := undefined; return 0 end if; if -2*X < -2.393827840 then YP[1] := undefined; return 0 end if; if -2*X < -1.814947840 then YP[1] := undefined; return 0 end if; if -(1/6)*X < -1 then YP[1] := undefined; return 0 end if; if -2*X < -1 then YP[1] := undefined; return 0 end if; YP[1] := evalf(1/(-12.0454404629703+0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)))^(1/2)); 0 end proc, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), ( 13 ) = (), ( 12 ) = (), ( 15 ) = ("rkf45"), ( 14 ) = ([0, 0]), ( 18 ) = ([]), ( 19 ) = (0), ( 16 ) = ([0, 0, 0, 0, 0, []]), ( 17 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(phi)]`; if 0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)) < 12.0454404629703 then YP[1] := undefined; return 0 end if; if 3672*X < -5717.34108232408 then YP[1] := undefined; return 0 end if; if 3672*X < -5302.56325335595 then YP[1] := undefined; return 0 end if; if -2*X < -2.393827840 then YP[1] := undefined; return 0 end if; if -2*X < -1.814947840 then YP[1] := undefined; return 0 end if; if -(1/6)*X < -1 then YP[1] := undefined; return 0 end if; if -2*X < -1 then YP[1] := undefined; return 0 end if; YP[1] := evalf(1/(-12.0454404629703+0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)))^(1/2)); 0 end proc, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), ( 22 ) = (0), ( 23 ) = (0), ( 20 ) = ([]), ( 21 ) = (0), ( 27 ) = (""), ( 26 ) = (Array(1..0, {})), ( 25 ) = (Array(1..0, {})), ( 24 ) = (0), ( 28 ) = (0)  ] ))  ] ); _y0 := Array(0..1, {(1) = -1.2}); _vmap := array( 1 .. 1, [( 1 ) = (1)  ] ); _x0 := _dtbl[1][5][5]; _n := _dtbl[1][4][1]; _ne := _dtbl[1][4][3]; _nd := _dtbl[1][4][4]; _nv := _dtbl[1][4][16]; if not type(_xout, 'numeric') then if member(_xout, ["start", "left", "right"]) then if _Env_smart_dsolve_numeric = true or _dtbl[1][4][10] = 1 then if _xout = "left" then if type(_dtbl[2], 'table') then return _dtbl[2][5][1] end if elif _xout = "right" then if type(_dtbl[3], 'table') then return _dtbl[3][5][1] end if end if end if; return _dtbl[1][5][5] elif _xout = "method" then return _dtbl[1][15] elif _xout = "storage" then return evalb(_dtbl[1][4][10] = 1) elif _xout = "leftdata" then if not type(_dtbl[2], 'array') then return NULL else return eval(_dtbl[2]) end if elif _xout = "rightdata" then if not type(_dtbl[3], 'array') then return NULL else return eval(_dtbl[3]) end if elif _xout = "enginedata" then return eval(_dtbl[1]) elif _xout = "enginereset" then _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); return NULL elif _xout = "initial" then return procname(_y0[0]) elif _xout = "laxtol" then return _dtbl[`if`(member(_dtbl[4], {2, 3}), _dtbl[4], 1)][5][18] elif _xout = "numfun" then return `if`(member(_dtbl[4], {2, 3}), _dtbl[_dtbl[4]][4][18], 0) elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return procname(_y0[0]), [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "last" then if _dtbl[4] <> 2 and _dtbl[4] <> 3 or _x0-_dtbl[_dtbl[4]][5][1] = 0. then error "no information is available on last computed point" else _xout := _dtbl[_dtbl[4]][5][1] end if elif _xout = "function" then if _dtbl[1][4][33]-2. = 0 then return eval(_dtbl[1][10], 1) else return eval(_dtbl[1][10][1], 1) end if elif _xout = "map" then return copy(_vmap) elif type(_xin, `=`) and type(rhs(_xin), 'list') and member(lhs(_xin), {"initial", "parameters", "initial_and_parameters"}) then _ini, _par := [], []; if lhs(_xin) = "initial" then _ini := rhs(_xin) elif lhs(_xin) = "parameters" then _par := rhs(_xin) elif select(type, rhs(_xin), `=`) <> [] then _par, _ini := selectremove(type, rhs(_xin), `=`) elif nops(rhs(_xin)) < nops(_pars)+1 then error "insufficient data for specification of initial and parameters" else _par := rhs(_xin)[-nops(_pars) .. -1]; _ini := rhs(_xin)[1 .. -nops(_pars)-1] end if; _xout := lhs(_xout); _i := false; if _par <> [] then _i := `dsolve/numeric/process_parameters`(_n, _pars, _par, _y0) end if; if _ini <> [] then _i := `dsolve/numeric/process_initial`(_n-_ne, _ini, _y0, _pars, _vmap) or _i end if; if _i then `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars); if _Env_smart_dsolve_numeric = true and type(_y0[0], 'numeric') and _dtbl[1][4][10] <> 1 then procname("right") := _y0[0]; procname("left") := _y0[0] end if end if; if _xout = "initial" then return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)] elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] else return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)], [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] end if elif _xin = "eventstop" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then return 0 end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 <= _dtbl[5-_i][4][9] then _i := 5-_i; _dtbl[4] := _i; _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) elif 100 <= _dtbl[_i][4][9] then _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) else return 0 end if elif _xin = "eventstatus" then if _nv = 0 then error "this solution has no events" end if; _i := [selectremove(proc (a) options operator, arrow; _dtbl[1][3][1][a, 7] = 1 end proc, {seq(_j, _j = 1 .. round(_dtbl[1][3][1][_nv+1, 1]))})]; return ':-enabled' = _i[1], ':-disabled' = _i[2] elif _xin = "eventclear" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then error "no events to clear" end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 < _dtbl[5-_i][4][9] then _dtbl[4] := 5-_i; _i := 5-_i end if; if _dtbl[_i][4][9] < 100 then error "no events to clear" elif _nv < _dtbl[_i][4][9]-100 then error "event error condition cannot be cleared" else _j := _dtbl[_i][4][9]-100; if irem(round(_dtbl[_i][3][1][_j, 4]), 2) = 1 then error "retriggerable events cannot be cleared" end if; _j := round(_dtbl[_i][3][1][_j, 1]); for _k to _nv do if _dtbl[_i][3][1][_k, 1] = _j then if _dtbl[_i][3][1][_k, 2] = 3 then error "range events cannot be cleared" end if; _dtbl[_i][3][1][_k, 8] := _dtbl[_i][3][1][_nv+1, 8] end if end do; _dtbl[_i][4][17] := 0; _dtbl[_i][4][9] := 0; if _dtbl[1][4][10] = 1 then if _i = 2 then try procname(procname("left")) catch:  end try else try procname(procname("right")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and member(lhs(_xin), {"eventdisable", "eventenable"}) then if _nv = 0 then error "this solution has no events" end if; if type(rhs(_xin), {('list')('posint'), ('set')('posint')}) then _i := {op(rhs(_xin))} elif type(rhs(_xin), 'posint') then _i := {rhs(_xin)} else error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; if select(proc (a) options operator, arrow; _nv < a end proc, _i) <> {} then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _k := {}; for _j to _nv do if member(round(_dtbl[1][3][1][_j, 1]), _i) then _k := `union`(_k, {_j}) end if end do; _i := _k; if lhs(_xin) = "eventdisable" then _dtbl[4] := 0; _j := [evalb(assigned(_dtbl[2]) and member(_dtbl[2][4][17], _i)), evalb(assigned(_dtbl[3]) and member(_dtbl[3][4][17], _i))]; for _k in _i do _dtbl[1][3][1][_k, 7] := 0; if assigned(_dtbl[2]) then _dtbl[2][3][1][_k, 7] := 0 end if; if assigned(_dtbl[3]) then _dtbl[3][3][1][_k, 7] := 0 end if end do; if _j[1] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[2][3][4][_k, 1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to defined init `, _dtbl[2][3][4][_k, 1]); _dtbl[2][3][1][_k, 8] := _dtbl[2][3][4][_k, 1] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to rate hysteresis init `, _dtbl[2][5][24]); _dtbl[2][3][1][_k, 8] := _dtbl[2][5][24] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to initial init `, _x0); _dtbl[2][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to fireinitial init `, _x0-1); _dtbl[2][3][1][_k, 8] := _x0-1 end if end do; _dtbl[2][4][17] := 0; _dtbl[2][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("left")) end if end if; if _j[2] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[3][3][4][_k, 2], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to defined init `, _dtbl[3][3][4][_k, 2]); _dtbl[3][3][1][_k, 8] := _dtbl[3][3][4][_k, 2] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to rate hysteresis init `, _dtbl[3][5][24]); _dtbl[3][3][1][_k, 8] := _dtbl[3][5][24] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to initial init `, _x0); _dtbl[3][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to fireinitial init `, _x0+1); _dtbl[3][3][1][_k, 8] := _x0+1 end if end do; _dtbl[3][4][17] := 0; _dtbl[3][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("right")) end if end if else for _k in _i do _dtbl[1][3][1][_k, 7] := 1 end do; _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); _dtbl[4] := 0; if _dtbl[1][4][10] = 1 then if _x0 <= procname("right") then try procname(procname("right")) catch:  end try end if; if procname("left") <= _x0 then try procname(procname("left")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and lhs(_xin) = "eventfired" then if not type(rhs(_xin), 'list') then error "'eventfired' must be specified as a list" end if; if _nv = 0 then error "this solution has no events" end if; if _dtbl[4] <> 2 and _dtbl[4] <> 3 then error "'direction' must be set prior to calling/setting 'eventfired'" end if; _i := _dtbl[4]; _val := NULL; if not assigned(_EnvEventRetriggerWarned) then _EnvEventRetriggerWarned := false end if; for _k in rhs(_xin) do if type(_k, 'integer') then _src := _k elif type(_k, 'integer' = 'anything') and type(evalf(rhs(_k)), 'numeric') then _k := lhs(_k) = evalf[max(Digits, 18)](rhs(_k)); _src := lhs(_k) else error "'eventfired' entry is not valid: %1", _k end if; if _src < 1 or round(_dtbl[1][3][1][_nv+1, 1]) < _src then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _src := {seq(`if`(_dtbl[1][3][1][_j, 1]-_src = 0., _j, NULL), _j = 1 .. _nv)}; if nops(_src) <> 1 then error "'eventfired' can only be set/queried for root-finding events and time/interval events" end if; _src := _src[1]; if _dtbl[1][3][1][_src, 2] <> 0. and _dtbl[1][3][1][_src, 2]-2. <> 0. then error "'eventfired' can only be set/queried for root-finding events and time/interval events" elif irem(round(_dtbl[1][3][1][_src, 4]), 2) = 1 then if _EnvEventRetriggerWarned = false then WARNING(`'eventfired' has no effect on events that retrigger`) end if; _EnvEventRetriggerWarned := true end if; if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then _val := _val, undefined elif type(_dtbl[_i][3][4][_src, _i-1], 'undefined') or _i = 2 and _dtbl[2][3][1][_src, 8] < _dtbl[2][3][4][_src, 1] or _i = 3 and _dtbl[3][3][4][_src, 2] < _dtbl[3][3][1][_src, 8] then _val := _val, _dtbl[_i][3][1][_src, 8] else _val := _val, _dtbl[_i][3][4][_src, _i-1] end if; if type(_k, `=`) then if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then error "cannot set event code for a rate hysteresis event" end if; userinfo(3, {'events', 'eventreset'}, `manual set event code `, _src, ` to value `, rhs(_k)); _dtbl[_i][3][1][_src, 8] := rhs(_k); _dtbl[_i][3][4][_src, _i-1] := rhs(_k) end if end do; return [_val] elif type(_xin, `=`) and lhs(_xin) = "direction" then if not member(rhs(_xin), {-1, 1, ':-left', ':-right'}) then error "'direction' must be specified as either '1' or 'right' (positive) or '-1' or 'left' (negative)" end if; _src := `if`(_dtbl[4] = 2, -1, `if`(_dtbl[4] = 3, 1, undefined)); _i := `if`(member(rhs(_xin), {1, ':-right'}), 3, 2); _dtbl[4] := _i; _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if; return _src elif _xin = "eventcount" then if _dtbl[1][3][1] = 0 or _dtbl[4] <> 2 and _dtbl[4] <> 3 then return 0 else return round(_dtbl[_dtbl[4]][3][1][_nv+1, 12]) end if elif type(_xin, `=`) and lhs(_xin) = "setdatacallback" then if not type(rhs(_xin), 'nonegint') then error "data callback must be a nonnegative integer (address)" end if; _dtbl[1][28] := rhs(_xin) else return "procname" end if end if; if _xout = _x0 then return [_x0, seq(evalf(_dtbl[1][6][_vmap[_i]]), _i = 1 .. _n-_ne)] end if; _i := `if`(_x0 <= _xout, 3, 2); if _xin = "last" and 0 < _dtbl[_i][4][9] and _dtbl[_i][4][9] < 100 then _dat := eval(_dtbl[_i], 2); _j := _dat[4][20]; return [_dat[11][_j, 0], seq(_dat[11][_j, _vmap[_i]], _i = 1 .. _n-_ne-_nd), seq(_dat[8][1][_vmap[_i]], _i = _n-_ne-_nd+1 .. _n-_ne)] end if; if not type(_dtbl[_i], 'array') then _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if end if; if _xin <> "last" then if 0 < 0 then if `dsolve/numeric/checkglobals`(op(_dtbl[1][14]), _pars, _n, _y0) then `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars, _i) end if end if; if _dtbl[1][4][7] = 0 then error "parameters must be initialized before solution can be computed" end if end if; _dat := eval(_dtbl[_i], 2); _dtbl[4] := _i; try _src := `dsolve/numeric/SC/IVPrun`(_dat, _xout) catch: userinfo(2, `dsolve/debug`, print(`Exception in solnproc:`, [lastexception][2 .. -1])); error  end try; if _dat[17] <> _dtbl[1][17] then _dtbl[1][17] := _dat[17]; _dtbl[1][10] := _dat[10] end if; if _src = 0 and 100 < _dat[4][9] then _val := _dat[3][1][_nv+1, 8] else _val := _dat[11][_dat[4][20], 0] end if; if _src <> 0 or _dat[4][9] <= 0 then _dtbl[1][5][1] := _xout else _dtbl[1][5][1] := _val end if; if _i = 3 and _val < _xout then Rounding := -infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further right of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further right of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further right of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further right of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further right of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further right of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further right of %1", evalf[8](_val) end if elif _i = 2 and _xout < _val then Rounding := infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further left of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further left of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further left of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further left of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further left of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further left of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further left of %1", evalf[8](_val) end if end if; if _EnvInFsolve = true then _dig := _dat[4][26]; if type(_EnvDSNumericSaveDigits, 'posint') then _dat[4][26] := _EnvDSNumericSaveDigits else _dat[4][26] := Digits end if; _Env_dsolve_SC_native := true; if _dat[4][25] = 1 then _i := 1; _dat[4][25] := 2 else _i := _dat[4][25] end if; _val := `dsolve/numeric/SC/IVPval`(_dat, _xout, _src); _dat[4][25] := _i; _dat[4][26] := _dig; [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] else Digits := _dat[4][26]; _val := `dsolve/numeric/SC/IVPval`(eval(_dat, 2), _xout, _src); [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] end if end proc, (2) = Array(0..0, {}), (3) = [phi, x(phi)], (4) = []}); _vars := _dat[3]; _pars := map(rhs, _dat[4]); _n := nops(_vars)-1; _solnproc := _dat[1]; if not type(_xout, 'numeric') then if member(x_rkf45, ["start", 'start', "method", 'method', "left", 'left', "right", 'right', "leftdata", "rightdata", "enginedata", "eventstop", 'eventstop', "eventclear", 'eventclear', "eventstatus", 'eventstatus', "eventcount", 'eventcount', "laxtol", 'laxtol', "numfun", 'numfun', NULL]) then _res := _solnproc(convert(x_rkf45, 'string')); if 1 < nops([_res]) then return _res elif type(_res, 'array') then return eval(_res, 1) elif _res <> "procname" then return _res end if elif member(x_rkf45, ["last", 'last', "initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(x_rkf45, 'string'); _res := _solnproc(_xout); if _xout = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] end if elif type(_xout, `=`) and member(lhs(_xout), ["initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(lhs(x_rkf45), 'string') = rhs(x_rkf45); if type(rhs(_xout), 'list') then _res := _solnproc(_xout) else error "initial and/or parameter values must be specified in a list" end if; if lhs(_xout) = "initial" then return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] elif lhs(_xout) = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] end if elif type(_xout, `=`) and member(lhs(_xout), ["eventdisable", 'eventdisable', "eventenable", 'eventenable', "eventfired", 'eventfired', "direction", 'direction', NULL]) then return _solnproc(convert(lhs(x_rkf45), 'string') = rhs(x_rkf45)) elif _xout = "solnprocedure" then return eval(_solnproc) elif _xout = "sysvars" then return _vars end if; if procname <> unknown then return ('procname')(x_rkf45) else _ndsol := 1; _ndsol := _ndsol; _ndsol := pointto(_dat[2][0]); return ('_ndsol')(x_rkf45) end if end if; try _res := _solnproc(_xout); [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] catch: error  end try end proc

Fails close to zero while still increasing, suggestng that the area might be infinite

p1:=plots:-odeplot(ans1,[phi,x(phi)],-1.2..0.5): display(p1);

Warning, cannot evaluate the solution further right of -.97056569e-3, probably a singularity

Restart integration on the other side of zero

ans2:=dsolve({ode,x(1e-2)=0},numeric);

proc (x_rkf45) local _res, _dat, _vars, _solnproc, _xout, _ndsol, _pars, _n, _i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; if 1 < nargs then error "invalid input: too many arguments" end if; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then _xout := evalf[_EnvDSNumericSaveDigits](x_rkf45) else _xout := evalf(x_rkf45) end if; _dat := Array(1..4, {(1) = proc (_xin) local _xout, _dtbl, _dat, _vmap, _x0, _y0, _val, _dig, _n, _ne, _nd, _nv, _pars, _ini, _par, _i, _j, _k, _src; option `Copyright (c) 2002 by Waterloo Maple Inc. All rights reserved.`; table( [( "complex" ) = false ] ) _xout := _xin; _pars := []; _dtbl := array( 1 .. 4, [( 1 ) = (array( 1 .. 28, [( 1 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 2 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 3 ) = ([0, 0, 0, Array(1..0, 1..2, {}, datatype = float[8], order = C_order)]), ( 4 ) = (Array(1..65, {(1) = 1, (2) = 1, (3) = 0, (4) = 0, (5) = 0, (6) = 0, (7) = 1, (8) = 0, (9) = 0, (10) = 0, (11) = 0, (12) = 0, (13) = 0, (14) = 0, (15) = 0, (16) = 0, (17) = 0, (18) = 1, (19) = 30000, (20) = 0, (21) = 0, (22) = 1, (23) = 4, (24) = 0, (25) = 1, (26) = 15, (27) = 1, (28) = 0, (29) = 1, (30) = 3, (31) = 3, (32) = 0, (33) = 1, (34) = 0, (35) = 0, (36) = 0, (37) = 0, (38) = 0, (39) = 0, (40) = 0, (41) = 0, (42) = 0, (43) = 1, (44) = 0, (45) = 0, (46) = 0, (47) = 0, (48) = 0, (49) = 0, (50) = 50, (51) = 1, (52) = 0, (53) = 0, (54) = 0, (55) = 0, (56) = 0, (57) = 0, (58) = 0, (59) = 10000, (60) = 0, (61) = 1000, (62) = 0, (63) = 0, (64) = -1, (65) = 0}, datatype = integer[8])), ( 5 ) = (Array(1..28, {(1) = 0.1e-1, (2) = 0.10e-5, (3) = .0, (4) = 0.500001e-14, (5) = 0.1e-1, (6) = 0.15908870632545985e-5, (7) = .0, (8) = 0.10e-5, (9) = .0, (10) = .0, (11) = .0, (12) = .0, (13) = 1.0, (14) = .0, (15) = .49999999999999, (16) = .0, (17) = 1.0, (18) = 1.0, (19) = .0, (20) = .0, (21) = 1.0, (22) = 1.0, (23) = .0, (24) = .0, (25) = 0.10e-14, (26) = .0, (27) = .0, (28) = .0}, datatype = float[8], order = C_order)), ( 6 ) = (Array(1..1, {(1) = .0}, datatype = float[8], order = C_order)), ( 7 ) = ([Array(1..4, 1..7, {(1, 1) = .0, (1, 2) = .203125, (1, 3) = .3046875, (1, 4) = .75, (1, 5) = .8125, (1, 6) = .40625, (1, 7) = .8125, (2, 1) = 0.6378173828125e-1, (2, 2) = .0, (2, 3) = .279296875, (2, 4) = .27237892150878906, (2, 5) = -0.9686851501464844e-1, (2, 6) = 0.1956939697265625e-1, (2, 7) = .5381584167480469, (3, 1) = 0.31890869140625e-1, (3, 2) = .0, (3, 3) = -.34375, (3, 4) = -.335235595703125, (3, 5) = .2296142578125, (3, 6) = .41748046875, (3, 7) = 11.480712890625, (4, 1) = 0.9710520505905151e-1, (4, 2) = .0, (4, 3) = .40350341796875, (4, 4) = 0.20297467708587646e-1, (4, 5) = -0.6054282188415527e-2, (4, 6) = -0.4770040512084961e-1, (4, 7) = .77858567237854}, datatype = float[8], order = C_order), Array(1..6, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = 1.0, (2, 1) = .25, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (2, 6) = 1.0, (3, 1) = .1875, (3, 2) = .5625, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (3, 6) = 2.0, (4, 1) = .23583984375, (4, 2) = -.87890625, (4, 3) = .890625, (4, 4) = .0, (4, 5) = .0, (4, 6) = .2681884765625, (5, 1) = .1272735595703125, (5, 2) = -.5009765625, (5, 3) = .44921875, (5, 4) = -0.128936767578125e-1, (5, 5) = .0, (5, 6) = 0.626220703125e-1, (6, 1) = -0.927734375e-1, (6, 2) = .626220703125, (6, 3) = -.4326171875, (6, 4) = .1418304443359375, (6, 5) = -0.861053466796875e-1, (6, 6) = .3131103515625}, datatype = float[8], order = C_order), Array(1..6, {(1) = .0, (2) = .386, (3) = .21, (4) = .63, (5) = 1.0, (6) = 1.0}, datatype = float[8], order = C_order), Array(1..6, {(1) = .25, (2) = -.1043, (3) = .1035, (4) = -0.362e-1, (5) = .0, (6) = .0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 1.544, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = .9466785280815533, (3, 2) = .25570116989825814, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = 3.3148251870684886, (4, 2) = 2.896124015972123, (4, 3) = .9986419139977808, (4, 4) = .0, (4, 5) = .0, (5, 1) = 1.2212245092262748, (5, 2) = 6.019134481287752, (5, 3) = 12.537083329320874, (5, 4) = -.687886036105895, (5, 5) = .0, (6, 1) = 1.2212245092262748, (6, 2) = 6.019134481287752, (6, 3) = 12.537083329320874, (6, 4) = -.687886036105895, (6, 5) = 1.0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = -5.6688, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = -2.4300933568337584, (3, 2) = -.20635991570891224, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = -.10735290581452621, (4, 2) = -9.594562251021896, (4, 3) = -20.470286148096154, (4, 4) = .0, (4, 5) = .0, (5, 1) = 7.496443313968615, (5, 2) = -10.246804314641219, (5, 3) = -33.99990352819906, (5, 4) = 11.708908932061595, (5, 5) = .0, (6, 1) = 8.083246795922411, (6, 2) = -7.981132988062785, (6, 3) = -31.52159432874373, (6, 4) = 16.319305431231363, (6, 5) = -6.0588182388340535}, datatype = float[8], order = C_order), Array(1..3, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 10.126235083446911, (2, 2) = -7.487995877607633, (2, 3) = -34.800918615557414, (2, 4) = -7.9927717075687275, (2, 5) = 1.0251377232956207, (3, 1) = -.6762803392806898, (3, 2) = 6.087714651678606, (3, 3) = 16.43084320892463, (3, 4) = 24.767225114183653, (3, 5) = -6.5943891257167815}, datatype = float[8], order = C_order)]), ( 9 ) = ([Array(1..1, {(1) = .1}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..1, {(1, 1) = .0}, datatype = float[8], order = C_order), Array(1..1, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 0}, datatype = integer[8]), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 0}, datatype = integer[8])]), ( 8 ) = ([Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = .0}, datatype = float[8], order = C_order), Array(1..1, {(1) = 3172.858006347206}, datatype = float[8], order = C_order), 0, 0]), ( 11 ) = (Array(1..6, 0..1, {(1, 1) = .0, (2, 0) = .0, (2, 1) = .0, (3, 0) = .0, (3, 1) = .0, (4, 0) = .0, (4, 1) = .0, (5, 0) = .0, (5, 1) = .0, (6, 0) = .0, (6, 1) = .0}, datatype = float[8], order = C_order)), ( 10 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(phi)]`; if 0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)) < 12.0454404629703 then YP[1] := undefined; return 0 end if; if 3672*X < -5717.34108232408 then YP[1] := undefined; return 0 end if; if 3672*X < -5302.56325335595 then YP[1] := undefined; return 0 end if; if -2*X < -2.393827840 then YP[1] := undefined; return 0 end if; if -2*X < -1.814947840 then YP[1] := undefined; return 0 end if; if -(1/6)*X < -1 then YP[1] := undefined; return 0 end if; if -2*X < -1 then YP[1] := undefined; return 0 end if; YP[1] := evalf(1/(-12.0454404629703+0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)))^(1/2)); 0 end proc, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), ( 13 ) = (), ( 12 ) = (), ( 15 ) = ("rkf45"), ( 14 ) = ([0, 0]), ( 18 ) = ([]), ( 19 ) = (0), ( 16 ) = ([0, 0, 0, 0, 0, []]), ( 17 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(phi)]`; if 0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)) < 12.0454404629703 then YP[1] := undefined; return 0 end if; if 3672*X < -5717.34108232408 then YP[1] := undefined; return 0 end if; if 3672*X < -5302.56325335595 then YP[1] := undefined; return 0 end if; if -2*X < -2.393827840 then YP[1] := undefined; return 0 end if; if -2*X < -1.814947840 then YP[1] := undefined; return 0 end if; if -(1/6)*X < -1 then YP[1] := undefined; return 0 end if; if -2*X < -1 then YP[1] := undefined; return 0 end if; YP[1] := evalf(1/(-12.0454404629703+0.49998e-1*evalf(1/(1-2*X)^(1/2))+7.800*evalf(1/(1-(1/6)*X)^(3/2))+0.244629654926413e-11*evalf((5717.34108232408+3672*X)^(3/2))-0.244629654926413e-11*evalf((5302.56325335595+3672*X)^(3/2))+(10/3)*evalf((2.393827840-2*X)^(3/2))-(10/3)*evalf((1.814947840-2*X)^(3/2)))^(1/2)); 0 end proc, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), ( 22 ) = (0), ( 23 ) = (0), ( 20 ) = ([]), ( 21 ) = (0), ( 27 ) = (""), ( 26 ) = (Array(1..0, {})), ( 25 ) = (Array(1..0, {})), ( 24 ) = (0), ( 28 ) = (0)  ] ))  ] ); _y0 := Array(0..1, {(1) = 0.1e-1}); _vmap := array( 1 .. 1, [( 1 ) = (1)  ] ); _x0 := _dtbl[1][5][5]; _n := _dtbl[1][4][1]; _ne := _dtbl[1][4][3]; _nd := _dtbl[1][4][4]; _nv := _dtbl[1][4][16]; if not type(_xout, 'numeric') then if member(_xout, ["start", "left", "right"]) then if _Env_smart_dsolve_numeric = true or _dtbl[1][4][10] = 1 then if _xout = "left" then if type(_dtbl[2], 'table') then return _dtbl[2][5][1] end if elif _xout = "right" then if type(_dtbl[3], 'table') then return _dtbl[3][5][1] end if end if end if; return _dtbl[1][5][5] elif _xout = "method" then return _dtbl[1][15] elif _xout = "storage" then return evalb(_dtbl[1][4][10] = 1) elif _xout = "leftdata" then if not type(_dtbl[2], 'array') then return NULL else return eval(_dtbl[2]) end if elif _xout = "rightdata" then if not type(_dtbl[3], 'array') then return NULL else return eval(_dtbl[3]) end if elif _xout = "enginedata" then return eval(_dtbl[1]) elif _xout = "enginereset" then _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); return NULL elif _xout = "initial" then return procname(_y0[0]) elif _xout = "laxtol" then return _dtbl[`if`(member(_dtbl[4], {2, 3}), _dtbl[4], 1)][5][18] elif _xout = "numfun" then return `if`(member(_dtbl[4], {2, 3}), _dtbl[_dtbl[4]][4][18], 0) elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return procname(_y0[0]), [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "last" then if _dtbl[4] <> 2 and _dtbl[4] <> 3 or _x0-_dtbl[_dtbl[4]][5][1] = 0. then error "no information is available on last computed point" else _xout := _dtbl[_dtbl[4]][5][1] end if elif _xout = "function" then if _dtbl[1][4][33]-2. = 0 then return eval(_dtbl[1][10], 1) else return eval(_dtbl[1][10][1], 1) end if elif _xout = "map" then return copy(_vmap) elif type(_xin, `=`) and type(rhs(_xin), 'list') and member(lhs(_xin), {"initial", "parameters", "initial_and_parameters"}) then _ini, _par := [], []; if lhs(_xin) = "initial" then _ini := rhs(_xin) elif lhs(_xin) = "parameters" then _par := rhs(_xin) elif select(type, rhs(_xin), `=`) <> [] then _par, _ini := selectremove(type, rhs(_xin), `=`) elif nops(rhs(_xin)) < nops(_pars)+1 then error "insufficient data for specification of initial and parameters" else _par := rhs(_xin)[-nops(_pars) .. -1]; _ini := rhs(_xin)[1 .. -nops(_pars)-1] end if; _xout := lhs(_xout); _i := false; if _par <> [] then _i := `dsolve/numeric/process_parameters`(_n, _pars, _par, _y0) end if; if _ini <> [] then _i := `dsolve/numeric/process_initial`(_n-_ne, _ini, _y0, _pars, _vmap) or _i end if; if _i then `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars); if _Env_smart_dsolve_numeric = true and type(_y0[0], 'numeric') and _dtbl[1][4][10] <> 1 then procname("right") := _y0[0]; procname("left") := _y0[0] end if end if; if _xout = "initial" then return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)] elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] else return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)], [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] end if elif _xin = "eventstop" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then return 0 end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 <= _dtbl[5-_i][4][9] then _i := 5-_i; _dtbl[4] := _i; _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) elif 100 <= _dtbl[_i][4][9] then _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) else return 0 end if elif _xin = "eventstatus" then if _nv = 0 then error "this solution has no events" end if; _i := [selectremove(proc (a) options operator, arrow; _dtbl[1][3][1][a, 7] = 1 end proc, {seq(_j, _j = 1 .. round(_dtbl[1][3][1][_nv+1, 1]))})]; return ':-enabled' = _i[1], ':-disabled' = _i[2] elif _xin = "eventclear" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then error "no events to clear" end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 < _dtbl[5-_i][4][9] then _dtbl[4] := 5-_i; _i := 5-_i end if; if _dtbl[_i][4][9] < 100 then error "no events to clear" elif _nv < _dtbl[_i][4][9]-100 then error "event error condition cannot be cleared" else _j := _dtbl[_i][4][9]-100; if irem(round(_dtbl[_i][3][1][_j, 4]), 2) = 1 then error "retriggerable events cannot be cleared" end if; _j := round(_dtbl[_i][3][1][_j, 1]); for _k to _nv do if _dtbl[_i][3][1][_k, 1] = _j then if _dtbl[_i][3][1][_k, 2] = 3 then error "range events cannot be cleared" end if; _dtbl[_i][3][1][_k, 8] := _dtbl[_i][3][1][_nv+1, 8] end if end do; _dtbl[_i][4][17] := 0; _dtbl[_i][4][9] := 0; if _dtbl[1][4][10] = 1 then if _i = 2 then try procname(procname("left")) catch:  end try else try procname(procname("right")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and member(lhs(_xin), {"eventdisable", "eventenable"}) then if _nv = 0 then error "this solution has no events" end if; if type(rhs(_xin), {('list')('posint'), ('set')('posint')}) then _i := {op(rhs(_xin))} elif type(rhs(_xin), 'posint') then _i := {rhs(_xin)} else error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; if select(proc (a) options operator, arrow; _nv < a end proc, _i) <> {} then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _k := {}; for _j to _nv do if member(round(_dtbl[1][3][1][_j, 1]), _i) then _k := `union`(_k, {_j}) end if end do; _i := _k; if lhs(_xin) = "eventdisable" then _dtbl[4] := 0; _j := [evalb(assigned(_dtbl[2]) and member(_dtbl[2][4][17], _i)), evalb(assigned(_dtbl[3]) and member(_dtbl[3][4][17], _i))]; for _k in _i do _dtbl[1][3][1][_k, 7] := 0; if assigned(_dtbl[2]) then _dtbl[2][3][1][_k, 7] := 0 end if; if assigned(_dtbl[3]) then _dtbl[3][3][1][_k, 7] := 0 end if end do; if _j[1] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[2][3][4][_k, 1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to defined init `, _dtbl[2][3][4][_k, 1]); _dtbl[2][3][1][_k, 8] := _dtbl[2][3][4][_k, 1] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to rate hysteresis init `, _dtbl[2][5][24]); _dtbl[2][3][1][_k, 8] := _dtbl[2][5][24] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to initial init `, _x0); _dtbl[2][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to fireinitial init `, _x0-1); _dtbl[2][3][1][_k, 8] := _x0-1 end if end do; _dtbl[2][4][17] := 0; _dtbl[2][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("left")) end if end if; if _j[2] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[3][3][4][_k, 2], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to defined init `, _dtbl[3][3][4][_k, 2]); _dtbl[3][3][1][_k, 8] := _dtbl[3][3][4][_k, 2] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to rate hysteresis init `, _dtbl[3][5][24]); _dtbl[3][3][1][_k, 8] := _dtbl[3][5][24] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to initial init `, _x0); _dtbl[3][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to fireinitial init `, _x0+1); _dtbl[3][3][1][_k, 8] := _x0+1 end if end do; _dtbl[3][4][17] := 0; _dtbl[3][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("right")) end if end if else for _k in _i do _dtbl[1][3][1][_k, 7] := 1 end do; _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); _dtbl[4] := 0; if _dtbl[1][4][10] = 1 then if _x0 <= procname("right") then try procname(procname("right")) catch:  end try end if; if procname("left") <= _x0 then try procname(procname("left")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and lhs(_xin) = "eventfired" then if not type(rhs(_xin), 'list') then error "'eventfired' must be specified as a list" end if; if _nv = 0 then error "this solution has no events" end if; if _dtbl[4] <> 2 and _dtbl[4] <> 3 then error "'direction' must be set prior to calling/setting 'eventfired'" end if; _i := _dtbl[4]; _val := NULL; if not assigned(_EnvEventRetriggerWarned) then _EnvEventRetriggerWarned := false end if; for _k in rhs(_xin) do if type(_k, 'integer') then _src := _k elif type(_k, 'integer' = 'anything') and type(evalf(rhs(_k)), 'numeric') then _k := lhs(_k) = evalf[max(Digits, 18)](rhs(_k)); _src := lhs(_k) else error "'eventfired' entry is not valid: %1", _k end if; if _src < 1 or round(_dtbl[1][3][1][_nv+1, 1]) < _src then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _src := {seq(`if`(_dtbl[1][3][1][_j, 1]-_src = 0., _j, NULL), _j = 1 .. _nv)}; if nops(_src) <> 1 then error "'eventfired' can only be set/queried for root-finding events and time/interval events" end if; _src := _src[1]; if _dtbl[1][3][1][_src, 2] <> 0. and _dtbl[1][3][1][_src, 2]-2. <> 0. then error "'eventfired' can only be set/queried for root-finding events and time/interval events" elif irem(round(_dtbl[1][3][1][_src, 4]), 2) = 1 then if _EnvEventRetriggerWarned = false then WARNING(`'eventfired' has no effect on events that retrigger`) end if; _EnvEventRetriggerWarned := true end if; if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then _val := _val, undefined elif type(_dtbl[_i][3][4][_src, _i-1], 'undefined') or _i = 2 and _dtbl[2][3][1][_src, 8] < _dtbl[2][3][4][_src, 1] or _i = 3 and _dtbl[3][3][4][_src, 2] < _dtbl[3][3][1][_src, 8] then _val := _val, _dtbl[_i][3][1][_src, 8] else _val := _val, _dtbl[_i][3][4][_src, _i-1] end if; if type(_k, `=`) then if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then error "cannot set event code for a rate hysteresis event" end if; userinfo(3, {'events', 'eventreset'}, `manual set event code `, _src, ` to value `, rhs(_k)); _dtbl[_i][3][1][_src, 8] := rhs(_k); _dtbl[_i][3][4][_src, _i-1] := rhs(_k) end if end do; return [_val] elif type(_xin, `=`) and lhs(_xin) = "direction" then if not member(rhs(_xin), {-1, 1, ':-left', ':-right'}) then error "'direction' must be specified as either '1' or 'right' (positive) or '-1' or 'left' (negative)" end if; _src := `if`(_dtbl[4] = 2, -1, `if`(_dtbl[4] = 3, 1, undefined)); _i := `if`(member(rhs(_xin), {1, ':-right'}), 3, 2); _dtbl[4] := _i; _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if; return _src elif _xin = "eventcount" then if _dtbl[1][3][1] = 0 or _dtbl[4] <> 2 and _dtbl[4] <> 3 then return 0 else return round(_dtbl[_dtbl[4]][3][1][_nv+1, 12]) end if elif type(_xin, `=`) and lhs(_xin) = "setdatacallback" then if not type(rhs(_xin), 'nonegint') then error "data callback must be a nonnegative integer (address)" end if; _dtbl[1][28] := rhs(_xin) else return "procname" end if end if; if _xout = _x0 then return [_x0, seq(evalf(_dtbl[1][6][_vmap[_i]]), _i = 1 .. _n-_ne)] end if; _i := `if`(_x0 <= _xout, 3, 2); if _xin = "last" and 0 < _dtbl[_i][4][9] and _dtbl[_i][4][9] < 100 then _dat := eval(_dtbl[_i], 2); _j := _dat[4][20]; return [_dat[11][_j, 0], seq(_dat[11][_j, _vmap[_i]], _i = 1 .. _n-_ne-_nd), seq(_dat[8][1][_vmap[_i]], _i = _n-_ne-_nd+1 .. _n-_ne)] end if; if not type(_dtbl[_i], 'array') then _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if end if; if _xin <> "last" then if 0 < 0 then if `dsolve/numeric/checkglobals`(op(_dtbl[1][14]), _pars, _n, _y0) then `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars, _i) end if end if; if _dtbl[1][4][7] = 0 then error "parameters must be initialized before solution can be computed" end if end if; _dat := eval(_dtbl[_i], 2); _dtbl[4] := _i; try _src := `dsolve/numeric/SC/IVPrun`(_dat, _xout) catch: userinfo(2, `dsolve/debug`, print(`Exception in solnproc:`, [lastexception][2 .. -1])); error  end try; if _dat[17] <> _dtbl[1][17] then _dtbl[1][17] := _dat[17]; _dtbl[1][10] := _dat[10] end if; if _src = 0 and 100 < _dat[4][9] then _val := _dat[3][1][_nv+1, 8] else _val := _dat[11][_dat[4][20], 0] end if; if _src <> 0 or _dat[4][9] <= 0 then _dtbl[1][5][1] := _xout else _dtbl[1][5][1] := _val end if; if _i = 3 and _val < _xout then Rounding := -infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further right of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further right of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further right of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further right of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further right of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further right of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further right of %1", evalf[8](_val) end if elif _i = 2 and _xout < _val then Rounding := infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further left of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further left of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further left of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further left of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further left of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further left of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further left of %1", evalf[8](_val) end if end if; if _EnvInFsolve = true then _dig := _dat[4][26]; if type(_EnvDSNumericSaveDigits, 'posint') then _dat[4][26] := _EnvDSNumericSaveDigits else _dat[4][26] := Digits end if; _Env_dsolve_SC_native := true; if _dat[4][25] = 1 then _i := 1; _dat[4][25] := 2 else _i := _dat[4][25] end if; _val := `dsolve/numeric/SC/IVPval`(_dat, _xout, _src); _dat[4][25] := _i; _dat[4][26] := _dig; [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] else Digits := _dat[4][26]; _val := `dsolve/numeric/SC/IVPval`(eval(_dat, 2), _xout, _src); [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] end if end proc, (2) = Array(0..0, {}), (3) = [phi, x(phi)], (4) = []}); _vars := _dat[3]; _pars := map(rhs, _dat[4]); _n := nops(_vars)-1; _solnproc := _dat[1]; if not type(_xout, 'numeric') then if member(x_rkf45, ["start", 'start', "method", 'method', "left", 'left', "right", 'right', "leftdata", "rightdata", "enginedata", "eventstop", 'eventstop', "eventclear", 'eventclear', "eventstatus", 'eventstatus', "eventcount", 'eventcount', "laxtol", 'laxtol', "numfun", 'numfun', NULL]) then _res := _solnproc(convert(x_rkf45, 'string')); if 1 < nops([_res]) then return _res elif type(_res, 'array') then return eval(_res, 1) elif _res <> "procname" then return _res end if elif member(x_rkf45, ["last", 'last', "initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(x_rkf45, 'string'); _res := _solnproc(_xout); if _xout = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] end if elif type(_xout, `=`) and member(lhs(_xout), ["initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(lhs(x_rkf45), 'string') = rhs(x_rkf45); if type(rhs(_xout), 'list') then _res := _solnproc(_xout) else error "initial and/or parameter values must be specified in a list" end if; if lhs(_xout) = "initial" then return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] elif lhs(_xout) = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] end if elif type(_xout, `=`) and member(lhs(_xout), ["eventdisable", 'eventdisable', "eventenable", 'eventenable', "eventfired", 'eventfired', "direction", 'direction', NULL]) then return _solnproc(convert(lhs(x_rkf45), 'string') = rhs(x_rkf45)) elif _xout = "solnprocedure" then return eval(_solnproc) elif _xout = "sysvars" then return _vars end if; if procname <> unknown then return ('procname')(x_rkf45) else _ndsol := 1; _ndsol := _ndsol; _ndsol := pointto(_dat[2][0]); return ('_ndsol')(x_rkf45) end if end if; try _res := _solnproc(_xout); [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] catch: error  end try end proc

p2:=plots:-odeplot(ans2,[phi,x(phi)],1e-2..0.4): display(p2);

NULL

``

Download Integral-New.mw

 

Although you have to return to the starting point, you can force it to return via the last vertex by using a directed graph, and so find the shortest path between the first and last vertices. I'm not sure I fully understood your description, so this may not be exactly what you want. I worked out edge distances from coordinates, but you could just enter edge weights for each edge.

restart

with(GraphTheory)

We want shortest distance between first and last vertex (1 and 5 here) that visits all vertices
List of coordinates of points labeled 1..n

pts := [[0, 0], [1, 2], [4, 2], [3, 1], [5, 1]]; n := nops(pts)

[[0, 0], [1, 2], [4, 2], [3, 1], [5, 1]]

5

Edges between points - include edge {1,5} between start and end vertices

edges := {{1, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {3, 5}, {4, 5}}

{{1, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {3, 5}, {4, 5}}

Find geometric distances along edges

weights1 := Matrix(n, n, shape = symmetric); for edge in edges do pt1, pt2 := edge[]; weights1[pt1, pt2] := evalf(Student:-Precalculus:-Distance(pts[pt1], pts[pt2])) end do

Ensure return is via vertex 5 and not any other neighbors of vertex 1

weights := Matrix(convert(weights1, listlist)); for j to n-1 do weights[j, 1] := 0 end do; weights[1, n] := 0

weights

Matrix(%id = 36893489987961631676)

G := Graph(weights); SetVertexPositions(G, pts)

GRAPHLN(directed, weighted, [1, 2, 3, 4, 5], Array(1..5, {(1) = {2, 4}, (2) = {3, 4}, (3) = {2, 5}, (4) = {2, 5}, (5) = {1, 3, 4}}), `GRAPHLN/table/1`, Matrix(5, 5, {(1, 1) = 0, (1, 2) = 2.236067977, (1, 3) = 0, (1, 4) = 3.162277660, (1, 5) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 3., (2, 4) = 2.236067977, (2, 5) = 0, (3, 1) = 0, (3, 2) = 3., (3, 3) = 0, (3, 4) = 0, (3, 5) = 1.414213562, (4, 1) = 0, (4, 2) = 2.236067977, (4, 3) = 0, (4, 4) = 0, (4, 5) = 2., (5, 1) = 5.099019514, (5, 2) = 0, (5, 3) = 1.414213562, (5, 4) = 2., (5, 5) = 0}))

DrawGraph(G)

w, tour := TravelingSalesman(G, startvertex = 1, solver = legacy)

14.91157871, [1, 4, 2, 3, 5, 1]

pathdist := w-weights[n, 1]

9.812559196

NULL

Download TravelingSalesman.mw

Here's a way that avoids using the known result for the othogonality. On the other hand it should be easier than finding a generating function...

restart;
with(PDEtools):
#with(Maplets[Elements]):

eq0:= E1 = (n+1/2)*_h; param := m1 =_h*sigma^2;

E1 = (n+1/2)*_h

m1 = _h*sigma^2

os := expand(isolate((-_h^2/(2*m1))*diff(psi(x),x,x)+(m1*x^2/2)*psi(x)-E1*psi(x)=0,diff(psi(x),x,x)));

diff(diff(psi(x), x), x) = m1^2*x^2*psi(x)/_h^2-2*m1*E1*psi(x)/_h^2

eq1 := PDEtools:-dchange([x=sqrt(_h/m1)*zeta,psi(x)=f(zeta)*exp(-zeta^2/2)],os,[zeta,f(zeta)],params={m1,_h,E1});
eq2 := expand(isolate(eq1,diff(f(zeta),zeta$2)));
eq3 := simplify(eval(remove(has,convert(rhs(dsolve(eq2,f(zeta))),Hermite),KummerM),eq0)*exp(-zeta^2/2),radical)       assuming zeta::positive;
eq4 := simplify(subs(param,simplify(subs(zeta=sqrt(_h/m1)*x,eq3)))) assuming sigma::positive;
eq5 := unapply(eq4,n,x,sigma);

((diff(diff(f(zeta), zeta), zeta))*exp(-(1/2)*zeta^2)-2*(diff(f(zeta), zeta))*zeta*exp(-(1/2)*zeta^2)-f(zeta)*exp(-(1/2)*zeta^2)+f(zeta)*zeta^2*exp(-(1/2)*zeta^2))*m1/_h = m1*zeta^2*f(zeta)*exp(-(1/2)*zeta^2)/_h-2*m1*E1*f(zeta)*exp(-(1/2)*zeta^2)/_h^2

diff(diff(f(zeta), zeta), zeta) = -2*E1*f(zeta)/_h+2*(diff(f(zeta), zeta))*zeta+f(zeta)

c__2*HermiteH(n, zeta)*exp(-(1/2)*zeta^2)/2^n

c__2*HermiteH(n, x/sigma)*2^(-n)*exp(-(1/2)*x^2/sigma^2)

proc (n, x, sigma) options operator, arrow; c__2*HermiteH(n, x/sigma)*2^(-n)*exp(-(1/2)*x^2/sigma^2) end proc

Work out the first few integrals

ints:=[seq(int(simplify(eq5(n,x,sigma)^2,'HermiteH'),x=-infinity..infinity),n=0..10)] assuming positive;

[c__2^2*sigma*Pi^(1/2), (1/2)*c__2^2*sigma*Pi^(1/2), (1/2)*c__2^2*sigma*Pi^(1/2), (3/4)*c__2^2*sigma*Pi^(1/2), (3/2)*c__2^2*sigma*Pi^(1/2), (15/4)*c__2^2*sigma*Pi^(1/2), (45/4)*c__2^2*sigma*Pi^(1/2), (315/8)*c__2^2*sigma*Pi^(1/2), (315/2)*c__2^2*sigma*Pi^(1/2), (2835/4)*c__2^2*sigma*Pi^(1/2), (14175/4)*c__2^2*sigma*Pi^(1/2)]

Find out the pattern

gfun:-guessgf(ints,x);
gf:=%[1]:
series(gf,x,11):
[op(convert(%,polynom))]:
seq(%[i]*(i-1)!,i=1..nops(%));

[2*c__2^2*sigma*Pi/(-Pi^(1/2)*x+2*Pi^(1/2)), egf]

c__2^2*sigma*Pi^(1/2), (1/2)*c__2^2*sigma*Pi^(1/2)*x, (1/2)*c__2^2*sigma*Pi^(1/2)*x^2, (3/4)*c__2^2*sigma*Pi^(1/2)*x^3, (3/2)*c__2^2*sigma*Pi^(1/2)*x^4, (15/4)*c__2^2*sigma*Pi^(1/2)*x^5, (45/4)*c__2^2*sigma*Pi^(1/2)*x^6, (315/8)*c__2^2*sigma*Pi^(1/2)*x^7, (315/2)*c__2^2*sigma*Pi^(1/2)*x^8, (2835/4)*c__2^2*sigma*Pi^(1/2)*x^9, (14175/4)*c__2^2*sigma*Pi^(1/2)*x^10

The nth coefficient of the exponential generating function is the nth derivative evaluated at x=0
So the general integral is

eval(diff(gf,[x$n]),x=0);
intn:=convert(simplify(%),factorial) assuming n::nonnegint;

2*c__2^2*sigma*Pi*(-Pi^(1/2))^n*pochhammer(-n, n)*(2*Pi^(1/2))^(-1-n)

2^(-n)*Pi^(1/2)*sigma*c__2^2*factorial(n)

And so the coefficient is given by

eqc2:=c__2=solve(intn=1,c__2)[1];

c__2 = 1/(Pi^(1/2)*2^(-n)*factorial(n)*sigma)^(1/2)

Leading to the final result for the wavefunction

simplify(eval(eq4,eqc2)) assuming n::nonnegint:
unapply(%,n,x,sigma);

proc (n, x, sigma) options operator, arrow; 2^(-(1/2)*n)*HermiteH(n, x/sigma)*exp(-(1/2)*x^2/sigma^2)/(Pi^(1/4)*factorial(n)^(1/2)*sigma^(1/2)) end proc

NULL

Download SolnforOS_dsolve.mw

I can only get 11 place accuracy without going beyond hardware precision. Probably a better estimate of the error term is required.

restart;

We want the integral of the absolute value of the following from 0 to infinity to 14 digits of precision

y:=sin(x^4)/(sqrt(x) + x^2);

sin(x^4)/(x^(1/2)+x^2)

plot(abs(y),x=0..3);

We could integrate the successive "bumps" and sum them out to a large number of bumps, but convergence is slow and the error of the omitted area is hard to estimate.
Consider a bump over the range X[i] to X[i+1] for some large integer i

X := i->(Pi*i)^(1/4);

proc (i) options operator, arrow; (Pi*i)^(1/4) end proc

dx:=X(i+1)-X(i);
midx:=(X(i)+X(i+1))/2;
I1:=Int(y,x=X(i)..X(i+1));

(Pi*(i+1))^(1/4)-(Pi*i)^(1/4)

(1/2)*(Pi*i)^(1/4)+(1/2)*(Pi*(i+1))^(1/4)

Int(sin(x^4)/(x^(1/2)+x^2), x = (Pi*i)^(1/4) .. (Pi*(i+1))^(1/4))

The bump approximates a scaled sin function for large i, with height 1/(sqrt(x) + x^2) and width dx. Even for i=10 this is visually a good approximation

plot(eval([[y,1/(sqrt(midx)+midx^2)*sin((x-X(i))/dx*Pi)],x=X(i)..X(i+1)][],i=10),color=[red,blue],tickmarks=[default$2]);

The area of a half period of a sine function is 2, and the area of the rectangle enclosing it is Pi, so the area of a bump is approximately

A:=2/Pi*dx/(sqrt(midx) + midx^2):

Compare with "exact" value for some i values - show absolute and relative errors

evalf[20](eval([Int(y,x=X(i)..X(i+1)),A],i=5000));
%[2]-%[1],(%[2]-%[1])/%[1];
evalf[20](eval([Int(y,x=X(i)..X(i+1)),A],i=6000));
%[2]-%[1],(%[2]-%[1])/%[1];

[0.27690079226180594383e-5, 0.27690079264874607246e-5]

0.38694013e-14, 0.13973962545912594e-8

[0.22085311083385978491e-5, 0.22085311104819695048e-5]

0.21433717e-14, 0.97049649511723881e-9

So the area from some large i to infinity is approximately 2/Pi times the integral of the envelope function.
The relative error in this should be better than the relative error above for the same i, so for 6000 the relative error is about 1e-9, or correct to about 10 decimal places

Int(2/Pi/(sqrt(x) + x^2),x=X(i)..infinity);
evalf[20](eval(%,i=6000));
%*1e-9;

Int(2/(Pi*(x^(1/2)+x^2)), x = (Pi*i)^(1/4) .. infinity)

0.53798339655515414492e-1

0.53798339655515414e-10

So numerically integrate the first n bumps and sum (backwards to reduce loss of significance), then add the above estimate for the rest.
At Digits=15 (hardware precision) we have n=1000 gives .618222938207432, n=5000 gives .618222937770406, n=6000 gives
.618222937766266
At Digits:=17 (slow), n=1000 gives .61822293820743028, suggesting the Digits=15 numerical integrations are in error only in the last digit, i.e. we have 14 digits of prcesion.
However estimate from n=5000 to n=6000 still changing in the 12th place due to the error term, slightly better than as expected from above

Digits:=15;
n:=6000; # n even
seq[reduce=`+`](evalf(eval(I1,i=ii)),ii=n-2..0,-2)
+seq[reduce=`+`](evalf(eval(-I1,i=ii)),ii=n-1..1,-2)
+evalf(Int(2/Pi/(sqrt(x) + x^2),x=X(n)..infinity));

15

6000

.618222937766266

Going to more, say 10000, terms will degrade the numerical sum and not much improve the error term, but probably the best possible with this strategy and hardware precision.
n = 10000 gives .618222937760668; "_noterminate", n=20000 gives .618222937758605

Digits:=15;#Digits:=17;
n:=20000; # n even
seq[reduce=`+`](evalf(eval(I1,i=ii)),ii=n-2..0,-2)
+seq[reduce=`+`](evalf(eval(-I1,i=ii)),ii=n-1..1,-2)
+evalf(Int(2/Pi/(sqrt(x) + x^2),x=X(n)..infinity));

15

20000

.618222937758605

NULL

Download integral2.mw

When you say they are not consistent, are you suggesting they are not mathematically equivalent? If so do you have some reason to think that? The following indicates they are the same, though it is frustrating that simplify doesn't show that directly. (Following is Maple 2023.)

restart

with(PDEtools); with(LinearAlgebra)

b := -(2*I)*exp(2*t*Im(lambda1))*(exp(I*a*x/conjugate(lambda1))*exp((2*I)*a*x/lambda1)*exp((-I*a*x)*(1/conjugate(lambda1)))*exp(I*conjugate(lambda1)*t)+exp(I*lambda1*t)*exp(I*a*x/lambda1)*exp((-I*a*x)*(1/lambda1))*exp((2*I)*a*x/conjugate(lambda1))*(abs(`&epsilon;1`)^2+abs(`&epsilon;2`)^2))*conjugate(`&epsilon;1`)*Im(lambda1)/(exp((2*I)*a*x/lambda1)*abs(`&epsilon;1`)^2*exp(-(2*I)*a*x/conjugate(lambda1))*exp(2*t*Im(lambda1))+exp(-(2*I)*a*x/lambda1)*abs(`&epsilon;1`)^2*exp((2*I)*a*x/conjugate(lambda1))*exp(2*t*Im(lambda1))+exp(I*a*x/lambda1)*exp((-I*a*x)*(1/lambda1))*exp(I*a*x/conjugate(lambda1))*exp((-I*a*x)*(1/conjugate(lambda1)))*(abs(`&epsilon;2`)^4+2*abs(`&epsilon;1`)^2*abs(`&epsilon;2`)^2+abs(`&epsilon;1`)^4+2*abs(`&epsilon;2`)^2*exp(2*t*Im(lambda1))+exp(4*t*Im(lambda1))))

bdif := simplify(diff(b, x)); bdifxzero := simplify(subs({x = 0}, bdif))

12*((2/3)*abs(epsilon2)^2*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)*exp(t*(I*abs(lambda1)^2+2*Im(lambda1)*conjugate(lambda1))/conjugate(lambda1))+(1/3)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)*exp(t*(I*abs(lambda1)^2+4*Im(lambda1)*conjugate(lambda1))/conjugate(lambda1))+(2/3)*abs(epsilon2)^2*conjugate(lambda1)*exp(t*(I*abs(lambda1)^2+2*Im(lambda1)*lambda1)/lambda1)+(1/3)*conjugate(lambda1)*exp(t*(I*abs(lambda1)^2+4*Im(lambda1)*lambda1)/lambda1)+(1/3)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)^3*exp(I*t*abs(lambda1)^2/conjugate(lambda1))+(1/3)*conjugate(lambda1)*(abs(epsilon1)^2+abs(epsilon2)^2)^2*exp(I*t*abs(lambda1)^2/lambda1)+abs(epsilon1)^2*((-I*Im(lambda1)+(1/3)*lambda1+(1/3)*Re(lambda1))*exp(t*(I*conjugate(lambda1)+2*Im(lambda1)))+(abs(epsilon1)^2+abs(epsilon2)^2)*exp(t*(I*lambda1+2*Im(lambda1)))*(I*Im(lambda1)+(1/3)*conjugate(lambda1)+(1/3)*Re(lambda1))))*conjugate(epsilon1)*a*Im(lambda1)*exp(2*t*Im(lambda1))/(abs(lambda1)^2*((2*abs(epsilon2)^2+2*abs(epsilon1)^2)*exp(2*t*Im(lambda1))+abs(epsilon2)^4+2*abs(epsilon1)^2*abs(epsilon2)^2+abs(epsilon1)^4+exp(4*t*Im(lambda1)))^2)

bdif1 := simplify(diff(b, x), size); bdif1xzero := simplify(subs({x = 0}, bdif1), size)

2*a*conjugate(epsilon1)*(conjugate(lambda1)*exp(I*conjugate(lambda1)*t)+exp(I*lambda1*t)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2))*exp(0)*Im(lambda1)*exp(2*t*Im(lambda1))/((((exp(0))^2*abs(epsilon2)^2+abs(epsilon1)^2)*exp(2*t*Im(lambda1))+(1/2)*(exp(4*t*Im(lambda1))+(abs(epsilon1)^2+abs(epsilon2)^2)^2)*(exp(0))^2)*conjugate(lambda1)*lambda1)

This should give zero but it doesn't.

simplify(bdifxzero-bdif1xzero)

12*exp(2*t*Im(lambda1))*conjugate(epsilon1)*a*((2/3)*abs(epsilon2)^2*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)*exp(t*(I*abs(lambda1)^2+2*Im(lambda1)*conjugate(lambda1))/conjugate(lambda1))+(1/3)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)*exp(t*(I*abs(lambda1)^2+4*Im(lambda1)*conjugate(lambda1))/conjugate(lambda1))+(2/3)*abs(epsilon2)^2*conjugate(lambda1)*exp(t*(I*abs(lambda1)^2+2*Im(lambda1)*lambda1)/lambda1)+(1/3)*conjugate(lambda1)*exp(t*(I*abs(lambda1)^2+4*Im(lambda1)*lambda1)/lambda1)+(1/3)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2)^3*exp(I*t*abs(lambda1)^2/conjugate(lambda1))+(1/3)*conjugate(lambda1)*(abs(epsilon1)^2+abs(epsilon2)^2)^2*exp(I*t*abs(lambda1)^2/lambda1)+((-I*Im(lambda1)-(2/3)*conjugate(lambda1)+(1/3)*lambda1+(1/3)*Re(lambda1))*abs(epsilon1)^2-(2/3)*conjugate(lambda1)*abs(epsilon2)^2)*exp(t*(I*conjugate(lambda1)+2*Im(lambda1)))-(1/3)*conjugate(lambda1)*exp(t*(I*conjugate(lambda1)+4*Im(lambda1)))+(abs(epsilon1)^2+abs(epsilon2)^2)*(((-(2/3)*lambda1+(1/3)*conjugate(lambda1)+(1/3)*Re(lambda1)+I*Im(lambda1))*abs(epsilon1)^2-(2/3)*abs(epsilon2)^2*lambda1)*exp(t*(I*lambda1+2*Im(lambda1)))-(1/3)*exp(t*(I*lambda1+4*Im(lambda1)))*lambda1-(1/3)*(abs(epsilon1)^2+abs(epsilon2)^2)*(conjugate(lambda1)*exp(I*conjugate(lambda1)*t)+exp(I*lambda1*t)*lambda1*(abs(epsilon1)^2+abs(epsilon2)^2))))*Im(lambda1)/(abs(lambda1)^2*((2*abs(epsilon2)^2+2*abs(epsilon1)^2)*exp(2*t*Im(lambda1))+abs(epsilon2)^4+2*abs(epsilon1)^2*abs(epsilon2)^2+abs(epsilon1)^4+exp(4*t*Im(lambda1)))^2)

This works but it assumes all indeterminates are real, which is not what you want. Nonetheless it suggests they are probably equal.

evalc(bdifxzero-bdif1xzero)

0

Choose some random complex values for the indeterminates and check

`~`[`=`](indets(bdif1xzero, name), RandomTools:-Generate(list(complex(float), 5))); eval(bdifxzero = bdif1xzero, %)

[a = .7038511227+.3447191092*I, lambda1 = .9034558453+.8219614586*I, t = .5091763968+.2999657008*I, epsilon1 = .2195119739+.9193194089*I, epsilon2 = .6279008356+.4128601644*I]

.4578157018-.3516923614*I = .4578157018-.3516923612*I

NULL

NULL

Download simplisize.mw

Of course the more specific you are about the function h(x) and the initial/boundary condition, the more detailed the solution will be. The help page is found online here.

restart

ode := h(x) = g(x)+(diff(g(x), x))/g(x)

h(x) = g(x)+(diff(g(x), x))/g(x)

dsolve(ode)

g(x) = exp(Int(h(x), x))/(Int(exp(Int(h(x), x)), x)+c__1)

DEtools:-odeadvisor(ode)

[_Bernoulli]

Following gives a help page describing the Bernoulli case and the transformation used to solve it.

DEtools:-odeadvisor(ode, help)


 

Download Bernoulli.mw

Here's my take on the derivatives, since you explicitly asked about D

Download Derivatives.mw

For approximations, you always trade off compactness for accuracy, so I don't see why you don't just plot derivatives. To solve any confusion about which Root is used, you can check with fdiff, which does it by numerical function evaluations of the RootOf. In all the cases here, it is the same as a derivative using D

MaPal93approx.mw

For your directed acyclic graph, the algorithm is relatively simple and can be be done with a compiled Maple routine that runs in a reasonable time (3 min on my old laptop).

Find all paths between two vertices in a Directed Acyclic Graph.
Basic algorithm is recursive depth-first-search with backtracking - see https://www.algotree.org/algorithms/tree_graph_traversal/depth_first_search/all_paths_in_a_graph/
Code in startup code region.
Slight delay after restart due to compiling.

restart

with(GraphTheory)

G := Graph({[1, 2], [1, 4], [2, 3], [2, 5], [3, 5], [4, 3]})

DrawGraph(G, layout = tree, size = [200, 200])
IsAcyclic(G)

GRAPHLN(directed, unweighted, [1, 2, 3, 4, 5], Array(1..5, {(1) = {2, 4}, (2) = {3, 5}, (3) = {5}, (4) = {3}, (5) = {}}), `GRAPHLN/table/1`, 0)

true

infolevel[DAGPaths] := 2

2

paths := DAGPaths(G, 1, 5)

DAGPaths: longest path length is 3

DAGPaths: calculating paths with length between 0 and 3

DAGPaths: calculating 3 paths...

DAGPaths: found expected number of paths

Matrix(%id = 36893490937258087356)

@sursumCorda's graph - see MaplePrimes

A := ImportMatrix(cat(currentdir(), "/matrix.txt"), source = csv)

G := Graph(A)

GRAPHLN(directed, unweighted, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173], Array(1..173, {(1) = {120, 125}, (2) = {77, 107, 121, 133}, (3) = {173}, (4) = {5, 47, 71, 87, 143}, (5) = {9, 32, 60, 120, 137, 138}, (6) = {47}, (7) = {40}, (8) = {105}, (9) = {86, 121, 133}, (10) = {11, 33}, (11) = {42, 69, 91, 118, 163}, (12) = {10, 78, 83, 134, 172}, (13) = {8, 137, 152}, (14) = {5, 45}, (15) = {99, 113}, (16) = {60, 162}, (17) = {39}, (18) = {54, 91, 118}, (19) = {20, 74, 111}, (20) = {9, 93, 138, 149}, (21) = {18, 42, 146}, (22) = {80, 100}, (23) = {26, 42}, (24) = {169}, (25) = {22, 74, 79}, (26) = {69, 163}, (27) = {21, 78, 134, 172}, (28) = {27, 83, 128}, (29) = {}, (30) = {153}, (31) = {5, 8, 140}, (32) = {43, 159}, (33) = {113, 148}, (34) = {39, 94, 103, 128}, (35) = {16, 32}, (36) = {6, 155, 156}, (37) = {34, 86, 98}, (38) = {22, 51, 85, 115, 120, 151}, (39) = {48, 90}, (40) = {17, 166}, (41) = {53, 84}, (42) = {54}, (43) = {55}, (44) = {34, 124, 129}, (45) = {35}, (46) = {9, 51, 152}, (47) = {1, 72, 101, 131}, (48) = {112, 171}, (49) = {54, 127, 147}, (50) = {7, 104}, (51) = {126, 160}, (52) = {25, 38, 46, 141}, (53) = {49, 83, 134}, (54) = {130}, (55) = {102}, (56) = {44, 98}, (57) = {31, 61, 67, 85}, (58) = {59, 71, 156}, (59) = {57, 72, 155}, (60) = {73, 108, 135}, (61) = {5, 74}, (62) = {64, 157, 168}, (63) = {170}, (64) = {63}, (65) = {17, 94, 128, 167}, (66) = {62, 117}, (67) = {25, 115, 120}, (68) = {65, 82, 86, 137}, (69) = {62, 76, 130}, (70) = {84}, (71) = {1, 72}, (72) = {67, 85, 125}, (73) = {28, 84}, (74) = {136, 140}, (75) = {17, 63, 117, 165, 166}, (76) = {64, 169}, (77) = {55, 65, 82, 108, 135, 159}, (78) = {18, 26, 66, 81}, (79) = {2, 51, 80, 105, 152}, (80) = {68, 77, 126, 160}, (81) = {42, 62, 76, 91, 118}, (82) = {27, 144, 145}, (83) = {26}, (84) = {23, 83, 134}, (85) = {74, 154}, (86) = {73, 108}, (87) = {32, 60, 92, 116, 156}, (88) = {165, 166}, (89) = {5, 35, 87}, (90) = {171}, (91) = {103}, (92) = {97, 155}, (93) = {2, 86, 137, 142}, (94) = {3, 15, 33, 66, 90}, (95) = {12, 21, 49, 158}, (96) = {9, 107}, (97) = {13, 141}, (98) = {73, 124, 129}, (99) = {168, 170}, (100) = {138, 152, 154}, (101) = {67, 85, 125}, (102) = {28, 53, 122}, (103) = {88}, (104) = {17, 117, 165, 166}, (105) = {96, 114}, (106) = {19, 61}, (107) = {98}, (108) = {28, 70}, (109) = {95, 123, 135}, (110) = {4, 58, 106}, (111) = {107, 133, 139, 142}, (112) = {15}, (113) = {157}, (114) = {86, 107, 121, 133, 142}, (115) = {13, 140}, (116) = {72, 101, 131}, (117) = {99, 157}, (118) = {130}, (119) = {97, 100, 115, 126}, (120) = {107, 121, 133, 142}, (121) = {56}, (122) = {27, 70, 95, 123}, (123) = {84, 118}, (124) = {11, 18, 81, 94, 128, 146}, (125) = {25, 46, 115}, (126) = {86, 121}, (127) = {24, 76, 130}, (128) = {3, 62, 99}, (129) = {43, 108, 109, 159}, (130) = {50, 164}, (131) = {52, 67, 119, 125}, (132) = {4, 31, 45, 61, 89}, (133) = {98}, (134) = {26, 42}, (135) = {28, 70}, (136) = {93, 96, 114, 138}, (137) = {107, 121, 133}, (138) = {129}, (139) = {138, 149}, (140) = {105, 137, 138}, (141) = {8, 19, 85, 120, 151}, (142) = {56}, (143) = {7, 66, 104, 128, 146}, (144) = {26, 33, 42, 66, 91, 118}, (145) = {41, 70, 95, 123}, (146) = {48, 91, 117, 164}, (147) = {50, 75}, (148) = {62, 117}, (149) = {77, 129}, (150) = {34, 86, 124, 129}, (151) = {20, 74, 111, 152, 154}, (152) = {86, 121}, (153) = {161}, (154) = {93, 105}, (155) = {13, 85, 100, 120}, (156) = {1, 72, 101}, (157) = {29}, (158) = {10, 94}, (159) = {145}, (160) = {37, 56, 150}, (161) = {14, 110, 132}, (162) = {36, 71, 116, 143}, (163) = {54, 127}, (164) = {167}, (165) = {3, 90}, (166) = {90}, (167) = {103}, (168) = {173}, (169) = {50, 75, 164}, (170) = {173}, (171) = {99}, (172) = {23, 81}, (173) = {29}}), `GRAPHLN/table/10`, 0)

paths := CodeTools:-Usage(DAGPaths(G, 30, 29, minlength = 45))

DAGPaths: longest path length is 49

DAGPaths: calculating paths with length between 45 and 49

DAGPaths: calculating 1008252 paths...

DAGPaths: found expected number of paths

memory used=254.33MiB, alloc change=188.31MiB, cpu time=3.42m, real time=3.56m, gc time=296.88ms

Matrix(%id = 36893490937258056028)

NULL

Download BacktrackDAGPaths.mw

DAGPaths:=proc(G::Graph,	# directed acyclic graph - self loops and duplicate edges (if multigraph) are ignored.
			V1, V2,	# start and end vertices to find paths between.
			{minlength::nonnegint := 0, 	# (optional) minimum length of path (measured in number of edges).
			maxlength::nonnegint := -1})	# (optional) maximum length of path - default is length of longestpath.
			# outputs an npaths x (maxlength+1) Matrix (datatype = integer[4]) that contains the paths.
			# entries are positive integers corresponding to the vertices.
			# use infolevel[DAGPaths] := 2 to output additional information. 
	description "finds all paths between two vertices in a directed acyclic graph";
	uses GraphTheory;
	local P, S, A, Adj, n, i, v1, v2, GG, G2, VerticesG, maxpathlength, minlengthi::integer[4], maxlengthi::integer[4],
		maxpaths, maxdeg, pathptr, path, paths, npaths, N, j, src::integer[4], dest::integer[4], newvertices;	
	# check arguments and set up 
	if not IsDirected(G) or not IsAcyclic(G) then error "graph must be directed and acyclic" end if;
	VerticesG := Vertices(G);
	if not member(V1,VerticesG,'v1') then error "Vertex %1 not in graph", V1 end if;
	if V1 = V2 and minlength = 0 then
		return Matrix(1, 1, [1], 'datatype' = integer[4])
	elif V1 = V2 and minlength > 0 then
		userinfo(2, procname, "no paths between %1 and %2 with length greater than %3", V1, V2, minlength); 
		return Matrix(0, 1, 'datatype' = integer[4])
	end if;
	if not member(V2, VerticesG, 'v2') then error "Vertex %1 not in graph", V2 end if;
	if OutDegree(G, V1) = 0 then error "start vertex has no departures" end if;
	if InDegree(G, V2) = 0 then error "end vertex has no arrivals" end if;
	if HasSelfLoop(G) or IsMultigraph(G) then
		userinfo(2, procname, "ignoring duplicate edges and self-loops")
	end if;	
	n := nops(VerticesG);
	GG := UnderlyingGraph(G, 'directed' = true, 'selfloops' = false, 'multigraph' = false);
  	# Delete departures from last vertex
  	if OutDegree(GG, V2) = 1 then
  		DeleteArc(GG, [V2, Departures(G, V2)[]])
  	elif OutDegree(GG, V2) > 1 then
  		DeleteArc(GG, [seq([V2, i], i in Departures(G, V2))])
  	end if;
  	# and delete arrivals to first vertex
  	if InDegree(GG, V1) = 1 then
  		DeleteArc(GG, [V1, Arrivals(G ,V1)[]])
  	elif InDegree(GG, V1) > 1 then
  		DeleteArc(GG, [seq([V1, i], i in Arrivals(G, V1))])
  	end if;
  	# work only on component that V1 is in for path length calc.
  	# (could be ommitted but calc is faster with smaller adjacency matrix)
  	newvertices := select(has, ConnectedComponents(GG), V1)[];
  	if not member(V2, newvertices) then
  		userinfo(2, procname, "no paths between %1 and %2", V1, V2); 
		return Matrix(0, 1, 'datatype' = integer[4])
	end if; 
	# Find length of longest path
	G2 := InducedSubgraph(GG, newvertices);
	Adj := AdjacencyMatrix(G2);
	maxpathlength := nops(BellmanFordAlgorithm(Graph(-Adj), v1, v2)[1]) - 1;
	userinfo(2, procname, "longest path length is %1", maxpathlength);
	if maxlength = -1 then
		maxlengthi := maxpathlength
	else
		maxlengthi := min(maxlength,maxpathlength);
	end if;
	if minlength > maxlengthi then
		userinfo(2, procname, "no paths with minlength %1 greater than maxlength %2", minlength, maxlengthi);
		return Matrix(0, 1, 'datatype' = integer[4])
	else
		minlengthi := minlength
	end if;
	userinfo(2, procname, "calculating paths with length between %1 and %2", minlengthi, maxlengthi);	
	# calculate number of paths from adjacency matrix since # walks = # paths
	P := Adj[v1];
	for i from 2 to minlength do
	P := P.Adj;
	end do:
	S := P:
	for i from minlength + 1 to maxlengthi do
  		P := P.Adj;
  		S := S + P;
	end do:
	maxpaths := S[v2];
	userinfo(2, procname, "calculating %1 paths... ", maxpaths);
	A := op(4,GG):
	# Construct an n x maxdeg Matrix equivalent to op(4,GG) 
	maxdeg := max(map(nops, A));
	N := Matrix(n, maxdeg, 'datatype' = integer[4]):
	for i to n do
		for j to nops(A[i]) do
			N[i,j]:=op(j,A[i])
		end do;
	end do;
	# allocate space and initialize
	src := v1;
	dest := v2;
	path := Vector(maxpathlength + 1, {1 = src}, 'datatype' = integer[4]); # +1 from edges to verts
	paths := Matrix(maxpaths, maxlengthi + 1, 'datatype' = integer[4]);
	npaths := Vector([0], 'datatype' = integer[4]);
	pathptr := 1;
	# call DFS recursively.
	DFS(src, dest, npaths, pathptr, path, paths, minlengthi, maxlengthi, N, maxdeg);
	if npaths[1] = 0 then
		userinfo(2, procname, "no paths between %1 and %2 with lengths between %3 and %4", V1, V2, minlengthi, maxlengthi)
	elif npaths[1] = maxpaths then
		userinfo(2, procname, "found expected number of paths")
	else
		userinfo(2, procname, "found %1 paths - unexpected result", npaths[1])
	end if; 
	# output results
	paths;
end proc:
#
# Compilable recursive Depth-First Search routine - compiled below
#
	DFSM:=proc(src::integer[4], dest::integer[4],
			npaths::Vector(datatype = integer[4]), pathptr::integer[4], path::Vector(datatype = integer[4]),
			paths::Matrix(datatype = integer[4]), minlength::integer[4], maxlength::integer[4],
			N::Matrix(datatype = integer[4]), maxdeg::integer[4])
		local v::integer[4], j::integer[4];
		if src = dest then
  			if pathptr >= minlength + 1 and pathptr <= maxlength + 1 then
    				npaths[1] := npaths[1] + 1;
	    			for j to pathptr do	
					paths[npaths[1], j] := path[j];
				end do;
			end if
		else
			for j to maxdeg do
				v:= N[src, j];
				if v = 0 then break end if;     
				path[pathptr + 1] := v;
				procname(v, dest, npaths, pathptr + 1, path, paths, minlength, maxlength, N, maxdeg);
			end do;
		end if;
		NULL;
	end proc;
#
DFS := Compiler:-Compile(DFSM);

 

restart

Open the Operators palette (or Large Operators) in 2D and choose a symbol - many of them automatically act as infix operators

`&npar;` := proc (R1, R2) options operator, arrow; R2*R1/(R1+R2) end proc

proc (R1, R2) options operator, arrow; R2*R1/(R1+R2) end proc

`&npar;`(X, Y)

Y*X/(X+Y)

Some symbols have predefined meanings, unfortunately including the concatenation operator ||.

I couldn't get the local mechanism to work.

`||` := proc (R1, R2) options operator, arrow; R2*R1/(R1+R2) end proc

Error, attempting to assign to `||` which is protected.  Try declaring `local ||`; see ?protect for details.

`&sqcap;` := proc (R1, R2) options operator, arrow; R2*R1/(R1+R2) end proc

proc (R1, R2) options operator, arrow; R2*R1/(R1+R2) end proc

`&sqcap;`(X, Y)

Y*X/(X+Y)

``

Download infix.mw

(I didn't understand what you meant by simplification if not the above.)

First 20 21 22 23 24 25 26 Last Page 22 of 81