cofactor.red 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module cofactor; % Cofactor operator.
  2. % Author: Alan Barnes <barnesa@kirk.aston.ac.uk>.
  3. comment
  4. Syntax: COFACTOR(MATRIX:matrix,ROW:integer,COLUMN:integer):algebraic
  5. The cofactor of the element in row ROW and column COLUMN of matrix
  6. MATRIX is returned. Errors occur if ROW or COLUMN do not simplify to
  7. integer expressions or if MATRIX is not square;
  8. symbolic procedure cofactorq (u,i,j);
  9. begin integer len;
  10. len:= length u;
  11. if not(i>0 and i<len+1)
  12. then rerror(matrix,20,"Row number out of range");
  13. if not(j>0 and j<len+1)
  14. then rerror(matrix,21,"Column number out of range");
  15. foreach x in u do
  16. if length x neq len then rerror(matrix,22,"non-square matrix");
  17. u := remove(u,i);
  18. clrhash();
  19. u := detq1(u,len-1,2**(j-1));
  20. clrhash();
  21. if remainder(i+j,2)=1 then u := negsq u;
  22. return u;
  23. end;
  24. put ('cofactor,'simpfn,'simpcofactor);
  25. symbolic procedure simpcofactor u;
  26. cofactorq(matsm car u,ieval cadr u,ieval carx(cddr u,'cofactor));
  27. endmodule;
  28. end;