partition.cpp 558 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Partition a term
  2. Input stack:
  3. term (factor or product of factors)
  4. free variable
  5. Output stack:
  6. constant expression
  7. variable expression
  8. */
  9. #include "stdafx.h"
  10. #include "defs.h"
  11. void
  12. partition(void)
  13. {
  14. save();
  15. p2 = pop();
  16. p1 = pop();
  17. push_integer(1);
  18. p3 = pop();
  19. p4 = p3;
  20. p1 = cdr(p1);
  21. while (iscons(p1)) {
  22. if (find(car(p1), p2)) {
  23. push(p4);
  24. push(car(p1));
  25. multiply();
  26. p4 = pop();
  27. } else {
  28. push(p3);
  29. push(car(p1));
  30. multiply();
  31. p3 = pop();
  32. }
  33. p1 = cdr(p1);
  34. }
  35. push(p3);
  36. push(p4);
  37. restore();
  38. }