1;; from Fateman
2
3
4(in-package :maxima)
5
6(defun $charsets_polylength (x)
7   (let ((y (ratf x)))
8   (+ (cp1 (cadr y)) ;numerator
9      (cp1 (cddr y))))) ;denominator
10
11(defun cp1(p)
12   ;; sum up  the sizes of the terms in the rational form polynomial p
13   (if (pcoefp p) (flatsize p)            ; a constant's length in
14decimal chars
15        (let ((count 0))
16       (do ((i (cdr p)(cddr i)))
17           ((null i) (1+ count))  ; one more for the variable name
18         (incf count (flatsize (car i))) ; length of exponent
19         (incf count (cp1 (cadr i))) ; length of coefficient, recursively
20        ))))
21
22
23;; Tests:
24#|
25pl(x):=charsets_polylength(x)         ;
26pl( (2*x^3*y^5+3*y*z^2)/5)         ; 12
27pl(x+y)                 ; 8
28pl(2*x)                 ; 4
29pl(2*x^2*y^3)                 ; 6
30|#
31;; This is NOT the same as Maple, but I am guessing that it is
32;; a satisfactory ranking of complexity for the
33;; characteristic set method.    RJF
34
35