# $Source: /u/maple/research/lib/DEtools/src/RCS/de2diffop,v $ # $Notify: mvanhoei@daisy.uwaterloo.ca $ # This file contains conversion and type checking tools for diffop: macro( x=`DEtools/diffop/x`, DF=`DEtools/diffop/DF`, to_diffop=`DEtools/diffop/to_diffop`, to_eqn=`DEtools/diffop/to_eqn` ): # Only for the homogeneous case. to_diffop:=proc(eqn,dvar) global x,DF,subs_rad; local d,L; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; `DEtools/diffop/l_p`(); d:=`if`(nargs>1 and (type(dvar,list) or type(dvar,function)) ,dvar,_Envdiffopdomain); if type(d,list) then # input is already a differential operator _Envdiffopdomain:=d; # the point of this step is that # this variable can be used for # making the output of userinfo nicer. subs(d[1]=DF,d[2]=x,eqn) elif type(d,function) then # input is an equation L:=subs(op(d)=x,`DEtools/convertAlg`(eqn,d)); if evala(Normal(L[2]))<>0 then error "expecting a linear homogeneous differential equation" fi; add(evala(Normal(L[1][d]))*DF^(d-1),d=1..nops(L[1])) else error "wrong number (or type) of arguments" fi end: # In case dvar is a function y(x) then this proceduces an equation. # If it is a list [Dx,x] then it produces an operator. to_eqn:=proc(L,dvar) global x,DF; local i; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved.`; # No options remember otherwise the following doesn't work: if nargs=1 then i:=_Envdiffopdomain; if type(i,list) then procname(L,i) else error "differential algebra not specified" fi elif type(L,list) or type(L,set) then map(procname,L,args[2..nargs]) elif type(dvar,list) then # original input was an operator, so operator syntax # output sort(subs(DF=dvar[1],x=dvar[2],L),dvar[1]) elif type(dvar,function) then subs(x=op(dvar),convert([ coeff(L,DF,0)*dvar,seq(coeff(L,DF,i)*diff(dvar,op(dvar)$i) ,i=1..degree(L,DF)) ],`+`)) else error "wrong arguments" fi end: #savelib('to_eqn','to_diffop'): #macro( # to_eqn=readlib(`DEtools/diffop/to_eqn`), # to_diffop=readlib(`DEtools/diffop/to_diffop`) #): # Input: homogeneous equation, dependent variable, domain (the # differential algebra) # Output: differential operator. # Options: monic -> make the output monic. # Perhaps `convert/diffop` would also be a good name for this procedure. `DEtools/de2diffop`:=proc(eqn,dvar,d) global x,DF; local L; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved. Author: M. van Hoeij`; if nargs<3 or d='monic' then return procname(eqn,dvar,_Envdiffopdomain,args[3..nargs]) fi; if not(type(d,list)) then if type(dvar,list) then return procname(eqn,d,dvar,args[4..nargs]) else error "differential algebra not specified" fi elif not(type(dvar,function)) then error "dependent variable must be specified" fi; L:=traperror(to_diffop(eqn,dvar)); if L=lasterror then # To make the error appear in here rather than # in some long procedure name. error L fi; L:=subs(DF=d[1],x=d[2],L); if nargs[nargs]='monic' then L:=collect(L/lcoeff(L,d[1]),d[1],evala@Normal) fi; sort(L,d[1]) end: `DEtools/diffop2de`:=proc(L,dvar,d) global x,DF; local M; option `Copyright (c) 1997 Waterloo Maple Inc. All rights reserved. Author: M. van Hoeij`; if nargs<3 or d='monic' then return procname(L,dvar,_Envdiffopdomain,args[3..nargs]) fi; if not(type(d,list)) then if type(dvar,list) then return procname(L,d,dvar,args[4..nargs]) else error "differential algebra not specified" fi elif not(type(dvar,function)) then error "dependent variable must be specified" fi; M:=subs(d[1]=DF,d[2]=x,L); if args[nargs]='monic' then M:=collect(M/lcoeff(M,d[1]),d[1],evala@Normal) fi; to_eqn(M,dvar) end: #savelib('`DEtools/de2diffop`','`DEtools/diffop2de`'):