A reckoner seed: alg's symbolic algebra, staying at the text boundary — machines/seeds/seedalg.shoddy
seedalg is a reckoner seed: the file that bridges one
machine's words into the reckoner, the calculator engine. It bridges
alg: ALGSIMPLIFY,
ALGEXPAND, ALGFACTOR, ALGSOLVE and
ALGDESOLVE. Every word here works on text. An expression
sits on the stack — the calculator's working pile of values — only as
text that reads back as itself: "x^2 - 4", never as a tree
only this machine could take apart. The reason is rule R4.16: there is no
EXPRESSION cell at the keyboard. Inside alg, an expression
(AlgEx) is a full symbolic tree of sums, products, powers
and function calls. No dict — a table of named values — and no pair fits
that shape without inventing a second grammar for it. So every word stays
at the string boundary alg.shoddy already has: text in through
AlgRead (the total half of AlgParse — total
meaning it answers on every input instead of aborting), then the algebra,
then AlgShow back out.
Every other seed converts a machine's record into a dict. This one
cannot, and what it did instead is the whole design. AlgEx
is a symbolic expression tree: sums, products, powers and function calls,
nested to any depth. No dict or pair shape holds that without inventing a
second grammar for expressions on top of the one alg already has. So the
seed does not try. It stays at the string boundary alg itself already
offers: text in through AlgRead, the algebra,
AlgShow back out.
An expression on this stack is text. That is a real
limitation, not only a convenience, so it is worth stating plainly. The
dictionary cannot take the text apart. There is no walking a tree, no
substituting a subexpression, no asking for the degree. Every word here
composes by writing a string and reading it back — exactly the text
AlgRead is total over. What this buys is that the answer is
always something you can read, retype, save with TAPESAVE,
and hand to any other alg word.
AlgRead being the total half of AlgParse is
what makes this safe. A malformed expression gets a refusal naming the
token it died at, not an aborted session.
The four things a computer algebra system is for, each one line:
> "(x+1)*(x-1)" ALGEXPAND
x: "-1 + x ^ 2"
> CLEAR "2*x + 3*x" ALGSIMPLIFY
x: "5 * x"
> CLEAR "x^2 - 4" "x" ALGFACTOR
x: "(-2 + x) * (2 + x)"
> CLEAR "y" "y" "x" ALGDESOLVE
x: "C * exp(x)"
The output is canonical, not pretty. Canonical means
one fixed standard form. Terms come back in alg's own order —
-1 + x ^ 2 rather than x^2 - 1. A canonical
form is what lets two expressions be compared, and reordering it for the
eye would cost that. The text reads back as itself, and that is the
property that matters.
ALGSOLVE answers a LIST of strings. The roots are exact
expressions, not evaluated numbers:
> CLEAR "x^2 - 4" "x" ALGSOLVE
x: { "(1 / 2) * 16 ^ (1 / 2)" "(-1 / 2) * 16 ^ (1 / 2)" }
Those are 2 and −2, written as the quadratic formula produced
them and not simplified afterwards. That is the honest form: the exact
root is what was computed. But when you want a number, you take the extra
step of evaluating it yourself — ALGSOLVE will not have done
so.
Three refusals, and each names a different kind of wrong:
> CLEAR "sin(x)" "x" ALGFACTOR
?: ALGFACTOR: NOT A POLYNOMIAL IN x
> CLEAR "x^2 + 1" "x" ALGFACTOR
?: ALGFACTOR: IRREDUCIBLE OVER THE RATIONALS
> CLEAR "((" ALGEXPAND
?: ALGEXPAND: UNEXPECTED END OF EXPRESSION AT TOKEN 3
The middle one is the interesting refusal. x^2 + 1 is a
perfectly good polynomial. It simply has no factorisation over the
rationals — the fractions. Saying so is different from saying the input
was wrong.
| Word | Description |
|---|---|
| ALGSIMPLIFY ( str -- str2 ) | The expression, simplified — like terms combined, obvious identities applied. |
| ALGEXPAND ( str -- str2 ) | The expression, multiplied out — (x+1)(x-1) becomes x^2 - 1. |
| ALGFACTOR ( str var -- str2 ) | The expression factored, as one string — a polynomial in var only. Refuses on a non-polynomial, a constant, or one irreducible over the rationals. |
| ALGSOLVE ( str var -- list ) | The roots, as a list of strings — degree <= 2 solved exactly, higher degrees bisected numerically. Refuses on a non-polynomial. |
| ALGDESOLVE ( rhs y x -- str2 ) | The general solution of y' = rhs. Refuses when rhs fits neither case this covers. |
| User | How | |
|---|---|---|
| halifax | The calculator's symbolic-algebra words: ALGSIMPLIFY, ALGEXPAND, ALGFACTOR, ALGSOLVE and ALGDESOLVE. | |
| sparky | Sparky folds it too, so a model calling eval reaches the same words halifax puts at a prompt. |
A mill claims this seed by folding RckSeedAlg over its
reckoner state, which is all halifax does.
| Machine | Why | |
|---|---|---|
| alg | The domain this seed bridges: AlgRead, AlgShow, AlgSimplify, AlgExpand, AlgFactor, AlgSolve, AlgDeSolve. | |
| cuttle | The Cell type every bridged word reads its arguments from and answers into. | |
| reckoner | RckReg and the text argument reader every registered word is built from. |