4 static void __rationalize_tensor(void);
5 static void multiply_denominators(U
*);
6 static void multiply_denominators_term(U
*);
7 static void multiply_denominators_factor(U
*);
8 static void __lcm(void);
11 eval_rationalize(void)
34 __rationalize_tensor();
40 if (car(p1
) != symbol(ADD
)) {
45 // get common denominator
48 multiply_denominators(p1
);
51 // multiply each term by common denominator
63 // collect common factors
67 // divide by common denominator
74 multiply_denominators(U
*p
)
76 if (car(p
) == symbol(ADD
)) {
79 multiply_denominators_term(car(p
));
83 multiply_denominators_term(p
);
87 multiply_denominators_term(U
*p
)
89 if (car(p
) == symbol(MULTIPLY
)) {
92 multiply_denominators_factor(car(p
));
96 multiply_denominators_factor(p
);
100 multiply_denominators_factor(U
*p
)
102 if (car(p
) != symbol(POWER
))
111 if (isnegativenumber(p
)) {
119 if (car(p
) == symbol(MULTIPLY
) && isnegativenumber(cadr(p
))) {
131 __rationalize_tensor(void)
137 eval(); // makes a copy
141 if (!istensor(p1
)) { // might be zero
146 n
= p1
->u
.tensor
->nelem
;
148 for (i
= 0; i
< n
; i
++) {
149 push(p1
->u
.tensor
->elem
[i
]);
151 p1
->u
.tensor
->elem
[i
] = pop();