!if F isin $field
 procoef=lift(Mod(1,$character)*($coef))
 procmat=Mod([$matrix],$character)
 procref=Mod([$reference],$character)
 proccon=Mod([$const],$character)
 liftm=m=lift(m)
!else
 procoef=$coef
 procmat=[$matrix]
 procref=[$reference]
 proccon=[$const]
 liftm=
!endif

const_add=m=$proccon;m[$dest]=coef*m[$origin]+m[$dest];$liftm;print(m);
const_exchange=m=$proccon;ct=m[$origin];m[$origin]=m[$dest];m[$dest]=ct;$liftm;print(m);
const_multiply=m=$proccon;m[$dest]=coef*m[$dest];$liftm;print(m);

!if $type=system
 pari_parm=$(const_$tmodif)
!else
 pari_parm=m=my_$tmodif($procref,$origin,$dest,coef);$liftm;print(m);
!endif
pari_parm=coef=$procoef;m=my_$tmodif($procmat,$origin,$dest,coef);$liftm;print(m);\
	print(coef);\
	print(m~);mm=m;\
	$pari_parm\
	if(mm==matid($size),print("Finalized"),print("Interm"));

pari_header={\
  my_add(matt,origin,dest,coef)=matt[dest,]=coef*matt[origin,]+matt[dest,];\
    return(matt);\
}\
{\
  my_exchange(matt,origin,dest,coef)=mt=matt[origin,];\
    matt[origin,]=matt[dest,];matt[dest,]=mt;\
    return(matt);\
}\
{\
  my_multiply(matt,origin,dest,coef)=matt[dest,]=coef*matt[dest,];\
    return(matt);\
}

pari_out=!exec pari $pari_parm
pari_out=!mathsubst I=i in $pari_out
coef_out=!line 2 of $pari_out
!if coef isin $coef_out or $coef_out=$empty
 error=$error bad_coef
 !exit
!endif
!if $tmodif=multiply and $coef_out=0
 error=$error mult_zero
 !exit
!endif
!distribute lines $pari_out into matrix,coef_out,transpose,tmp,pari_status
transpose=!translate ; to $\
$ in $transpose
!if $type=system
 const=$tmp
!else
 reference=$tmp
!endif
!if $pari_status=Finalized
 ended=yes
!endif

