primitive.red 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module primitive; % Include primitive module alterations to solve.
  2. fluid '(!*cramer bareiss!-step!-size!*);
  3. symbolic procedure primitivesf(xl,vl);
  4. % xl:list of sf, vl:list of kernel -> primitivesf:sf
  5. % Returns each x in xl divided by gcd of the coefficients of vl.
  6. % x is ordered wrt vl, and linear in vl.
  7. foreach x in xl collect
  8. quotf!*(x,coeffgcd(x,vl));
  9. symbolic procedure coeffgcd(x,vl);
  10. % x:sf, vl:list of kernel -> coeffgcd:sf
  11. % returns gcd of coefficients of vl (including degree 0) in x
  12. if domainp x or not(mvar x memq vl) then x
  13. else if null red x then lc x
  14. else gcdf(lc x,coeffgcd(red x,vl));
  15. symbolic procedure solvelnrsys(exlis,varlis);
  16. % exlis: list of sf, varlis: list of kernel
  17. % -> solvelnrsys: tagged solution list
  18. % Check the system for sparsity, then decide whether to use the
  19. % Cramer or Bareiss method. Using the Bareiss method on sparse
  20. % systems, 4-step elimination seems to be faster than 2-step.
  21. % The Bareiss code is not good at handling surds at the moment,
  22. % hence exptexpflistp test.
  23. begin scalar w,method;
  24. exlis := primitivesf(exlis,varlis);
  25. if w := solvesparsecheck(exlis,varlis) then exlis := w
  26. else exlis := exlis . varlis;
  27. if null !*cramer and null exptexpflistp exlis
  28. then method := 'solvebareiss
  29. else method := 'solvecramer;
  30. exlis := apply2(method,car exlis,cdr exlis)
  31. where bareiss!-step!-size!* = if w then 4 else 2;
  32. return solvesyspost(exlis,varlis);
  33. end;
  34. endmodule;
  35. end;