summaryrefslogtreecommitdiff
path: root/web/reduce/rweb/appl/integrator.web
blob: abdfb6a1d29ef184260bcf3e085577967f5d9904 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
% Copyright (c) 1991 Marcel Roelofs, University of Twente, Enschede,
% The Netherlands.
%
% $Header: integrator.web,v 0.92 91/12/18 17:39:37 roelofs Exp $
%
\input specification
\def\Version$#1Revision: #2 ${Version #2}
\def\title{INTEGRATOR}
\font\titlefont=cmcsc10 scaled\magstep3
\font\ttitlefont=cmtt10 scaled\magstep4
\def\topofcontents{\null\vfill
\centerline{\titlefont The {\ttitlefont INTEGRATOR} package for REDUCE}
\vskip15pt\centerline{\Version$Revision: 0.92 $}
\vskip15pt\centerline{\sc Marcel Roelofs}\vfill}
\def\enditem{\medskip\noindent\ignorespaces}
\def\pde{p.d.e.}

@*=Introduction. In this \.{WEB} file we shall describe a REDUCE package for 
the integration of overdetermined systems of partial differential
equations (p.d.e.'s). This work is mainly based on a similar package by Paul
Kersten for just the determination of symmetry groups and an extension
by myself which also allows the determination of Wahlquist and
Estabrook prolongation algebras. 

The main reasons for the implementation of this package, are our
improved insight in the internals of REDUCE, the wish to have one
combined integrator for both cases and the availability of substantially
improved versions of some the procedures used in the former packages.

\medskip

The ``banner line'' defined here is intended for indentification
purposes on loading. It should be changed whenever this file is
modified. System dependent changes, however, should be made in a
separate change file.

@d banner="Integrator package for REDUCE 3.4, $Revision: 0.92 $"

@ We define the following macros for clarity.
@d change_to_symbolic_mode =symbolic
@d change_to_algebraic_mode =algebraic
@d stop_with_error(string_1,expr_1,string_2,expr_2) = @/
  msgpri(string_1,expr_1,string_2,expr_2,t) @;
@d message(string_1,expr_1,string_2,expr_2) = @/
  msgpri(string_1,expr_1,string_2,expr_2,nil) @;
@d operator_name_of=car
@d arguments_of=cdr
@d first_argument_of=cadr
@d second_argument_of=caddr
@d first_element_of=car
@d rest_of=cdr
@d skip_list=cdr   %Skip the |'list| in front of an algebraic list%
@f function = identifier

@ The following macros are intended as common programming idioms.
@d incr(x) = (x:=x+1)@;
@d decr(x) = (x:=x-1)@;

@ A new REDUCE switch can be introduced using the following code.

@d initialize_global(global_name,value)=@/
global '(global_name)$@/
global_name:=value
@d initialize_fluid(fluid_name,value)=@/
fluid '(fluid_name)$@/
fluid_name:=value
@d new_switch(switch_name,value)=@/
initialize_fluid(!* @& switch_name,value)$@/
flag('(switch_name),'switch)

@ We do all initializations in the beginning of the package.  
@u
change_to_symbolic_mode$@/ 
write banner$terpri()$@/
@<Lisp initializations@>@/
change_to_algebraic_mode$

@*=Integration of overdetermined systems of \pde's.
For the determination of symmetry groups or prolongation structures of
(systems of) partial differential equations, the defining relations
give rise to an overdetermined system of \pde's. Finding the symmetry
group or prolongation structure boils down to solving such a system. 

There are, however, some differences between the determination of a
symmetry group or the determination of a prolongation structure. These
differences are:\medskip 

\item{1.} The differential equations for the determination of the
symmetry group are linear, the equations for the determination of a
prolongation structure are nonlinear. This nonlinearity, however, is
of a special kind, namely, the only occuring nonlinear terms are
(possibly nested) liebrackets of the functions to be integrated.

\item{2.} For the determination of symmetry groups, the functions to be
determined integrate to polynomials with constant coefficients. For
the determination of prolongation structures, functions integrate to
polynomials, coefficients of which are generators of some unknown Lie
algebra. The defining relations of this algebra are the remaining
(nonlinear) relations which have no dependency on the independent
variables involved.

\enditem
From the above it is clear that integration has to be treated slightly
different in either of the cases. The differences are however small
enough to allow the implementation of one integrator for both cases.

@ In order to explain all possible p.d.e.'s which can be integrated, we make
the following assumptions:\medskip

\item{1.} Functions are represented by expressions $f(n)$, where $f$ is
some specified operator and $n$ is an integer. Since we intend to use
the package for computations for supersymmetric p.d.e.'s, we shall use
the notion the elements with $n$ positive must integrate to an even
polynomial and elements with negative $n$ must integrate to an odd
polynomial (this is only useful for computations in prolongation
theory, where coefficients can be even or odd Lie algebra generators).

\item{2.} The dependencies of functions are solely listed on the
dependency list, i.e.\ must be stated by the 'depend' statement of REDUCE.
Notice, however, that we do not allow dependencies of odd variables.
The reason for this is a pragmatic one: due to the anticommutivity of
odd variables, $n$ odd variables can only produce $2^n$ different
terms containing these variables, hence can be stated explicitly
provided that $n$ is not too big. On the other hand, if we allow
dependencies of odd variables, a lot of additional operators have to
be implemented to take care of e.g. partial differentation w.r.t. odd
variables.
\medskip

@ If $f$ is the operator denoting functions, $x$ the operator denoting
Lie algebra generators (or, in the case of a symmetry group, just
constants), then following the description above, a p.d.e.\
has the following possible terms (any coefficient $c$ is always some polynomial
in the independent variables):\medskip

\item{A.} terms of the form $c_n \hbox{df}(f(n),\dots)$.

\item{B.} terms of the form $c_n f(n)$.

\item{C.} terms of the form $c_{1,2}[z_1,z_2]$ where $z_1,z_2$ are
either functions $f(n)$ or Lie algebra generators $x(n)$.

\item{D.} terms of the form $c_n x(n)$.
\medskip

These possibilities lead, in a natural way, to the following strategy
of solving the p.d.e.'s:\medskip

\item{1.} If there is only one term of type A, we can integrate this
equation homogeneously, i.e. give a polynomial expression for $f(n)$
using the variables involved in the differential term.

\item{2.} If the p.d.e.\ is a polynomial in one or more independent
variables on which none of the occuring functions depend, all
coefficients of this polynomial have to be zero, i.e., the p.d.e.\
splits up into a set of smaller p.d.e.'s.

\item{3.} If there are only terms of type C and D we have a Lie
algebra relation, which can be solved by the LIESUPER package, if
solvable.

\item{4.} If there is a function of type B depending on all variables
occuring in the p.d.e.\ and not occuring in a term of type A, we can
solve for this function.

\item{5.} If there is one term of type A depending on all variables
occuring the p.d.e.\ and the remaining terms are polynomial in the
variables occuring in the derivative, the p.d.e.\ can be integrated
inhomogeneously.

\item{6.} If there is just one function in the p.d.e.\ which depends on a
variable only occuring polynomially in the rest of the p.d.e., such
that the p.d.e.\ can not be integrated inhomogeneously since the
dependencies of the various occuring functions do not match, we can
introduce new equations of type 1 by appropriately differentiating the
p.d.e.

@*1 Initializing an equation set.
The integrator will be implemented in such a way that integration
can be performed on different sets of p.d.e.'s at the same time.
Different sets of p.d.e.'s will be distinguished by the name of the
operator in which they are stored.

For each operator representing a set of p.d.e.'s we must know: the
name of the operator(s) representing the functions and the operator
that must be used to represent constants coefficients during the
integration. If this last operator is of rtype 'algebra\_generator' we
know that we are in the prolongation case and the name of the
associated liebracket can be found on the property list of this
operator.

Moreover, we have to know the total number of equations used, in view of
the additional equations that may be generated and which must be
numbered subsequently. 
In connection with the integrations taking place we also have to know the
number of functions, resp. constants (generators) being in use. 

This is all taken care of by the procedure |initialize_equations|,
which assigns to an operator |operator_name|, the total number of used
equations |total_used|, the list |variable_list| of all occuring independent
variables, the operator |constant_operator|, elements of
which act as constants, and an arbitrary number of operators
|function_operator| acting as functions.
|constant_operator| and each |function_operator| should be given a an
algebraic list of the form $\{$operator, number of even elements used,
number of odd elements used$\}$.

In order to allow an arbitrary number of parameters we make
|initialize_equations| a |psopfn|. How |psopfn|'s are dealt with
internally is explained in the documentation of either the TOOLS
package or the LIESUPER package.

@<Lisp ini...@>=@/
put('initialize_equations,'psopfn,'initialize_equations1)$

@ 
@u
lisp procedure initialize_equations1 specification_list;
begin scalar operator_name,total_used,variable_list,
             specification,even_used,odd_used,
             constant_operator,bracketname,function_name,function_list;
  if length specification_list<5 then
  rederr("INITIALIZE_EQUATIONS: wrong number of parameters");
  if not idp(operator_name:=first_element_of specification_list) then
  rederr("INITIALIZE_EQUATIONS: equations operator must be identifier");
  if not fixp(total_used:=
      reval first_element_of(specification_list:=rest_of specification_list)) 
     or total_used<0 then 
  rederr("INITIALIZE_EQUATIONS: total number of equations must be positive");
  put(operator_name,'total_used,total_used);
  variable_list:=reval first_element_of(
      specification_list:=rest_of specification_list);
  if atom variable_list or operator_name_of variable_list neq 'list then
     rederr("INITIALIZE_EQUATIONS: variable list must be algebraic list");
  put(operator_name,'variable_list,skip_list variable_list);
  @<Check and initialize |constant_operator|@>;
  @<Check and initialize |function_list|@>;
end$

@ The |constant_operator| can either be of rtype |algebra_generator|
or not. If so, we also have to assign the associated liebracket to
|operator_name| and used the procedure |define_used| to take care of
the assignment of the used dimensions to the liebracket. If
|constant_operator| is not an |algebra_generator|, we store these
dimensions in the same way as happens for liebrackets.

@d check_valid_function_declaration(op_list,op_name)=@/
if atom op_list or length op_list neq 4 or operator_name_of op_list neq 'list@| 
   or not idp(op_name:=first_argument_of op_list) or 
   not fixp(even_used:=reval caddr op_list) @| or 
   not fixp(odd_used:=reval cadddr op_list)
   or even_used<0 or odd_used<0 then @/
       stop_with_error("INITIALIZE_EQUATIONS: invalid declaration of",
                        op_list,nil,nil)

@d put_used_dimensions(op_name,even_used,odd_used)=@/
     if get(op_name,'rtype)='algebra_generator then@/
       define_used(bracketname,list('list,even_used,odd_used))
     else
     begin
       put(op_name,'even_used,even_used);@/
       put(op_name,'odd_used,odd_used);
     end

@<Check and initialize |constan...@>=@/
specification_list:=rest_of specification_list;
specification:=first_element_of specification_list;
check_valid_function_declaration(specification,constant_operator);
put(operator_name,'constant_operator,constant_operator);
if get(constant_operator,'rtype)='algebra_generator then@/
  put(operator_name,'bracketname,
      bracketname:=get(constant_operator,'bracketname));
put_used_dimensions(constant_operator,even_used,odd_used)

@ 
@<Check and initialize |fu...@>=@/
for each function_specification in rest_of specification_list do
begin
  check_valid_function_declaration(function_specification,function_name);
  put_used_dimensions(function_name,even_used,odd_used);
  function_list:=function_name . function_list;
end;
put(operator_name,'function_list,function_list)

@ Since we can apparently choose different sets of p.d.e.'s for
solving, we must tell the integrator which set to take. This is done
via a global variable |current_equation_set!*|. We will take the
operator |equ| as the default |current_equation_set!*|.
In this file we will use the abbreviation |ces!*| for
|current_equation_set!*|.

@d ces!*=current_equation_set!*

@<Lisp ini...@>=@/
initialize_global(ces!*,'equ)$

@ 
@u
lisp operator use_equations;@/
lisp procedure use_equations operator_name;
begin
  if idp operator_name then
    ces!*:=operator_name
  else rederr("USE_EQUATIONS: argument must be identifier");
end$

@*1 The integration procedure.
The implementation of the integrator follows the description of all
the possible steps given above.

\noindent For the use of the fluid variable |listpri_depth!*|, see below. Its
local rebinding is necessary for a proper printing of the messages
given by the procedure.

@u 
lisp operator integrate_equation;
lisp procedure integrate_equation n;
begin scalar listpri_depth!*,total_used,equation,denominator,
   solvable_kernel,solvable_kernels,df_list,df_kernel,
   function_list,present_functions_list,variable_list,absent_variables,
   polynomial_variables,equations_list,linear_functions_list,constants_list,
   bracketname,df_terms,df_functions,@|
   linear_functions,functions_and_constants_list,commutator_functions,
   present_variables,@|
   inhomogeneous_term,nr_of_variables,integration_variables,
   forbidden_functions,differentiations_list,polynomial_order;
  listpri_depth!*:=200;
  terpri!* t;
  @<Find the equation to be integrated@>;
  @<Step 1: search for homogeneous integration@>;
  @<Step 2: search for polynomial behaviour@>;
  @<Step 3: search for a Lie relation@>;
  @<Step 4: search for a solvable function@>;
  @<Step 5: search for inhomogeneous integration@>;
  @<Step 6: search for a useful differentation@>;
  @<Step 7: print a ``Not solved'' message@>;
solved: %Go here when the equation is solved or its type is determined%
end$

@ The part of the equation containing all necessary information is its
numerator. For reasons that will become clear in the sequel we need,
however, also know its denominator. If the equation is zero, no
analysis has to be performed.

@d nullify_equation(n)=@/
  setk(list(ces!*,n),0)

@<Find the equation...@>=
  if null(total_used:=get(ces!*,'total_used)) or
     n>total_used then 
     stop_with_error("INTEGRATE_EQUATIONS: properly initialize",
                     ces!*,nil,nil);
  if null (equation:=cadr assoc(list(ces!*,n),
                                get(ces!*,'kvalue))) then
    stop_with_error("INTEGRATE_EQUATION:", list(ces!*,n),
       "is non-existent",nil);
  denominator:=denr(equation:=simp!* equation);
  equation:=numr equation;
  if null equation then 
    <<write ces!*,"(",n,") = 0"; terpri!* t;
      nullify_equation(n); goto solved>>
  
@*1 Homogeneous integration. 
Homogeneous integration must be performed if the equation consists
of just one |df| term. In order to find all possible |df| terms we
apply |split_form| to |equation|. This returns a list the |car| of
which is the part of |equation| independent of the |df| operator, the
|cdr| of which is a list of all linear |df| terms, together with their
coefficients. |split_form| will return with an error if nonlinear |df|
terms occur.

@d independent_part_of=car 
@d kc_list_of=cdr
@d kernel_of=car  %For use with a kernel-coefficient list%
@d coefficient_of=cdr %For use with a kernel-coefficient list%

@ If there is one |df| term, we only solve it if its coefficient is a
number, by default. This behaviour is governed by the switch
|coefficient_check|, which is |on| by default. In order to check the coefficient
we will use the procedure |find_solvable_kernel| to be explained below.

@<Lisp ini...@>=
new_switch(coefficient_check,t)$

@
@d assoc_delete(kernel,assoc_list)=@/
   delete(assoc(kernel,assoc_list),assoc_list)
@d successful_message_for(action,kernel)=@/
<<write ces!*,"(",n,"): ",action; maprin kernel; terpri!* nil;@/
  nullify_equation(n); goto solved>>
@d not_a_number_message_for(action,kernel)=@/
<<write "*** ",ces!*,"(",n,"): ",action," failed:"; terpri!* t;@/
           write "    coefficient not a number for ";
           maprin kernel; terpri!* nil;@/
           write "    Solvable with 'off coefficient_check'";@/
           terpri!* t; goto solved>>

@<Step 1...@>=@/
  df_list:=split_form(equation,'(df));
  if null independent_part_of df_list and 
     (kc_list_of df_list) and length(kc_list_of df_list)=1
  then 
    if (solvable_kernel:=find_solvable_kernel(@|
         solvable_kernels:=list(kernel_of first_element_of kc_list_of df_list),@|
                               kc_list_of df_list,denominator)) then
      <<df_kernel:=first_argument_of solvable_kernel;@/
        setk(df_kernel,homogeneous_integration_of(solvable_kernel));@/
        depl!*:=assoc_delete(df_kernel,depl!*);
               %Remove |df_kernel| from the |depl!*| list%
        successful_message_for("Homogeneous integration of ",solvable_kernel)>>
    else not_a_number_message_for("Homogeneous integration",
                                  first_element_of solvable_kernels)

@ The procedure |find_solvable_kernel| tries to find the first element
of |kernel_list| which has a number as coefficient. 
If |coefficient_check| is |off| we can simply take the first element
of |kernel_list|, otherwise we can most conveniently implement a
recursive procedure |first_solvable_kernel|, which finds the first
element of |kernel_list| with a number as coefficient.

@u 
lisp procedure find_solvable_kernel(kernel_list,kc_list,denominator);
if !*coefficient_check then first_solvable_kernel(kernel_list,kc_list,denominator)
else first_element_of kernel_list$

@#
lisp procedure first_solvable_kernel(kernel_list,kc_list,denominator);
if kernel_list then @/
  (if numberp coefficient_of kc_pair or 
      numberp !*ff2a(coefficient_of kc_pair,denominator) 
   then @/ kernel_of kc_pair
   else first_solvable_kernel(rest_of kernel_list,kc_list,denominator))
  where kc_pair=assoc(first_element_of kernel_list,kc_list)$

@ The equation
\def\dd#1#2{{\partial^{#2}\over\partial{#1}^{#2}}}
$$
\dd{x_1}{k_1}\cdots\dd{x_m}{k_m} f(x_1,\dots,x_n)=0\qquad (m\leq n)
$$
has general solution
$$
f=\sum_{j=1}^{m}\sum_{i_j=0}^{k_j-1}
x_j^{i_j}f_{j,i_j}(x_1,\dots,\hat{x_j},\dots,x_n).
$$
Thus, given a homogenous p.d.e., |homogeneous_integration_of| has to
return the REDUCE equivalent of the last expression.

If $f$ depends on only one variable the $f_{j,i_j}$ are constants,
otherwise they are new functions with dependency on one less variable. 
In the Lie algebra case the constants are generators of the Lie
algebra. Since the dimensions of a |liebracket| in REDUCE have to be
given on beforehand, there may not be enough generators left to
generate $f$. In this case, we have to enlarge the |liebracket|.

@d get_dependencies_of(kernel)=@/
  ((if depl_entry then cdr depl_entry)@| where depl_entry=assoc(kernel,depl!*))

@u
lisp procedure homogeneous_integration_of df_term;
begin scalar df_function,function_number,dependency_list,integration_list,
             coefficient_name,bracketname,even_used,odd_used,
             integration_variable,@|
             number_of_integrations,solution,new_dependency_list;
@<Check if |df_term| can be integrated, find |df_function| and
|function_number|@>;
dependency_list:=get_dependencies_of(df_function);
if length dependency_list=1 then 
  coefficient_name:=get(ces!*,'constant_operator)
  else coefficient_name:=operator_name_of df_function;
@<Get |even_used|, |odd_used| and if necessary |bracketname|@>;
integration_list:=rest_of arguments_of df_term;
@<Find the next |integration_variable| and |number_of_integrations|@>;
if bracketname then 
    @<Check and possibly enlarge dimensions of |bracketname|@>;
@<Perform the integration@>;
return solution
end$

@ We required |df_term| to be of the form |df|($f(k),\dots$) where
$f$ is a function occuring on the |function_list| of |ces!*| and $k$
is an integer not equal to zero.

@<Check if |df_term|...@>=@/
df_function:=first_argument_of df_term;
if not member(operator_name_of df_function,get(ces!*,'function_list)) @|
or not fixp(function_number:=first_argument_of df_function) or function_number=0 then
@/stop_with_error("PERFORM_HOMOGENEOUS_INTEGRATION: integration of",
                df_function, "not allowed",nil)

@ In the liebracket case |even_used| and |odd_used| are stored as
properties of |bracketname| instead of |coefficient_name|.

@<Get |even_used|, |odd...@>=
     if get(coefficient_name,'rtype)='algebra_generator then
     begin bracketname:=get(ces!*,'bracketname);@/
       even_used:=get(bracketname,'even_used);
       odd_used:=get(bracketname,'odd_used);
     end
     else
     begin
       even_used:=get(coefficient_name,'even_used);@/
       odd_used:=get(coefficient_name,'odd_used);
     end

@ Finding the integration variables is rather straightforward.

@<Find the next |int...@>=
if integration_list then integration_variable:=first_element_of
integration_list else integration_variable:=nil;
if integration_variable and (integration_list:=rest_of integration_list) @|
   and fixp first_element_of integration_list then 
 <<number_of_integrations:=first_element_of integration_list;
      integration_list:=rest_of integration_list>>
else number_of_integrations:=1

@ If |df_function| depends on only one variable, the number of
constants being introduced is equal to the |number_of_integrations|.
The even and odd dimension of |bracketname| are stored as the
properties |even_dimension| and |odd_dimension|.

@<Check and poss...@>=
if function_number > 0 then @/
  (if even_used+number_of_integrations>get(bracketname,'even_dimension) then@/
     change_dimensions_of(bracketname,even_used+number_of_integrations,@|
                          get(bracketname,'odd_dimension)))
else @/
  (if odd_used+number_of_integrations>get(bracketname,'odd_dimension) then@/
     change_dimensions_of(bracketname,get(bracketname,'even_dimension),
                          odd_used+number_of_integrations))

@ The actual integration is fairly straightforward by now: for all the
possible integration variables we can simply add new terms to
|solution|.

@d new_coefficient=@/
list(coefficient_name,if function_number>0 then
                      incr(even_used) else -incr(odd_used)) 
@d ext_mksq(kernel,power)=@/
if power=0 then 1 ./ 1 else mksq(kernel,power)
@d depend_new_coefficient(dependency_list)=@/
  depl!*:= (list(coefficient_name,if function_number>0 then even_used
else -odd_used) . dependency_list) . depl!*;

@<Perform the integration@>=@/
solution:=nil ./ 1;
while integration_variable do
begin new_dependency_list:=delete(integration_variable,dependency_list);
  for i:=0:number_of_integrations-1 do
  <<solution:=addsq(solution,multsq(ext_mksq(integration_variable,i),
                     mksq(new_coefficient,1)));
    if new_dependency_list then depend_new_coefficient(new_dependency_list)
  >>;
  @<Find the next |int...@>
end;
solution:=mk!*sq subs2 solution;@/
put_used_dimensions(coefficient_name,even_used,odd_used)

@*1 Splitting polynomial equations.
For the polynomial behaviour of |equation| we need to know the
dependencies of all the functions occuring in |equation| at any level.
If there occur any other variables in |equation| and |equation| is
polynomial in these variables, the coefficients of this polynomial
give rise to a new set of equations.

@d pc_list_of=kc_list_of %power-coefficient list%
@d powers_of=kernel_of

@<Step 2...@>=@/
@<Find |present_functions_list| and the |absent_variables|@>;
@<Find the |polynomial_variables| and test for polynomial behaviour@>;
@<If possible, split up |equation| into smaller equations@>

@ Finding all the functions in |equation| can be done by applying the
procedure |get_recursive_kernels| of the TOOLS package.

@<Find |present_functions_list| and the |absent_variables|@>=@/
function_list:=get(ces!*,'function_list);@/
present_functions_list:=get_recursive_kernels(equation,function_list);@/
variable_list:=get(ces!*,'variable_list);
absent_variables:=variable_list;
for each function in present_functions_list do
  for each variable in get_dependencies_of(function) do@/
   absent_variables:=delete(variable,absent_variables)

@ In most cases the equations under consideration are polynomial in any
of the variables and therefore we shall by default not test for
polynomial behaviour. This testing is governed by the switch
|polynomial_check| which, be default, is |off|. If it is |on| testing
is done by the procedure |polynomialp| to be defined below.

@<Find the |polynomial_variables| and test for polynomial behaviour@>=@/
polynomial_variables:=absent_variables;
if !*polynomial_check then@/
  polynomial_variables:=for each variable in polynomial_variables join@/
    if polynomialp(equation,variable) then list(variable)

@ @<Lisp ini...@>=
new_switch(polynomial_check,nil)$

@ Checking a standard form for polynomial behaviour in some kernel can
be done by checking the main variable, the leading coefficient and the
reductum, respectively.

@u 
lisp procedure polynomialp(expression,kernel);
if domainp expression then t
else ((main_variable=kernel or not depends(main_variable,kernel)) @|and
      polynomialp(lc expression,kernel) and polynomialp(red expression,kernel)) @|
      where main_variable=mvar expression$

@ The coefficients of a polynomial can be found by
applying the procedure |multi_split_form| from the TOOLS package.

@<If possible, split up |equation| into smaller equations@>=@/
equations_list:=multi_split_form(equation,polynomial_variables);
if length equations_list>1 then
<<for each pc_pair in pc_list_of equations_list do@/
    setk(list(ces!*,incr(total_used)),
          mk!*sq((coefficient_of pc_pair) ./ 1));
  if independent_part_of equations_list then @/
   setk(list(ces!*,incr(total_used)),
           mk!*sq((independent_part_of equations_list) ./ 1));
  write ces!*,"(",n,") breaks into ",
        ces!*,"(",get(ces!*,'total_used)+1,@|
        "),...,",ces!*,"(",total_used,") by ";@/
  maprin partial_list(polynomial_variables,5);
  terpri!* nil;@/
  nullify_equation(n);
  put(ces!*,'total_used,total_used);
  goto solved
>>

@ In order to get messages in a readable form, we sometimes need to
print lists partially. This is taken care of the following procedures.

@u
lisp procedure partial_list(printed_list,nr_of_items);
'list . broken_list(printed_list,nr_of_items)$
@#
lisp procedure broken_list(list,n);
if list then if n=0 then '(!.!.!.)
else car list . broken_list(cdr list,n-1)$

@*1 Solving Lie algebra relations. 
If the first two steps have failed, we need to analyze |equation| in
a more drastic way: we need to find all functions occuring linearly in
|equation|, and if a liebracket is specified, all commutators and
algebra generators occuring in |equation| as well.
Since we have already looked for |df| terms in |equation| in each next
step we only have to examine the independent part of the previous step.

@<Step 3...@>=@/
linear_functions_list:=split_form(independent_part_of df_list,
                                  function_list);@/
df_list:=kc_list_of df_list;
constants_list:=split_form(independent_part_of linear_functions_list,
                             list get(ces!*,'constant_operator));@/
linear_functions_list:=kc_list_of linear_functions_list;
if (bracketname:=get(ces!*,'bracketname)) then
  @<Solve |equation| if it is a Lie expression@>

@ In the Lie algebra case we can try to solve the Lie expression if
there are no |df| terms or linearly occuring functions. Solving Lie
expression can be done using the procedure |relation_analysis| of the
LIESUPER package. |relation_analysis| returns either the kernel for which
the relation is solved or an atom indicating the nature of the
non-solvability.

@<Solve |equation| if it is a Lie expression@>=
  if length(df_list)=0 and 
     length(linear_functions_list)=0 then
  <<
    if atom(solvable_kernel:=
            relation_analysis(!*ff2a(equation,denominator),bracketname))
    then <<write ces!*,"(",n,") is a non-solvable Lie relation";
           terpri!* t >>
    else <<write ces!*,"(",n,") solved for "; maprin solvable_kernel;
           terpri!* t; nullify_equation(n)>>;
    goto solved
  >>

@*1 Solving a function.
If |equation| is not a Lie expression, there may be a function or a
constant for which we can solve it. In order to do this we need to
\medskip

\item{$-$} find all variables |present_variables|, on which at
least one of the present functions |recursive_functions_list| depends;
of course it is the complement of |absent_variables| in |variable_list|.

\item{$-$} find all linearly occuring functions |solvable_kernels| which
depend on all of the |present_variables|; these are the possible
candidates for solving. If there are no |present_variables|,
|equation| is apparently a relation between some constants and we can
try to solve one.

\item{$-$} remove all functions from |solvable_kernels|, which also
occur in a |df| term, or in the liebracket case, in a commutator.

\item{$-$} if |coefficient_check| is |on| we must only solve for those
functions which have a number as coefficient. This is checked by the procedure
|find_solvable_kernel|.

\enditem
Before doing anything we shall, however, construct lists containing
all functions occuring in |df| terms, occuring linearly (and the
constants) and, if necessary, occuring in commutators. These lists
will also come in handy in the next steps.
 
@<Step 4...@>=
@<Construct |df_terms|, |df_functions|, |linear_functions| and
|commutator_functions|@>;
@<Get |present_variables| and |nr_of_variables|@>;
for each kernel in linear_functions do if length
  get_dependencies_of(kernel)=nr_of_variables then@/
  solvable_kernels:=kernel . solvable_kernels; 
for each kernel in append(df_functions,commutator_functions) do @/
  solvable_kernels:=delete(kernel,solvable_kernels);
if solvable_kernels then 
   @<Try to solve a function@>

@ Of course we are only interested in |df| terms of functions occuring
on |function_list|.

@<Construct |df_terms|, |df_functions|, ...@>=
df_terms:=for each df_term in df_list join 
  if member(operator_name_of first_argument_of kernel_of df_term,function_list) 
    then @/list kernel_of df_term;
for each df_term in df_terms do if not member(first_argument_of
df_term,df_functions) then@/ df_functions:=first_argument_of(df_term) . df_functions;
functions_and_constants_list:=append(linear_functions_list,
                                     kc_list_of constants_list);@/
linear_functions:=for each linear_function in
   functions_and_constants_list collect kernel_of linear_function;
if bracketname then commutator_functions:=@| 
   get_recursive_kernels(independent_part_of constants_list,
                         get(ces!*,'function_list));

@ @<Get |present_variables| and |nr_of_variables|@>=
present_variables:=variable_list;
for each variable in absent_variables do
     present_variables:=delete(variable,present_variables);
nr_of_variables:=length present_variables

@ @<Try to solve a function@>=
   <<solvable_kernel:=
      find_solvable_kernel(solvable_kernels,functions_and_constants_list,denominator);
     if solvable_kernel then 
     <<linear_solve_and_assign(!*ff2a(equation,1),solvable_kernel);
       depl!*:=assoc_delete(solvable_kernel,depl!*);
                   %Remove the dependencies of the solved function%
       successful_message_for("Solved for ",solvable_kernel)
     >>
     else not_a_number_message_for("Solving a function",
                 partial_list(solvable_kernels,3))
   >>

@*1 Inhomogeneous integration.
For an inhomogeneous integration, we are looking for a maximal |df| term,
i.e. which has dependency on all the |present_variables|, such that
the remaining part of |equation| is polynomial in the
variables, w.r.t.\ which the function in the |df| term is
differentiated, i.e.\ {\it a}) we only have to look at |df| terms
which are differentiated w.r.t.\ variables on which none of the
non-maximally occuring functions in |equation| depend, and {\it b}) if
|polynomial_check| is |on|, we must check explicitly if the rest of
|equation| is polynomial in these variables. 

We shall collect the list of ``integrable'' variables in the list
|integration_variables|.

@<Step 5...@>=
@<Find the possible |integration_variables|@>;
@<If possible find and integrate the integrable |df| term |solvable_kernel|@>

@ Finding the |integration_variables| is rather easy using the lists
|df_functions|, |linear_functions| and |commutator_functions|.
Starting with |present_variables| we have to
delete all variables on which on of the |linear_functions| or
|commutator_functions| depend, or one of the |df_functions|, which do
not have maximal dependency, i.e. which do no depend on
|nr_of_variables| variables.

@<Find the possible |int...@>=@/
integration_variables:=present_variables;
for each kernel in append(linear_functions,commutator_functions) do 
  for each variable in get_dependencies_of(kernel) do@/
    integration_variables:=delete(variable,integration_variables);
for each df_function in df_functions do
  if not length get_dependencies_of(df_function)=nr_of_variables then
    for each variable in get_dependencies_of(df_function) do@/
      integration_variables:=delete(variable,integration_variables)

@ Finding the integrable |df| terms is rather easy know: find all
the |df| terms which have maximal dependency and are only
differentiated w.r.t.\ variables occuring on |integration_variables|.
In order to check this last item we need to know the form of |df|
term: it is a list |'(df @tfunction@> @tdifferentiation\_sequence@>)|, where
differentiation\_sequence is a sequence of variables, each variable optionally
followed by a integer indicating the number of differentiations
w.r.t.\ to that variable. The procedure
|check_differentiation_sequence| checks whether all variables in a
differentiation\_sequence are member of the second argument
|variable_list|.

@u 
lisp procedure check_differentiation_sequence(sequence,variable_list);
if null sequence then t
else @+if fixp first_element_of sequence or 
        member(first_element_of sequence,variable_list) then@/
check_differentiation_sequence(rest_of sequence,variable_list)$

@ @<If possible find and integrate...@>=
@<Find the integrable |df_terms|@>;
@<Find a |solvable_kernel|, check the |inhomogeneous_term| and possibly integrate@>

@ There one situation we have to take care of specifically: if there
are more |df_terms| for the same function, only one of which is
differentiated just w.r.t. |integration_variables|, we are not allowed
to integrate, since the function would be expressed in itself. In this
case, we will make |solvable_kernels| a list of at least length 2
in order to prevent integration.

@<Find the integrable |df_terms|@>=
for each df_term in df_terms do
 <<if length get_dependencies_of(first_argument_of df_term)=nr_of_variables @|
     and (check_differentiation_sequence(rest_of arguments_of df_term,
                                        integration_variables)@|
          or member(first_argument_of df_term,forbidden_functions))
   then @/solvable_kernels:=if member(first_argument_of df_term,forbidden_functions)
      then list(nil,nil) else df_term . solvable_kernels;
   forbidden_functions:=(first_argument_of df_term) . forbidden_functions>>;

@ @<Find a |solvable_kernel|, check the |inhomogeneous_term| and possibly integrate@>=
if solvable_kernels then
if length(solvable_kernels)=1 then 
  if (solvable_kernel:=find_solvable_kernel(solvable_kernels,df_list,denominator))
  then 
    if (inhomogeneous_term:=linear_solve(mk!*sq(equation ./ 1),solvable_kernel))@| 
       and (not !*polynomial_check @|or 
            check_polynomial_integration(solvable_kernel,inhomogeneous_term))
    then
       <<df_kernel:=first_argument_of solvable_kernel;@/
         setk(df_kernel,
              inhomogeneous_integration_of(solvable_kernel,inhomogeneous_term));
         depl!*:=assoc_delete(df_kernel,depl!*);
                %Remove |df_kernel| from the |depl!*| list%
         successful_message_for("Inhomogeneous integration of ",solvable_kernel)>>
    else 
     <<write ces!*,"(",n,"): Inhomogeneous integration failed: "; terpri!* t;
       write "inhomogeneous term not polynomial in integration variables";
       terpri!* t; goto solved>>
  else not_a_number_message_for("Inhomogeneous integration",
                                 first_element_of solvable_kernels)
else <<write ces!*,"(",n,"): Inhomogeneous integration failed: "; terpri!* t;
       write "more terms with maximal dependency"; terpri!* t; goto solved>>

@ Checking that the inhomogeneous term is polynomial in the
integration variables is fairly easy. For all the integration
variables we have to check that the denominator does not depend on it
and the numerator should be polynomial.

@u lisp procedure check_polynomial_integration(df_term,integration_term);
begin scalar numerator,denominator,integration_variables,variable,ok;
  numerator:=numr simp integration_term;
  denominator:=denr simp integration_term;@/
  integration_variables:=
    for each argument in rest_of arguments_of df_term join
      if not fixp argument then list argument;
  ok:=t;
  while ok and integration_variables do
    <<variable:=first_element_of integration_variables;
      ok:=(not depends(denominator,variable) and polynomialp(numerator,variable));
      integration_variables:=rest_of integration_variables
    >>;
  return ok;
end$

@ We can perform the inhomogeneous integration by applying
|multi_split_form| to find all the
polynomial components of the inhomogeneous term and
|homogeneous_integration_of| for solving the homogeneous equation.

@u 
lisp procedure inhomogeneous_integration_of(df_term,inhomogeneous_term);
begin scalar df_sequence,integration_variables,int_sequence,
      variable,nr_of_integrations,integration_terms,solution,
      powers,coefficient,int_factor,solution_term,n,k;
  df_sequence:=rest_of arguments_of df_term;
  @<Find the |integration_variables| and |int_sequence|@>;
  integration_terms:=multi_split_form(numr simp inhomogeneous_term,
                                      integration_variables); 
  integration_terms:=(nil . independent_part_of integration_terms) . 
                     pc_list_of integration_terms;
    %Make |integration_terms| a full blown |pc_list|%
  @<Perform the inhomogeneous integration of the numerator of |inhomogeneous_term|@>;
  solution:=multsq(solution,1 ./ denr simp inhomogeneous_term);
  solution:=mk!*sq subs2 addsq(solution,simp homogeneous_integration_of df_term);
  return solution
end$

@ We must analyze |df_sequence| to get all the integration variables,
together with the number of integrations belonging to them.

@<Find the |integration_variables| and ...@>=
  while df_sequence do
  <<variable:=first_element_of df_sequence;
    df_sequence:=rest_of df_sequence;
    if df_sequence and fixp first_element_of df_sequence then
      <<nr_of_integrations:=first_element_of df_sequence;
        df_sequence:=rest_of df_sequence>>
    else nr_of_integrations:=1;
    integration_variables:=variable . integration_variables;
    int_sequence:=(variable . nr_of_integrations) . int_sequence
  >>

@ The particular solution of the equation $F^{(k)}(x)=x^n$ is
$$
F(x)={1\over(n+1)\cdots(n+k)}x^{n+k}.
$$
This process has to be performed for all the terms in
|integration_terms| and for all integrations in |int_sequence|.

@<Perform the inhomogeneous integration ...@>=
solution:=nil ./ 1;
for each term in integration_terms do
<<powers:=powers_of term; coefficient:=coefficient_of term;
  int_factor:=1; solution_term:=1 ./ 1;
  for each integration in int_sequence do
  <<variable:=car integration; k:=cdr integration;@/
    n:=(if power then cdr power @+else 0) where power=assoc(variable,powers); 
        %If |variable| does not occur in |term|, |n=0|%
    for i:=1:k do int_factor:=(n+i)*int_factor;
    solution_term:=multsq(solution_term,mksq(variable,n+k))
  >>;
  solution_term:=multsq(solution_term,coefficient ./ int_factor);
  solution:=addsq(solution,solution_term)
>>

@*1 Generation of new equations by differentiation. 
As a last method of solving we notice the following: if there is a
variable, such that just one |df| term or just one linearly occuring
function depends on it and all the other terms are polynomial in this
variable, let's say of degree $n$, then we can differentiate
|equation| $n+1$ times to get a new equation of type A.

Experience has proven, however, that applying the above mentioned
method, generally will lead to multiple generation of equivalent
terms in the answer. Therefore we will only generate a new equation if
the switch |allow_differentiation| is |on|, otherwise we will only
generate a message that it is possible to generate a new equation of
type A. Solving of such a new equation is always left to the responsibility
of the user.

@<Lisp ini...@>=@/
new_switch(allow_differentiation,nil)$

@ After this introduction it is clear what we have to do for step 6:

@<Step 6...@>=
@<Count the number of occurences of all |present_variables|@>;
@<If possible and allowed, generate new equations@>

@ Counting the occurence of variables is rather easy. For all
functions in |df_terms|, |linear_functions| and
|commutator_functions|, we have to count the occurences of all the
variables in their respective entries on the dependency list |depl!*|.

For this purpose we rebuild |present_variables| to an association list
with entries of the form |variable . origin . number_of_occurences|
where |origin| indicates the |df_term|, |linear_function| or 
|commutator_function| in which |variable| occured last.

The action of the following macros, which harmlessly make use of the
procedure |rplacd|, is clear.

@d reinitialize_present_variables=@/
present_variables:=for each variable in present_variables collect
  (variable . nil . 0)
@d variable_of=car
@d origin_of=cadr
@d counter_of=cddr 
@d update_variable(variable,origin)=
rplacd(entry,origin . (counter_of entry + 1)) 
   where entry=assoc(variable,present_variables)
@d update_variables_using(kernel_list,kernel_selector,flag_function)=@/
for each kernel in kernel_list do
  for each variable in get_dependencies_of(kernel_selector(kernel)) do@/
    update_variable(variable,flag_function(kernel));
@d identity_function(kernel)=kernel
@d empty_function(kernel)=nil

@<Count the number ...@>=@/
reinitialize_present_variables;@/
update_variables_using(df_terms,first_argument_of,identity_function);@/
update_variables_using(linear_functions,identity_function,identity_function);
if bracketname then update_variables_using(commutator_functions,
                                           identity_function,empty_function)

@ After the preceding step we can generate new equations by
differentiating |equation| w.r.t.\ to all those variables which occur
in only one |df_term| or |linear_function| and for which all other
terms of |equation| are polynomial.  Using the above code one can check
that these variables are exactly the ones for which the |origin| has a
value and the |counter| is 1.

@<If possible and ...@>=
differentiations_list:=
  for each entry in present_variables join 
    if origin_of entry and counter_of entry=1 @|and
       (polynomial_order:=@|get_polynomial_order(
        linear_solve(mk!*sq(equation ./ 1),origin_of entry),variable_of entry))@|
    then list(variable_of entry . origin_of entry . (polynomial_order+1));
if differentiations_list then
  if !*allow_differentiation then
    <<for each entry in differentiations_list do @/
        setk(list(ces!*,incr(total_used)),@|
             mk!*sq simpdf list(mk!*sq(equation ./ 1),
                    variable_of entry,counter_of entry));
       write ces!*,"(",n,"): Generation of ",ces!*,"(",get(ces!*,'total_used)+1,
        "),...,",@|ces!*,"(",total_used,") by differentiation w.r.t. ";
       terpri!* t;@/
       maprin partial_list(for each entry in differentiations_list collect@|
                    list('list, variable_of entry,counter_of entry),10);@/
       terpri!* nil;
       put(ces!*,'total_used,total_used);
       goto solved
    >>
  else <<
    write "*** ",ces!*,"(",n,
      "): Generation of new equations by differentiation possible.";
    terpri!* t; write "    Solvable with 'on allow_differentiation'";
    terpri!* t; goto solved>>

@ An algebraic expression is polynomial in a variable if the
denominator does not depend on it and if the numerator is polynomial
(we only have to check this if |polynomial_check| is |on|).
The polynomial order we can obtain by simply reordering the numerator
w.r.t. the variable involved.

@u
lisp procedure get_polynomial_order(expression,variable);
if not depends(denr(expression:=simp expression),variable) @|and
   (not !*polynomial_check or polynomialp(numr expression,variable)) then
  begin scalar kord!*;
    setkorder list !*a2k variable;
    expression:=reorder numr expression;
    return @+if mvar expression=variable then ldeg expression @+else 0;
  end$

@ If none of the above methods can be applied, we cannot solve
|equation|.

@<Step 7...@>=@/
write ces!*,"(",n,") not solved"; terpri!* t

@*=Additional tools. 
The following procedure are meant for solving more equations at a
time or solving ``exceptional'' equations, which need the least restrictive
setting of the switches |coefficient_check|, |polynomial_check| or
|allow_differentiation|.

@u 
algebraic procedure integrate_equations(m,n);
for i:=m:n do integrate_equation(i)$

@#
lisp operator integrate_exceptional_equation;
lisp procedure integrate_exceptional_equation(n);
integrate_equation(n) 
where @|
  !*coefficient_check=nil,@|
  !*polynomial_check=nil,@|
  !*allow_differentiation=t$


@ As a last set of tools, we shall give a procedure to print
an equation together with all the functions occuring in it and their
dependencies, and some procedures for showing and changing the properties
of an equation set and a the functions/constants used.

As a side effect the procedure |show_equation| will reassign the shown
equation to its current value.

@u lisp operator show_equation;
lisp procedure show_equation n;
begin scalar equation,total_used,function_list;
  if null(total_used:=get(ces!*,'total_used)) or
     n>total_used then 
     stop_with_error("SHOW_EQUATION: properly initialize",
                     ces!*,nil,nil);
  if (equation:=assoc(list(ces!*,n),get(ces!*,'kvalue))) then
  begin
    equation:=setk(list(ces!*,n),aeval cadr equation);
    varpri(equation,list('setk,mkquote list(ces!*,n),mkquote equation),'only); 
    function_list:=get_recursive_kernels(numr simp equation,
                                               get(ces!*,'function_list));
    if function_list then 
    <<terpri!* t;
      for each fn in function_list do 
        <<maprin(fn . get_dependencies_of(fn)); terpri!* nil>>
    >>
    else terpri!* nil
  end
end$

@#
algebraic procedure show_equations(m,n);
for i:=m:n do show_equation i$

@ 
@u
lisp operator functions_used,put_functions_used,equations_used,put_equations_used;

@#
lisp procedure functions_used function_name;
list('list,get(function_name,'even_used),get(function_name,'odd_used))$

@#
lisp procedure put_functions_used(function_name,even_used,odd_used);
begin
  if not fixp even_used or even_used<0 or 
     not fixp odd_used or odd_used<0 then@/
  stop_with_error("PUT_FUNCTIONS_USED: used functions number invalid",nil,nil,nil);
  put(function_name,'even_used,even_used);
  put(function_name,'odd_used,odd_used);
end$

@#
lisp procedure equations_used;
get(ces!*,'total_used)$

@#
lisp procedure put_equations_used(n);
if not fixp n or n<0 then@/
  stop_with_error("PUT_EQUATIONS_USED: used equation number invalid",nil,nil,nil)
else put(ces!*,'total_used,n)$

@ There is one slight detail which we have not dealt with yet: in
prolongation theory differentiation should act as a derivation on the
arguments of a (eventually nested) commutator. In REDUCE 3.4 there is
a hook which can take care of this situation. In the procedure
|diffp|, which takes care of differentiation of standard powers, if
this standard power is an operator kernel, the property |dfform| is
checked for operator concerned. If this property has a value, it
should be a function which takes care of the differentiation of such a
standard power.

@u
lisp operator df_acts_as_derivation_on;

lisp procedure df_acts_as_derivation_on operator_name;
begin
 put(operator_name,'dfform,'df_as_derivation);
end$

@ The procedure |df_as_derivation| is quite straightforward: apply
|df| to all the arguments of the operator, one at a time, leaving the
other ones untouched.

@u
lisp procedure df_as_derivation(kernel,variable,power);
begin scalar left_part,right_part,argument,derivative;
  if power neq 1 then 
    stop_with_error("DF_AS_DERIVATION:",kernel,"must occur linearly",nil);
  left_part:=list operator_name_of kernel;@/ right_part:=arguments_of kernel;@/
  derivative:=nil . 1;
  while right_part do 
   <<argument:=first_element_of right_part; @/right_part:= rest_of right_part;@/
     derivative:=addsq(derivative,
          simp append(reverse left_part,list('df,argument,variable) . right_part));@/
     left_part:=argument . left_part;
   >>;
  return derivative;
end$

@ In order to get nice output of some of the messages given by
|integrate_equation| we redefine the print function |listpri| for
algebraic lists. Namely, we want don't want algebraic lists to split
over multiple lines in the messages we give. For this purpose, we
introduce a fluid variable |listpri_depth!*| which governs the depth
for which algebraic lists are split along lines. The default value is
the same as the value in the used in REDUCE.

@<Lisp ini...@>=
initialize_fluid(listpri_depth!*,40)$

@ The following procedure can be used at algebraic level to change
|listpri_depth!*|.

@u
lisp operator listlength$
lisp procedure listlength l;
listpri_depth!*:=l$

@ The definition of |listpri| is basically that of |inprint|, except
that it decides when to split at the comma by looking at the size of
the argument, using the global variable |listpri_depth!*|.

@u
symbolic procedure listpri l;
   begin scalar orig,split,u;
      u := l;
      l := cdr l;
      prin2!* get('!*lcbkt!*,'prtch);
         % Do it this way so table can change%
      orig := orig!*;@/
      orig!* := if posn!*<18 then posn!* @+else orig!*+3;
      if null l then go to b;
      split := treesizep(l,listpri_depth!*);
   a: maprint(negnumberchk car l,0);
      l := cdr l;
      if null l then go to b;
      oprin '!*comma!*;
      if split then terpri!* t;
      go to a;
   b: prin2!* get('!*rcbkt!*,'prtch);
      orig!* := orig;
      return u
   end$

@ The end of a REDUCE input file must be marked with |end|.

@u end;

@*=Index. This section contains a cross reference index of all
identifiers, together with the numbers of the mdules in which they are
used. Underlined entries correspond to module numbers where the
identifier was declared.