!set methtit=Integration by parts
!set methenv=ZZ QQ RR
!set methparmtype=parm function integrate, function, function
!set methhelp=This method applies integration by parts.

!if $wims_read_parm iswordof form check
  !goto $wims_read_parm
!endif

!exit
:form
 Apply integration by parts on
!read deduc/methparm.phtml 1
:
<div class="wimscenter">
	\(integrate(u*v'dx) = u*v - integrate(u'*v dx))
</div>
<table class="wimsnoborder">
<tr><td style="text-align:right"> where \(u = ) </td><td>
!read deduc/methparm.phtml 2,30
</td></tr>
<tr><td style="text-align:right"> and \(v = ) </td><td>
!read deduc/methparm.phtml 3,30
</td></tr>
</table>

!exit
:check
ker=!item 2 of $methparmobj1
ker=!mathsubst integrate= in $ker
ker=!trim $ker
ker=!declosing $ker
!distribute items $ker into iker,ivar
vartest=!varlist $ivar
!if $ivar != $vartest
  error=Fail
  !exit
!endif

mout=!exec maxima diff($methparm3,$ivar);\
	diff($methparm2,$ivar);
!distribute lines $mout into vprime,uprime
!if diff isvarof $vprime,$uprime or $vprime=$empty or $uprime=$empty
  :bad_data
  error=bad_data
  !exit
!endif
!read deduc/sub/checkzero ($iker)-($methparm2)*($vprime)\
	($uprime)*($methparm3)
!distribute lines $out into ztest1,ztest2
!if $ztest1=$empty or $ztest2=$empty
  !goto bad_data
!endif
!if $ztest1!=yes
    error=Bad function: \(uv') $m_neq \($iker)!
  !advance penalty
  !exit
!endif
!read deduc/sub/simplify ($methparm2)*($methparm3)\
	($uprime)*($methparm3)
!distribute lines $out into uv,uprimev
!if $ztest2=yes
  !if strictintegrate isin $m_options
    error=You don't have the right to take a constant for \(u).\
	  Please change your method.
    !exit
  !else
    newobject1=($uv)
  !endif
!else
  newobject1=($uv - integrate($uprimev,$ivar))
!endif
oldobject=1
methexp=\(u=$methparm2), \(v=$methparm3)

!exit
