I would like to write some functions to carry elementary symbolic calculations,
like dealing with polynomials of 'symbols', each symbol subject to be substituate
by others polynomials.
Say if P(x,y) and Q(x,y,z) are given, then P(Q(x,y,z),-3) would also be tractable.
Of course the first approach I see is a tree structure together with predefine
types.
sym-coeff = rational. ; the coefficients.
sym-var = member of a list of symbols. ; the variables.
sym-atom = sym-coeff or sym-var. ; atomic expressions.
A symbolic expression would then be defined by:
sym-exp = sym-atom ; starting point.
sym-exp = ('op+ e1 ... en) or ; where e, ei are sym-exp
('op* e1 ... en) or ; and n an integer (say >= 0).
('op^ e n)
We can also image an intermediate type like the monomials.
In principle this should work, even if for now I am not sure how to represent
these entities: Here is where I need your advise.
For example how can I define types that will be recognize by a generic function?
I have tried without success both of the following:
(deftype sym-coeff () 'rational)
(typep 1/7 'sym-coeff) => T.
(defmethod double ((x sym-coeff)) (* 2 x))
Error: "sym-coeff to find-class does not name a class".
(defclass sym-coeff (rational) ())
Error: "when defining a standard class, the DIRECT-SUPERCLASSES argument
contains #<BUILT-IN_CLASS RATIONAL #...> which is incompatible
with the metaclass #<STANDARD-CLASS #...>".
Of course it is possible to define the class:
(defclass sym-coeff ()
((data :accessor data :initform 0)))
where the unique slot is the rational. Is it a good practice?
Anyhow is it a good idea to typedef what I have called the sym-exp,
since type specifiers are interpreted, slow?
The other way around is to write a plain function which returns the
type of its parameter, but then I can't take advantage of the generic
functions.
I would greatly appreciate your comments and suggetions.
Antoine Zahnd.