% 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()$@/ @@/ 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. @=@/ 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); @; @; 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 @=@/ 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) @ @=@/ 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!* @=@/ 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; @; @; @; @; @; @; @; @; 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) @= 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 <> @*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. @= new_switch(coefficient_check,t)$ @ @d assoc_delete(kernel,assoc_list)=@/ delete(assoc(kernel,assoc_list),assoc_list) @d successful_message_for(action,kernel)=@/ <> @d not_a_number_message_for(action,kernel)=@/ <> @=@/ 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 <> 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; @; 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; @; integration_list:=rest_of arguments_of df_term; @; if bracketname then @; @; 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. @=@/ 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|. @= 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. @= 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 <> 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|. @= 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!*; @=@/ solution:=nil ./ 1; while integration_variable do begin new_dependency_list:=delete(integration_variable,dependency_list); for i:=0:number_of_integrations-1 do <>; @ 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 @=@/ @; @; @ @ Finding all the functions in |equation| can be done by applying the procedure |get_recursive_kernels| of the TOOLS package. @=@/ 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. @=@/ polynomial_variables:=absent_variables; if !*polynomial_check then@/ polynomial_variables:=for each variable in polynomial_variables join@/ if polynomialp(equation,variable) then list(variable) @ @= 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. @=@/ equations_list:=multi_split_form(equation,polynomial_variables); if length equations_list>1 then <> @ 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. @=@/ 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 @ @ 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. @= if length(df_list)=0 and length(linear_functions_list)=0 then << if atom(solvable_kernel:= relation_analysis(!*ff2a(equation,denominator),bracketname)) then <> else <>; 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. @= @; @; 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 @ @ Of course we are only interested in |df| terms of functions occuring on |function_list|. @= 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)); @ @= present_variables:=variable_list; for each variable in absent_variables do present_variables:=delete(variable,present_variables); nr_of_variables:=length present_variables @ @= <> 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|. @= @; @ @ 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. @=@/ 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)$ @ @= @; @ @ 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. @= for each df_term in df_terms do <>; @ @= 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 <> else <> else not_a_number_message_for("Inhomogeneous integration", first_element_of solvable_kernels) else <> @ 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 <>; 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; @; 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|% @; 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. @= while df_sequence do <> 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|. @= solution:=nil ./ 1; for each term in integration_terms do <>; 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. @=@/ new_switch(allow_differentiation,nil)$ @ After this introduction it is clear what we have to do for step 6: @= @; @ @ 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 @=@/ 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. @= 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 <> 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|. @=@/ 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 <> >> 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 <>; 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. @= 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.