-
Notifications
You must be signed in to change notification settings - Fork 1
/
ode1_ps.mac
2202 lines (1767 loc) · 92.7 KB
/
ode1_ps.mac
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ************************************************************************** */
/* ***** prellesingerODE ***** */
/* ***** ***** */
/* ***** Author: Nijso Beishuizen ***** */
/* ***** ***** */
/* ***** PRELLE-SINGER METHOD FOR SOLVING FIRST ORDER ODES ***** */
/* ***** Based on the paper ***** */
/* ***** Y.K. Man - Computing closed form solutions of first order ***** */
/* ***** ODEs using the Prelle-Singer procedure ***** */
/* ***** Journal of Symbolic Computation 16 (1993) pp. 423-443 ***** */
/* ***** and the work of ***** */
/* ***** R. Shtokhamer - Solving first order differential equations ***** */
/* ***** using the Prelle-Singer algorithm ***** */
/* ***** Technical Report 88-09, May 1988 ***** */
/* ***** and the work of ***** */
/* ***** J. Avellar, L.G.S. Duarte, S.E.S. Duarte, L.A.C.P. la Mota ***** */
/* ***** Determining Liouvillian first integrals for dynamical ***** */
/* ***** systems in the plane ***** */
/* ***** ***** */
/* ***** ***** */
/* ************************************************************************** */
/* ************************************************************************** */
/* --- TODO --- */
/* fixed points X: f(X)=0
*/
/* 1. implement line at infinity (exponential factors for trivial darboux polynomials) */
/* 2. introduce auxiliary variables for x^n and y^m, where n,m are defined integers >4 */
/* 3. */
/* ************************************************************************** */
put('prellesinger,001,'version)$
/* ************************************************************************** */
/* ***** print all statements with flag lower than DEBUGFLAG ***** */
DEBUGFLAG:1$
load(lrats)$ /* for lratsubst */
load(grobner)$ /* for computing Groebner the basis */
load(functs)$ /* for the least common multiple command lcm */
define_variable(degreeboundf, 2, fixnum)$ /* max degree of trial polynomials for the invariant algebraic curves (realistic is 1-4) */
define_variable(degreeboundP, 4, fixnum)$ /* max degree of trial polynomials for exponential factors(realistic is 1-4) */
define_variable(degreeboundQ, 4, fixnum)$ /* max degree of trial polynomials for exponential factors(realistic is 1-4) */
define_variable(ODEFI_GRAD_LIST ,[] ,any)$ /* not used (yet), This idea was introduced in Shtokhamer's paper */
define_variable(convertImaginary ,false, boolean)$ /* true = try to convert complex Invariant Algebraic Curves to real */
define_variable(convertTrig , true, boolean)$ /* true = convert trig functions (sin,cos,csc,sec,cot) to tan */
define_variable(returnExplicit , true, boolean)$ /* true = return and explicit solution, else return an implicit solution */
define_variable(returnIntFactor ,false, boolean)$ /* true = returns only the integrating factor */
define_variable(returnDarboux ,false, boolean)$ /* true = returns only the Darboux polynomials+cofactors (and exponential factors if found) */
define_variable(use_to_poly_solve,false, boolean)$ /* true = use to_poly_solve as solver */
define_variable(convertVariables,false, boolean)$ /* true = try to convert dependent (transcendental variables) to y,x */
halfangles : true$ /* if true, converts trigonometric halfangles, i.e. tan(x/2), sin(x/2), etc */
%edispflag : true$ /* if true, writes negative powers of %e as a quotient, i.e. %e^-x -> 1/%e^x */
exptdispflag : true$ /* if true, writes exponents with negative powers as quotients */
linsolvewarn : false$ /* if true, linsolve prints a message "Dependent equations eliminated". */
/* this stuff below is for simplifying constants of integration appearing in exponentials, like exp(%c+a*x) */
/* this can be simplified to %c*exp(a*x) */
matchdeclare (_a, lambda ([_e], _e#0 and freeof(_x, _e)), _b, freeof(_x));
defmatch (linearp, _a*_x + _b, _x);
/* detect p1*sqrt(p2/q2) and split into sqrt(p2) and sqrt(q2) */
matchdeclare(_p1,lambda([_e1],_e1#0),_p2,lambda([_e3],_e3#0),_q2,lambda([_e4],_e4#1));
defmatch(sqrtOfFraction,_p1*sqrt(_p2/_q2));
/* global variables */
/* question: do we want to have global variables like basisFunctions? */
/* ************************************************************************** */
/* ***** MAIN ROUTINE ***** */
/* ***** INPUT: ode of the form P(x,y)*'diff(y,x)= Q(x,y) ***** */
/* ***** y = dependent variable, x = independent variable ***** */
/* ***** OUTPUT: solution of the ODE, or false ***** */
/* ************************************************************************** */
prellesingerODE(_ode1,_y,_x,[options]):=block(
[varlist, Sfg:[],_k,fList,%Ci,Sum_nigi:0,niList:[],firstIntegral:1,feqns,
dx,dy,ddx,ddy,denom_lcm,dPdx_plus_dQdy,constantlist,method:false,_mu:false,
denom_lcm:1,ExponentialFactors:[1],DarbouxPolynomials:[]],
dprint(1,""),
dprint(1,"----------------------------------------------------------------------------"),
dprint(1,"--- Prelle-Singer method for first order ordinary differential equations ---"),
dprint(1,"----------------------------------------------------------------------------"),
dprint(1,""),
/* --- check all the optional arguments --- */
searchExponentialFactors : assoc('searchExponentialFactors,options,false), /* if true, then also search for exponential factors (takes longer but you can solve more equations) */
convertImaginary : assoc('convertImaginary,options,true), /* if true, convert imaginary numbers to real to simplify integrating factor. true if input ODE does not contain %i */
searchRational : assoc('searchRational,options,false), /* if true, only search for rational solutions */
convertTrig : assoc('convertTrig,options,true), /* if true, convert (sin,cos,csc,sec,cot) functions to tan to create a true transcendence base */
basisFunctions : assoc('basisFunctions,options,[]), /* user-defined lexicographically ordered list of basis functions */
returnExplicit : assoc('returnExplicit,options,true), /* if true, tries to return an explicit solution in _y, else returns an implicit solution */
returnIntFactor : assoc('returnIntFactor,options,false), /* if true, returns only the integrating factor instead of the solution of the ode */
returnDarboux : assoc('returnDarboux,options,false), /* if true, returns only the Darboux polynomials instead of the solution of the ode */
use_to_poly_solve : assoc('use_to_poly_solve,options,false), /* if true, use the to_poly_solve solver (in case you encounter "quotient" errors) */
convertVariables : assoc('convertVariables,options,true), /* if true, try to convert auxiliary variables v(x,y) in the basis functions to x,y in intermediate steps (rarely needs to be set to false) */
dprint(1,""),
dprint(1,"---------- optional arguments : -----------------------------"),
dprint(1,"---------- user defined basis functions = ",basisFunctions),
dprint(1,"---------- search only rational solutions = ",searchRational),
dprint(1,"---------- search for exponential factors = ",searchExponentialFactors),
dprint(1,"---------- convert imaginary to real = ",convertImaginary),
dprint(1,"---------- convert trig functions to tan = ",convertTrig),
dprint(1,"---------- convert auxiliary variables = ",convertVariables),
dprint(1,"---------- return explicit solution = ",returnExplicit),
dprint(1,"---------- return only integrating factor = ",returnIntFactor),
dprint(1,"---------- return only Darboux polynomials = ",returnDarboux),
dprint(1,"------------------------------------------------------------"),
dprint(1,""),
/* check if input is a first order ode */
_type: odeType(_ode1,_y,_x,'firstorder),
dprint(3,"type = ",_type),
if _type=false then return(false),
/* rewrite the ode to canonical form */
dprint(3,"ode = ",_ode1),
_ode: ode1CanonicalForm(_ode1,_y,_x),
dprint(3,"canonical form of ode = ",_ode),
/* convert sin,cos, csc,sec,cot to t=tan(x/2), u=tan(y/2) */
if (convertTrig=true) then (
_ode:Trig2T(_ode,_x,_y,_t,_u),
dprint(3,"ode = ",_ode),
apply('gradef,[_t,_x,(_t^2+1)/2]),
apply('gradef,[_t,_y,0]),
apply('gradef,[_u,_x,0]),
apply('gradef,[_u,_y,(_u^2+1)/2])
),
/* get the Pfaffian coefficients */
[_P,_Q] : ode1PfaffianForm(_ode,_y,_x),
dprint(3,"P = ",_P),
dprint(3,"Q = ",_Q),
/* analyse P,Q: compute the degree=max(deg(P),deg(Q)))*/
/* deal with user-defined substitution rules */
/*
if ODEFI_GRAD_LIST # nil then (
ODEFI_GRAD_LIST:subst(%x2,_x,subst(%x1,_y,ODEFI_GRAD_LIST)),
for _dfs in ODEFI_GRAD_LIST do (
_df:lhs(_dfs),
_df_x:diff(_df,_x),
_df_y:diff(_df,_y),
if _df_x#0 or _df_y#0 then (
apply('gradef,[_df,%x2,subst(%x2,_x,subst(%x1,_y,_df_x))]),
apply('gradef,[_df,%x1,subst(%x2,_x,subst(%x1,_y,_df_y))])
)
)
),
*/
/* Call the Prelle Singer method (following the naming convention of Man (1993)) */
[method,DarbouxPolynomials,DarbouxMultiplicities,ExponentialFactors] : new_ps_1(_P,_Q,_y,_x,basisFunctions),
if method=false then return(false),
/* back-substitution of temporary trig-substitution */
if (convertTrig=true) then (
DarbouxPolynomials : T2Trig(DarbouxPolynomials,_x,_y,_t,_u),
ExponentialFactors : T2Trig(ExponentialFactors,_x,_y,_t,_u),
_P : T2Trig(_P,_x,_y,_t,_u),
_Q : T2Trig(_Q,_x,_y,_t,_u),
/* we might get trivial polynomials because of trig identities. We will remove them */
indices : sublist_indices(DarbouxPolynomials,lambda([_i],not lfreeof([_x,_y],_i) )),
DarbouxPolynomials : makelist(DarbouxPolynomials[i],i,indices),
DarbouxMultiplicities : makelist(DarbouxMultiplicities[i],i,indices)
),
dprint(3,"P = ",_P),
dprint(3,"Q = ",_Q),
dprint(3,"method = ",method),
dprint(1,"Darbouxpolynomials,cofactors = ",DarbouxPolynomials),
dprint(3,"Darbouxpolynomials = ",grind(DarbouxPolynomials)),
dprint(3,"DarbouxMultiplicities = ",grind(DarbouxMultiplicities)),
if returnDarboux=true then return([DarbouxPolynomials,DarbouxMultiplicities,ExponentialFactors]),
if (method="Darboux" or method="integratingFactor") then (
_mu : DarbouxIntegratingFactor(DarbouxPolynomials,DarbouxMultiplicities,ExponentialFactors),
if returnIntFactor=true then return(_mu)
),
if method="firstIntegral" then (
dprint(1,"FIRST INTEGRAL FOUND"),
w:1,
for i:1 thru length(DarbouxPolynomials) do
w: w*DarbouxPolynomials[i][1]^DarbouxMultiplicities[1],
sol: w - %c
)
else (
dprint(1,"INTEGRATING FACTOR FOUND, mu = ",_mu),
sol : ode1Solve(_P,_Q,_y,_x,'integratingFactor=_mu)
),
/* clean up and try to write in explicit form*/
if (returnExplicit=true) then sol: cleanupODESolution(sol,_y,_x),
dprint(1,"solution = ",grind(sol)),
return(sol)
)$
/* ************************************************************************** */
/* ************************************************************************** */
/* ***** solve an ode using an integrating factor and simplify result ***** */
/* ************************************************************************** */
ode1Solve(_P,_Q,_y,_x,[options]):=block([_check,_res,_mu:false,mu_P,mu_Q,exactode,_N,_M,res1,res2,sol],
/* --- check all the optional arguments --- */
_mu : assoc('integratingFactor,options,[]),
dprint(3,""),
dprint(3,"---------- optional arguments : -----------------------------"),
dprint(3,"---------- use integrating factor = ",_mu),
dprint(3,""),
if _mu=false then (
dprint(0,"only integrating factor is implemented!"),
return(false)
),
_P : rootscontract(_P),_Q:rootscontract(_Q), /* the simplification to canonical could introduce imaginary numbers when square roots are in the expression */
dprint(3,"P = ",grind(_P)),
dprint(3,"Q = ",grind(_Q)),
_mu: ratsimp(trigsimp(_mu)),
/* rootscontract converts products of roots into roots of products, simplifies an expression like 1/(sqrt(x-%i)sqrt(x+%i)) = 1/(sqrt(x^2+1)) */
/* note that abs(x) can also be put into the root when x is real*/
_mu: rootscontract(_mu),
dprint(3,"MU = ",grind(_mu)),
/* we try to get rid of imaginary numbers */
mu_P : num(_mu),
mu_Q : denom(_mu),
/*if not freeof(%i,mu_P) and (convertImaginary=true) then (*/
if not freeof(%i,mu_P) then (
mu_P : rootscontract(mu_P),
mu_P : rectform(radcan(mu_P)), /* for simplification of e.g. -1^%i*/
mu_P : trigreduce(trigsimp(demoivre(mu_P))) /* if mu=exp(sin(x)) then exponentialize(mu) has exploded this expression and introduced complex numbers */
),
/*if not freeof(%i,mu_Q) and (convertImaginary=true) then (*/
if not freeof(%i,mu_Q) then (
mu_Q : rootscontract(mu_Q),
mu_Q : rectform(radcan(mu_Q)), /* for simplification of e.g. -1^%i*/
mu_Q : trigreduce(trigsimp(demoivre(mu_Q))) /* if mu=exp(sin(x)) then exponentialize(mu) has exploded this expression and introduced complex numbers */
),
dprint(3,"MU = ",mu_P,"/ ",mu_Q),
_mu : radcan(mu_P / mu_Q),
/*
if not freeof(%e,_mu) then
_mu: radcan(exponentialize(_mu)), /* will simplify e.g. exp(log(a*x+b)) */
*/
dprint(3,"MU = ",grind(_mu),_y,_x),
exactode : radcan(trigsimp( ratsimp(diff(_mu*_P,_x) + diff(_mu*_Q,_y)))), /* extra ratsimp for 1.350*/
dprint(1,"Does integrating factor make ODE exact? ",grind(exactode), " ",is(exactode=0)),
/* we integrate the exact equation. note that we can do that in two ways and we need to choose the easiest one */
/* NB: trigsimp helps in simplifying e.g. kamke1.6, speedup from 20s to 1s !!! */
_N : trigsimp(ratsimp(-_mu*_P)),
_M : trigsimp(ratsimp(_mu*_Q)),
dprint(3,"N = ",grind(_N)),
dprint(3,"M = ",grind(_M)),
/* *************************** */
halfangles : false,
/* *************************** */
res1: integrate(_M,_x),
dprint(3,"res1 = ",grind(res1)),
/* is this really necessary? */
/*if freeof(%i,res1) then (*/
res1: radcan(res1), /* kamke 364*/
/* if freeof(%i,res1a) then res1:res1a*/
/*),*/
dprint(3,"res1 = ",grind(res1)),
res2: integrate(_N,_y),
dprint(3,"res2 = ",grind(res2)),
/*if freeof(%i,res2) then (*/
res2: radcan(res2),
/* if freeof(%i,res2a) then res2:res2a*/
/*),*/
res3: diff(res1,_y),
dprint(3,"res3 = ",grind(res3)),
/* radcan: simplifies kamke1.41, we should only use radcan when we do not have %i terms (messes up results) */
/*if freeof(%i,res3) then (*/
res3: radcan(res3),
/* if freeof(%i,res3a) then res3:res3a*/
/*),*/
dprint(3,"res3 = ",grind(res3)),
res3: integrate(res3,_y),
dprint(3,"res3 = ",grind(res3)),
sol: res1 + res2 - res3 = %c,
dprint(3,"sol = ",sol),
sol : ratsimp(sol),
dprint(3,"(ratsimp)sol = ",sol),
if trigonometricp(sol) then (
sol : trigexpand(sol), /* kamke 358 */
dprint(3,"(trigexpand)sol = ",sol),
sol : trigsimp(sol), /* kamke 364 */
dprint(3,"(trigsimp)sol = ",sol),
sol : trigreduce(sol),
dprint(3,"(trigreduce)sol = ",sol)
),
/* *************************** */
halfangles : true,
/* *************************** */
return(sol)
)$
/* ************************************************************************** */
/* ************************************************************************** */
/* ***** new_ps_1 - prelle singer method from Y.K. Man (1993) ***** */
/* ***** - added search for the exponential factors ***** */
/* ************************************************************************** */
new_ps_1(_P,_Q,_y,_x,_userDefinedBasisFunctions):=block(
[EXIT:false, realSystem:false, sol:false, integratingFactor:false,
Sum_nigi:0, firstIntegral:1,
Sfg:[], niList:[], exponentialFactor:[],
varlist, _k, fList, %Ci, feqns, dx,dy,ddx,ddy, denom_lcm, dPdx_plus_dQdy, constantlist ],
dprint(3,"P = ",_P),
dprint(3,"Q = ",_Q),
dprint(3,"degreebound = ",degreeboundf),
/* if the ode is real we set the realsystem to true. Invariant algebraic curves, cofactors and exponential factors will now be converted to */
/* real expressions by using the complex conjugate expressions: when f is an IAC, then conj(f) is an IAC and also f*conj(f) is an AIC. */
/* Moreover, f*conj(f) is real. */
if (freeof(%i,_P) and freeof(%i,_Q)) then realSystem:true,
dprint(3,"is the ODE real: ",realSystem),
/* ******************************* */
if _userDefinedBasisFunctions = [] then
varlist : BasisFunctions(_P,_Q,_y,_x)
else
varlist : _userDefinedBasisFunctions,
dprint(2,"basis functions = ",varlist),
/* ******************************* */
/* get a list of all variables in P and Q, remove the variables in varlist and make the remaining variables a constant */
constantlist: complement(varlist,listofvars(_Q/_P)),
dprint(3,"detected free variables (undefined constants) in ode: ",constantlist),
/* (BUG) note: should remove from constantlist the constants that are already declared constant by the user! */
apply(declare,[''constantlist,constant]), /* declare quotes its arguments so we unquote it*/
/* ----------------------------------------------------------------------------------------------- */
/* now replace with internal variables [x1,x2,x3,...,xn] where x1 > x2 > x3 > x4 > ... > xn */
/* ----------------------------------------------------------------------------------------------- */
original_variables : varlist,
varlist:makelist(concat(%x,i),i,1,length(varlist)),
dprint(3,"varlist = ",varlist),
/* define varlist as ratvars, such that a*%x1 + b*a*%x1 = (a+b*a)*%x1 */
/* (if ratvars=[a], then a*%x1+b*a*%x1) = (%x1+b*%x1)*a ) */
/* TODO: _oldratvars : ratvars,*/ /* check if this clashes with _oldratvars elsewhere*/
/* ratvars=varlist,*/
/* 2. define derivatives dci/dx and dci/dy */
dx: trigexpand(trigsimp(diff(original_variables,_x))),
dy: trigexpand(trigsimp(diff(original_variables,_y))),
ddx : map(denom,dx), /* take the gradient of all variables wrt y and then take the denominator */
ddy : map(denom,dy),
dprint(3,"dx = ",dx),
dprint(3,"dy = ",dy),
dprint(3,"ddx = ",ddx),
dprint(3,"ddy = ",ddy),
/*
if convertTrig=true then (
dx : Trig2Tan(dx,_y,_x),
dy : Trig2Tan(dy,_y,_x),
ddx : map(denom,dx),
ddy : map(denom,dy)
),
*/
denom_lcm : lcm([ddx,ddy]), /* compute the denominator of the least common multiple */
dPdx_plus_dQdy : -ratsimp(trigsimp((diff(_P,_x) + diff(_Q,_y)))), /* needed in step 4 */
/* if convertTrig=true then dPdx_plus_dQdy : Trig2Tan(dPdx_plus_dQdy,_y,_x),*/
dprint(3,"dx = ",dx),
dprint(3,"dy = ",dy),
dprint(3,"ddx = ",ddx),
dprint(3,"ddy = ",ddy),
dprint(3,"denom_lcm = ",denom_lcm),
dprint(3,"dP/dx + dQ/dy = ",grind(dPdx_plus_dQdy)),
dx : lratsubst(map("=",reverse(original_variables),reverse(varlist)),dx), /* we have to use reverse, because the transcendentals come at the end*/
dy : lratsubst(map("=",reverse(original_variables),reverse(varlist)),dy), /* and they depend on x,y so we substitute the transcendentals first */
dprint(3,"dx = ",dx),
dprint(3,"dy = ",dy),
/* ***** rational approach, not implemented yet ***** */
/*
if (searchRational=true) then (
W : ratexpand(ratsimp(_x*_Q - _y*_P)),
dprint(3,"W = ",W),
dprint(3,"varlist = ",original_variables),
dprint(3,"P = ",_P),
dprint(3,"deg(P) = ",degree_l_t(_P,original_variables)),
dprint(3,"Q = ",_Q),
dprint(3,"deg(Q) = ",degree_l_t(_Q,original_variables)),
degree_ode : max(degree_l_t(_P,original_variables),degree_l_t(_Q,original_variables)),
dprint(3,"degree of the ode = ",degree_ode),
W_nplus1 : (_x*d_t(_Q,original_variables,degree_ode) - _y*d_t(_P,original_variables,degree_ode)),
dprint(3,"W_nplus1 = ",W_nplus1),
factorW : sublist(args(ratexpand(W_nplus1)),lambda([__x],not(integerp(__x)))),
dprint(3,"rational factors are : ",factorW)
),
*/
/* factorW contains the leading terms of the test polynomials. */
/* we can remove from fList all polynomials with leading terms that are not in factorW */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* 1. declare dependencies x,y */
depends(varlist,[_x,_y]),
/* now define derivatives of new variables using gradef */
for v in varlist do (
apply('gradef,[v,_x,first(dx)]),
apply('gradef,[v,_y,first(dy)]),
dx:rest(dx),dy:rest(dy)
),
/* replace dx and dy with the new variables */
_P : lratsubst(map("=",reverse(original_variables),reverse(varlist)),_P),
_Q : lratsubst(map("=",reverse(original_variables),reverse(varlist)),_Q),
dx: diff(varlist,_x),
dy: diff(varlist,_y),
ddx : map(denom,dx), /* take the gradient of all variables wrt y and then take the denominator */
ddy : map(denom,dy),
denom_lcm : lcm([ddx,ddy]), /* compute the denominator of the least common multiple */
dPdx_plus_dQdy : lratsubst(map("=",reverse(original_variables),reverse(varlist)),dPdx_plus_dQdy),
dprint(3,"dx = ",dx),
dprint(3,"dy = ",dy),
dprint(3,"ddx = ",ddx),
dprint(3,"ddy = ",ddy),
dprint(3,"denom_lcm = ",denom_lcm),
dprint(3,"dP/dx + dQ/dy = ",dPdx_plus_dQdy),
_P : ratsimp(_P * denom_lcm),
_Q : ratsimp(_Q * denom_lcm),
dPdx_plus_dQdy : ratsimp(dPdx_plus_dQdy * denom_lcm),
_degree_ode : max(degree_l_t(_P,varlist),degree_l_t(_Q,varlist)),
/* ******************************* */
dprint(3,"P = ",_P),
dprint(3,"Q = ",_Q),
dprint(3,"degree of the ode :", _degree_ode),
/* note: if the degree of the ode is very large, the AIC degree can also be very large. therefore, it is maybe better to introduce new variables
X = x^highdegree, or maybe even several variables that represent the factors of x^highdegree */
_k : degreeboundf,
method : false, /* no solution method was found yet */
dprint(3,"************************"),
dprint(3,"*** max degree = ", degreeboundf," *** "),
dprint(3,"************************"),
/* step 2: find all monic irreducible polynomials fi such that deg(fi) <= degreebound and fi divides D[fi] */
[%Ci,fListofTerms] : PolyList(varlist,_k,%f), /* we have to reverse the varlist, so that the added term is always the leading term (note that varlist is [x1,x2,x3,x4,...,xn] and we have the ordering x1>x2>x3>x4>...>xn )*/
/* fList contains a monomial basis (we need this for computation of the extactic and algebraic multiplicity) */
dprint(3,"fList = ",fListofTerms),
fListofTerms:rest(reverse(fListofTerms)), /* strip the constant (last element) because we don't want to start with that (or do we?)*/
/*apply(declare,[''%Ci,constant]),*/
dprint(3,"%Ci = ",%Ci),
fi_backup : %Ci[1],
/* TODO: note that fList now contains the leading terms, in order. We can use that whenever we need the leading term of f */
/* note that %Ci contains the leading coefficients, in order */
/* 2. */
fList:[],
/* naively construct the test polynomial. */
/* Maybe this is faster: first use all first order polynomials f1+x, f1+y, then the first order polynomials f1 + f2x + y, */
_i:1,
for f in fListofTerms do (
fi:fi_backup + f,
fList:endcons(fi,fList),
fi_backup : fi_backup + %Ci[_i+1]*f,
_i:_i+1
),
/* fList now contains the complete polynomial*/
dprint(3,"fList = ",fList),
degree_f:1,
while length(fList)#0 and EXIT=false do (
fi:first(fList), fList:rest(fList), /* we do it in this way because we can then add new fi to the list*/
gi:0,
degree_f : degree_l_t(fi,varlist),
dprint(1,"********************************"),
dprint(1,"fi = ",fi),
dprint(1,"degree(fi) = ",degree_f),
dprint(1,"********************************"),
dprint(3,"P = ",_P),
dprint(3,"Q = ",_Q),
dprint(3,"x = ",_x),
dprint(3,"y = ",_y),
/*Dfi : ratexpand(_P*diff(fi,_x) + _Q*diff(fi,_y)),*/
Dfi : _P*diff(fi,_x) + _Q*diff(fi,_y),
dprint(3,"Dfi = ",Dfi),
/* !!!!!!!!!!!!!!! */
/* so how do we know when to do this substitution ????? */
/* maybe: first switch back to original variables, simplify, then go back to internal variables */
/* only do this if we have more than two variables in varlist */
/* TODO: ratsimp is usually enough but is there a benefit in using radcan as well? */
/* when is this beneficial? it makes 1.62,1.63 fail, but with makes 1.112 run! without: 192 runs*/
if (convertVariables=true) then (
Dfi : fullratsimp(lratsubst(map("=",varlist,original_variables),Dfi)),
dprint(5,"Dfi = ",Dfi),
Dfi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Dfi),
dprint(5,"Dfi = ",Dfi)
),
indivisible : false,
feqns : [],
while not(indivisible) and (Dfi#0) and (fi#0) do ( /* nijso added fi#0*/
dprint(3,"fi = ",fi),
dprint(3,"fi = ",grind(fi)),
/* sometimes (when using non-rational approach) we get fractions and we need to divide fi by the gcd */
/* TODO: when do we need to do this? It seems that this line is obsolete! If no further problems are */
/* detected, lets delete it in january 2017 */
/*fi : poly_primitive_part(fi,varlist),*/
dprint(3,"Dfi = ",Dfi),
/* leading term of fi divides leading term of Dfi ? */
lt_fi : l_t(fi,varlist),
dprint(3,"lt_fi = ",lt_fi),
/*
if freeof(%x3,lt_fi) and freeof(%x4,lt_fi) and freeof(lt_fi,Dfi) then (
dprint(1,"trying to convert auxiliary variables to primary variables..."),
Dfi : fullratsimp(lratsubst(map("=",varlist,original_variables),Dfi)),
dprint(1,"Dfi = ",Dfi),
Dfi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Dfi),
dprint(1,"Dfi = ",Dfi)
),
*/
/*dprint(5,"WE ARE GOING TO COMPUTE lt_DFI ",Dfi," ",varlist),*/
lt_Dfi : l_t(Dfi,varlist),
dprint(5,"lt_Dfi = ",lt_Dfi),
/* leading coefficients */
/*lc_Dfi : l_c(lt_Dfi,varlist),*/ /* leading coeff can be 2*a, 3.0*%e, etc. */
lc_Dfi : constant_factors(lt_Dfi,varlist), /* call directly for speedup*/
/*print("varlist = ",varlist), */
dprint(5,"lc_Dfi = ",lc_Dfi, "constant = ",constantp(lc_Dfi)),
counter: length(fi_in(lc_Dfi,%Ci)),
dprint(5,"******************* F|DF ??? ***********************"),
Dfi_fi : monomialdivide(lt_Dfi,lt_fi,varlist), /* divide lt(Dfi) by lt(fi) */
dprint(5,"lt(Dfi)/lt(fi) = ",Dfi_fi),
dprint(5,"number of fi's in Dfi_fi = ",counter),
if Dfi_fi#false then (
dprint(5,"lt(fi) divides lt(Dfi)"),
/* lt(f) divides lt(Df) */
/*gi : ratexpand(ratsimp(gi + Dfi_fi)),*/
gi : ratsimp(gi + Dfi_fi),
dprint(5,"gi = ",gi),
Dfi : ratsimp(Dfi - fi*Dfi_fi)
)
else if (constantp(lc_Dfi) and counter=0) then (dprint(3,"***** INDIVISIBLE *****"),indivisible:true)
else if counter=1 then (
dprint(3,"********************************"),
dprint(5,"there is exactly one unknown coefficient in lc_Dfi"),
dprint(3,"********************************"),
dprint(3,"feqns = ",feqns),
dprint(3,"********************************"),
_var:fi_in(lc_Dfi,%Ci)[1], /* get me the unknown coefficient */
dprint(5,"vars in lc_Dfi = ",grind(_var)),
dprint(5,"lc_Dfi = ",grind(lc_Dfi)),
/* number of fi's in lc_Dfi = 1 */
/* step 1: solve for the list s */
sList : solve(lc_Dfi,_var),
dprint(5,"solution s = ",sList), /* sList might be a rational expression that can be simplified (already done below) */
/* RATIONAL APPROACH : check if the solution is rational */
/* why simplify slist at this point? */
/*sList : radcan(sList), */
dprint(5,"solution sList = ",sList), /* sList might be a rational expression that can be simplified (already done below) */
/* throw away all non-integers (rational approach!) */
/*sList : sublist(map(lambda([__x],rhs(__x)),sList),integerp), This command gives a list with only the right hand side */
/* TODO: maybe better to use 'factor' instead of solve to fill sList? is it faster? */
/* note: we do not yet want to throw away imaginary terms! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* not so fast! we first need to check if the content of the test polynomial is without fractions (we divide by the gcd of all coefficients)*/
/* so at this point we need to split into numerator and denominator and multiply the test polynomial with the denominator */
/* to get rid of fractions (we have poly_primitive_part command for this )*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/*if freeof(%i,sList) then sList : sublist(sList,lambda([__x],integerp(rhs(__x)))),*/
/*print("sList, keeping %i = ",sList),*/
/* extra check for sqrt functions, should we check for more?*/
/*
if not(freeof(sqrt,dispform(sList,all))) then sList : sublist(sList,lambda([__x],integerp(rhs(__x)))),
print("sList, throwing away sqrt = ",sList),
*/
if sList # [] then (
fiList : makelist(fi,i,1,length(sList)),
feqnsList : makelist(feqns,i,1,length(sList)), /* equationslist */
giList : makelist(gi,i,1,length(sList)),
DfiList : makelist(Dfi,i,1,length(sList)),
/* we could have more than one solution for var. We have loop over all solutions */
dprint(3,"fiList = ",fiList),
dprint(3,"giList = ",giList),
dprint(3,"DfiList = ",DfiList),
/*fList : append(fiList,fList), *//* add the solutions to sList*/
/* TODO: radcan is very slow. Do we really need this? there was a benefit using it in Dfi to simplify kamke1.39 */
for s in sList do (
dprint(5," * s=",s),
/*Dfi : first(DfiList), Dfi : ratexpand(ratsimp(radcan(subst(s,Dfi)))), DfiList : endcons(Dfi,rest(DfiList)),*/
Dfi : first(DfiList), Dfi : ((radcan(subst(s,Dfi)))), DfiList : endcons(Dfi,rest(DfiList)),
/* if Dfi=0 then all fi are solved, we can keep all fi in the list fi */
fi : first(fiList), fi : (ratsimp((subst(s,fi)))), fiList : endcons(fi,rest(fiList)),
gi : first(giList), gi : (ratsimp((subst(s,gi)))), giList : endcons(gi,rest(giList)),
feqns : first(feqnsList), feqns : (ratsimp((subst(s,feqns)))), feqnsList : endcons(feqns,rest(feqnsList)),
/* maybe the previous command reduced a term in feqn to zero (there was a term f1*f2 and we did a subst(f2=0))*/
/* actually, if this happens, then it might be that other terms also simplify, but we can catch that with grobner */
/* we should remove duplicates and zeros from feqns (NIJSO: can we also have this for fi,gi,Dfi?????)*/
feqns:delete(0,feqns),
feqns:unique(feqns),
dprint(3,"feqns = ",feqns),
dprint(3,"fiList = ",fiList),
dprint(3,"giList = ",giList)
/* if there are equations in feqns, then check if they can now be solved */
/* if they can be solved, then substitute the solved %fi coefficients and add f into the filist */
),
fList : append(rest(reverse(fiList)),fList), /* we skip the last one and keep this value in fi*/
/*print("fList = ",fList), */
dprint(3,"fi = ",fi),
dprint(3,"Dfi = ",Dfi),
dprint(3,"gi = ",gi),
if Dfi=0 and gi=0 then fi:0 /* Dfi,gi=0 happens when the variables in fi cancel, i.e. when varlist:[y,x,sqrt(x)] and fi:x - sqrt(x)^2 */
) else (
indivisible : true /* there are no integer solutions */
)
) else (
/* we have more than 1 fi in lc_Dfi, we add it to feqns */
dprint(3,"there are more than 1 unknowns in the leading coefficient"),
feqns : cons(lc_Dfi,feqns), /* add lc_Dfi to the list of feqns */
dprint(3,"********************************"),
dprint(3,"feqns = ",feqns),
dprint(3,"********************************"),
/*Dfi : expand(Dfi - lt_Dfi),*/ /* nijso: ratexpand -> expand because it also simplifies expressions */
Dfi : fullratsimp(Dfi - lt_Dfi), /* nijso: ratexpand -> expand because it also simplifies expressions */
dprint(3,"Dfi-lt_Dfi = ",grind(Dfi))
)
), /* end while loop */
/* ************************************************************************** */
dprint(3,"Dfi = ",Dfi), /* this must be 0*/
dprint(3,"feqns:",grind(feqns)),
if not(indivisible) and (length(feqns)#0) then (
dprint(1,"Warning: we need to compute a groebner base (This is computationally expensive)!"),
/* 1/2 compute groebner base */
/* 2/2 if system is consistent then all unknown coefficients in fi and gi can be determined */
/* else jump the next step and try the next fi */
_var : fi_in(feqns,%Ci),
dprint(3,"unknown variables: ",_var),
feqns_grobner : poly_reduced_grobner(feqns,_var), /* todo? why poly_reduced_groebner? */
dprint(3,"reduced grobner basis of feqns = ",feqns_grobner),
/*
if (length(feqns_grobner)=1) then if (feqns_grobner[1]=1) then
print("inconsistent case!")
else (
*/
/* all coefficients can be computed */
%rnum_list:[],
sList : algsys(feqns_grobner,_var), /* TODO: why algsys? */
dprint(3,"sList = ",sList),
for r in %rnum_list do sList:subst(0,r,sList), %rnum_list:[], /* replace all free variables with a value (here: 0)*/
dprint(3,"sList = ",sList),
/* we now have multiple solutions for fi. We now change fi and gi into a list. we first copy fi with the unknown coefficients*/
/*
fiList : makelist(fi,i,1,length(sList)),
giList : makelist(gi,i,1,length(sList)),
*/
fiList : [],giList:[],
dprint(3,"fiList = ",fiList),
dprint(3,"giList = ",giList),
for s in sList do (
dprint(3,"s = ",s),
/* fi:first(fiList), fi : subst(s,fi), fiList: endcons(fi,rest(fiList)),
gi:first(giList), gi : subst(s,gi), giList: endcons(gi,rest(giList))
*/
fiList : endcons(subst(s,fi),fiList),
giList : endcons(subst(s,gi),giList)
),
dprint(3,"fiList = ",fiList),
dprint(3,"giList = ",giList),
/* put the list in fi and gi*/
fi : fiList,
gi : giList
),
dprint(3,"indivisible:",indivisible),
if not(indivisible) then (
/* make a copy of the old Sfg, because we have to check irreducibility excluding fi that are added in this loop */
/*Sfg0 : Sfg, print("Sfg0 = ",Sfg0), */
dprint(3,"fi = ",fi),
dprint(3,"gi = ",gi),
dprint(3,"fiList = ",fiList),
dprint(3,"giList = ",giList),
/* compute fi*conj(fi) to get a real fi, and compute D[f]/f to get the real cofactor*/
/* note: if we find one complex fi, do we know which of the next equations will give us the complex conjugate? */
/* if we do, we can skip this equation */
dprint(3,"realSystem : ",realSystem),
/* it is possible that f still has a free variable, e.g. kamke 1.118 (and that f|D[f] with this free variable), so we simply put this free variable to 0 */
if not lfreeof(%Ci,fi) then (
dprint(0,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),
dprint(0,"Invariant algebraic curve found with free variable!" ),
dprint(0,"Extra free variables may be present in the solution!"),
dprint(0,"Multiple solutions may be possible! Setting the variable to 0!"),
dprint(0,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),
for _c in %Ci do fi:subst(0,_c,fi)
),
/* make fi,gi into a list, */
/* at this point we can also add all other solved fi that are in fiList */
fi : flatten([fi]),
gi : flatten([gi]),
tmpgiList : giList, /* TODO: I don't like working with tmplists*/
for f in fiList do (
g : first(tmpgiList),tmpgiList:rest(tmpgiList),
if lfreeof(%Ci,f) and freeof(f,fi) then (fi : endcons(f,fi),fiList:delete(f,fiList),gi:endcons(g,gi),giList:delete(g,giList))
),
dprint(3,"fi = ",fi),
dprint(3,"gi = ",gi),
fiReal : [],
giReal : [],
for f in fi do (
g : first(gi), gi:rest(gi),
if (realSystem=true) and (convertImaginary=true) and not(freeof(%i,f)) then (
dprint(1,"fi is complex, using fi*conj(fi) as Darboux polynomial instead : "),
fReal : ratsimp(f*conjugate(f)),
/* !!!!! at this location, we should check if fReal can be factored - if so, factor and compute the gReals*/
/*sublist(list_of_factors(fReal),lambda([_x],not(integerp(_x)))),*/ /* throw away the multiplicities */
gReal : ratsimp((_P*diff(fReal,_x) + _Q*diff(fReal,_y))/fReal),
if freeof(%i,fReal) then (
f : fReal,
g : gReal
) else (
dprint(1,"Warning: invariant algebraic curves were not simplified to real, keeping them complex!")
)
),
/* always recompute g */
/*g : ratsimp((_P*diff(fReal,_x) + _Q*diff(fReal,_y))/fReal),*/
fiReal : endcons(f,fiReal),
dprint(3,"fiReal = ",f, fiReal),
giReal : endcons(g,giReal),
dprint(3,"giReal = ",g, giReal)
),
dprint(3,"fiReal = ",fiReal),
dprint(3,"giReal = ",giReal),
fi : fiReal,
gi : giReal,
dprint(3,"fi = ",fi),
dprint(3,"gi = ",gi),
/* at this point, check if the fi are trivial by converting back to normal variables and simplifying*/
fi_originalVariables : lratsubst(map("=",varlist,original_variables),fi),
fi_originalVariables : trigreduce(trigsimp(ratsimp(fi_originalVariables))),
dprint(3,"fi = ",fi),
/* check if fi is a multiple of an existing fi */
fi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),fi_originalVariables),
/* also try to simplify the cofactors (e.g. kamke1.112 needs this) */
gi_originalVariables : lratsubst(map("=",varlist,original_variables),gi),
gi_originalVariables : ratsimp(gi_originalVariables),
gi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),gi_originalVariables),
dprint(3,"fi = ",fi),
dprint(3,"gi = ",gi),
for f in fi do (
g : first(gi), gi : rest(gi),
/* divide by the gcd of the coefficients to eliminate fractional coefficients */
/* we can do this because D[c*f]/(c*f) = c*D[f]/(c*f) = D[f]/f */
f: poly_primitive_part(f,varlist),
if lfreeof(varlist,f) then (
dprint(3,"f is trivial : f=",f)
)
else if not(freeof(sqrt,dispform(f,all))) then (
/* we keep the solutions with square roots, but we do not check for irreducibility */
dprint(3,"f contains square roots, adding anyway : f=",f),
Sfg : cons([f,g],Sfg) /* add [f,g] to the list of Darboux polynomials and cofactors */
)
else if irreducible(f,Sfg,varlist) then (
dprint(3,"irreducible"),
Sfg : cons([f,g],Sfg), /* add [f,g] to the list of Darboux polynomials and cofactors */
dprint(3,"*** list of Darboux polynomials f and cofactors g: [[f1,g1],[f2,g2],...] = "),
dprint(3,"Sfg = ",Sfg)
/* TODO: it can happen that we find a reducible polynomial with factors that are not in Sfg, we then need to add all factors to Sfg! */
) else (
dprint(3,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),
dprint(3,"!!!!!!!!!! not irreducible !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),
dprint(3,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
)
)
),
dprint(3,"wrapping up, preparing for the next f! "),
dprint(3,"Sfg = ",Sfg),
/* if in the previous step we had an indivisible result or the result was irreducible, there is no need to go through the steps below because there was no new information added */
if not(indivisible) and Sfg#[] then (
/* get the cofactors g from Sfg and multiply with the variable ni, i=1..length(Sfg) */
niList : makelist(concat(n,i),i,length(Sfg)),
dprint(3,"niList = ",niList),
/* ********************************************************************************** */
/* step 3, decide if there are constants ni, not all zero, such that sum(n_i*g_i) = 0 */
/* ********************************************************************************** */
dprint(3,"***** STEP 3 ***** "),
Sum_nigi : apply("+",niList*map(rest,Sfg))[1],
dprint(3,"sum_nigi = ",Sum_nigi),
Sum_nigi_originalVariables : lratsubst(map("=",varlist,original_variables),Sum_nigi),
dprint(3,"sum_nigi = ",Sum_nigi_originalVariables),
Sfg_originalVariables : lratsubst(map("=",varlist,original_variables),Sfg),
/* we need the transformed variables for this because we cannot have e.g. sin(x) as a variable*/
Sum_nigi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Sum_nigi_originalVariables),
dprint(3,"sum_nigi = ",Sum_nigi),
Sfg : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Sfg_originalVariables),
ni : ode1CheckDarboux(Sfg,varlist,niList,Sum_nigi),
Sum_nigi : ratsimp(Sum_nigi),
dprint(3,"sum_nigi = ",Sum_nigi),
Sfg : ratsimp(Sfg),
dprint(3,"sum_nigi = ",Sum_nigi),
dprint(3,"Sfg = ",Sfg),
dprint(3,"Vars = ",varlist),
if ni # [] then (
if length(delete(0,ni)) # 0 then (
EXIT : true,
method: "firstIntegral",
dprint(1," ***** FIRST INTEGRAL FOUND ***** "),
return(method)
)
),
/* ********************************************************************************** */
/* step 4: step 3 failed, now we construct a nonzero right hand side -(dP/dx + dQ/dy) and add to Sum_nigi */
/* note we assume that varlist[1] is the dependent variable and varlist[2] is the dependent variable, this is prone to error! */
/* ********************************************************************************** */
dprint(3,"***** STEP 4 ***** "),
Sum_nigi : ratsimp(Sum_nigi - dPdx_plus_dQdy),
dprint(3,"dPdx+dQdy = ",dPdx_plus_dQdy),
dprint(3,"dPdx+dQdy = ",grind(dPdx_plus_dQdy)),
dprint(3,"sum_nigi = ",Sum_nigi),
Sum_nigi_originalVariables : lratsubst(map("=",varlist,original_variables),Sum_nigi),
Sfg_originalVariables : lratsubst(map("=",varlist,original_variables),Sfg),
Sum_nigi : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Sum_nigi_originalVariables),
Sfg : lratsubst(map("=",reverse(original_variables),reverse(varlist)),Sfg_originalVariables),
ni : ode1CheckDarboux(Sfg,varlist,niList,Sum_nigi),
Sum_nigi : ratsimp(Sum_nigi),
Sfg : ratsimp(Sfg),
dprint(3,"sum_nigi = ",Sum_nigi),
dprint(3,"Sfg = ",Sfg),
dprint(3,"Vars = ",varlist),
if ni # [] then (
EXIT : true,
method:"integratingFactor",
dprint(1," ***** INTEGRATING FACTOR FOUND ***** "),
return(method)
),
/* ********************************************************************************** */
/* step 5: step 4 failed, now we try to find an exponential factor and determine the multiplicity */
/* ********************************************************************************** */
if (searchExponentialFactors = true) then (
dprint(3,"***** STEP 5 ***** "),
Sfg : delete([0,0],Sfg), /* delete darboux polynomials zero */
/* note that we have as exponential factors exp(P/Q) and that Q can only be an invariant algebraic curve */
/* Note that when taking into account the line at infinity, Q can be trivial, and there are odes with Liouvillian first integrals */
/* that do not have invariant algebraic curves, but only an exponential factor */
/* when do we need to search for exponential factors? only when we have already found Darboux polynomials, so length(Sfg)#0 ? */
/* we can also construct Pdh/dx + Qdh/dy = h*k + f*k_g , with f and k the invariant algebraic curves and the cofactors*/
/* note that Q = f1^m1 * f2^m2 * ... * fn^mn with fi the invariant algebraic curves */
if Sfg#[] then (
deg_Q : 1,
deg_P : 1, /* note that the degree of P deg(P) is bound by deg(P)=deg(Q) + max(deg(M),deg(N)) */
while (deg_Q <= degreeboundQ) do (
dprint(3," *** exponential factor: deg(Q)=",deg_Q," / ",degreeboundQ),
degreeboundP : min(deg_Q + max(degree_l_t(_P,varlist),degree_l_t(_Q,varlist)),degreeboundP),
dprint(3,"degreeboundP = ",degreeboundP),
while (deg_P <= degreeboundP) do (
dprint(3," *** exponential factor: deg(P)= ",deg_P," / ",degreeboundP),
mi: [],
for i in integer_partitions(deg_Q,length(Sfg)) do (mi:append(mi,listify(permutations(i)))),
dprint(3,"exponents mi = ",mi),
/* >>>> loop from degree of P is 1 to maxdeg_P */
/* construct polynomial for P */
[%ai,pListofTerms] : PolyList(varlist,deg_P,%a),
polyP : apply("+",apply("*",[reverse(%ai),pListofTerms])),