rank.red 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module rank;
  2. % Author: Eberhard Schruefer.
  3. % Module for calculating the rank of a matrix or a system of linear
  4. % equations.
  5. % Format: rank <matrix> : rank <list of equations>.
  6. symbolic procedure rank!-eval u;
  7. begin scalar n;
  8. if cdr u then rerror(matrix,17,"Wrong number of arguments")
  9. else if getrtype (u := car u) eq 'matrix
  10. then return rank!-matrix matsm u
  11. else if null eqcar(u := aeval u,'list) then typerr(u,"matrix")
  12. else return rank!-matrix
  13. for each row in cdr u collect
  14. if not eqcar(row,'list)
  15. then rerror(matrix,15,"list not in matrix shape")
  16. else <<row := cdr row;
  17. if null n then n := length row
  18. else if n neq length row
  19. then rerror(matrix,151,"list not in matrix shape");
  20. for each j in row collect simp j>>
  21. end;
  22. put('rank,'psopfn,'rank!-eval);
  23. symbolic procedure rank!-matrix u;
  24. begin scalar x,y,z; integer m,n;
  25. z := 1;
  26. for each v in u do
  27. <<y := 1;
  28. for each w in v do y := lcm(y,denr w);
  29. m := 1;
  30. x := nil;
  31. for each j in v do
  32. <<if numr j then
  33. x := list m .* multf(numr j,quotf(y,denr j)) .+ x;
  34. m := m + 1>>;
  35. if y := c!:extmult(x,z)
  36. then <<z := y; n := n + 1>>>>;
  37. return n
  38. end;
  39. endmodule;
  40. end;