eigenmath/partition.cpp

54 lines
558 B
C++
Raw Permalink Normal View History

2006-06-01 19:32:39 +02:00
/* Partition a term
Input stack:
term (factor or product of factors)
free variable
Output stack:
constant expression
variable expression
*/
2006-06-01 22:41:33 +02:00
#include "stdafx.h"
#include "defs.h"
2006-06-01 19:32:39 +02:00
void
partition(void)
{
save();
p2 = pop();
p1 = pop();
2006-06-02 18:03:42 +02:00
push_integer(1);
p3 = pop();
p4 = p3;
2006-06-01 19:32:39 +02:00
p1 = cdr(p1);
while (iscons(p1)) {
if (find(car(p1), p2)) {
2006-06-02 18:03:42 +02:00
push(p4);
push(car(p1));
multiply();
p4 = pop();
2006-06-01 19:32:39 +02:00
} else {
2006-06-02 18:03:42 +02:00
push(p3);
push(car(p1));
multiply();
p3 = pop();
2006-06-01 19:32:39 +02:00
}
p1 = cdr(p1);
}
2006-06-02 18:03:42 +02:00
push(p3);
push(p4);
2006-06-01 19:32:39 +02:00
restore();
}