# Is there CAS design wisdom regarding categorizing expressions?

Is there CAS design wisdom regarding categorizing expressions?

For instance. A user types in the expression $X^2 + X + 1$. Would it be best to classify it as a member of $R[X]$ (for some R, yet to be determined)?

What about $e^{X^2 + X + 1}$ this is some expression that is usually interpreted as a function, but it could also be just an element of $R[e^{X^2}, e^{X}, e^{1}]$ And there are other interpretations.

So the question is, what would be a simple but reasonful way to parse expressions. Maybe there could be a general Expression class that stands for all expressions, and later that expression might be tied to a function name, or something.

I'm using the D language and want to have syntactic sugar support for things like $e^x$ in code. So I'm thinking all objects will default to variables unless they're declared with const:

const C y; R x;

then

Function(R,R) $f = e^x$;

and

C z = $e^y$;

Where Function(R,R) is a template trick in D and the above would mean $f: \mathbb{R} \rightarrow \mathbb{R} : x \mapsto e^x$ and of course e would be defined as a const R.

$z$ would just be a variable assigned some value since $e^y$ is a constant.

Or something like that. The syntactic sugar stops at some point in D, but it would be fracking awesome to use it as much as possible.

Then an interpreter program could be written to communicate with the CAS.

-

Have a look also on Representing Elementary Functions in a CAS

Are you familiar with Axiom CAS (or its forks)? It has a type constructor Expression. It's not to construct multivariate polynomials over $R$ as you were talking in the beginning, but rather to construct rational functions. So for example:

(1) -> 2 * x + exp(3*y)

3y
(1)  %e   + 2x
Type: Expression(Integer)

(2) -> 2/3 * x + exp(3*y)

3y
3%e   + 2x
(2)  ──────────
3
Type: Expression(Integer)

(3) -> 0.5 * x + exp(3*y)

3.0 y
(3)  %e      + 0.5 x
Type: Expression(Float)


A similar way to represent expressions is used in REDUCE. I'm afraid I can't tell anything more. Just a bit of information about representing expressions can be found in the book "Computer algebra: systems and algorithms for algebraic computation" by Davenport, Siret, Tournier. But it is really "just a bit".

Upd Digging the Axiom's documentation:

Conceptually, an object of type Expression can be thought of a quotient of multivariate polynomials, where the "variables" are kernels. The arguments of the kernels are again expressions and so the structure recurses. See Expression for examples of using kernels to take apart expression objects.

-
I decided to go with using Sage (leaving the CAS design wisdom to the pros), and working on a simpler D programming project. Sage is neat. You can make interactive plots (sliders, entry fields, buttons), so a is a great tool for teaching yourself or others topics that use math. – Enjoys Math May 1 '12 at 22:17