# [Maxima] strange behaviour with simple decimals

Robert Dodier robert.dodier at gmail.com
Thu Apr 12 18:52:41 CDT 2007

```On 4/12/07, Michel Van den Bergh <michel.vandenbergh at uhasselt.be> wrote:

> This problem is easily solved in object oriented languages.
> For example in python you can create genuine decimal numbers
> if you really want to (for financial calculations I presume).
> http://www2.hursley.ibm.com/decimal/decarith.html
> It seems less clear how to do this cleanly within the maxima
> language.

Well, Maxima is not object oriented but all the same it is fairly
straightforward to define simplification rules for new operators,
and that can yield a similar behavior (namely to punt to a
specialized function when arguments of addition or whatever
are a certain type). I've implemented several examples like
that and if you want I can dig out one of them.

User-defined simplification rules are much, much slower than
the hand-written Lisp code which now implements simplification.
I investigated the difference not long ago and the hand-written
simplification functions were 10 times as fast as functions
defined via the user-defined simplification stuff (tellsimpafter etc).
This is enough of a difference that we can't seriously consider
replacing hand-written functions with automatically generated ones.
There are various other problems in the user-defined simplification stuff.

It is also straightforward to assign a display property (i.e. a function
pointer which is called when the object needs to be displayed).
So decimal(1.4) can be displayed as just "1.4" or "1.4 (decimal)"
or whatever.

> PS. To construct the decimal number 1.4 you use the constructor
> Decimal("1.4").  Note the use of strings. Something like
> Decimal(1.4) can not work since the number 1.4 would be converted
> to binary before the constructor has a chance to look at it.

It seems within the realm of possibility to get the cooperation of
the parser in order to handle some new operator. The parser
handles quote-quote (i.e. '') at present; as an experiment I modifed
it to handle a package-symbol resolution operator and that wasn't
difficult. So conceivably the parser could refuse to parse 1.4 as a
number if it saw it inside decimal(1.4) or something like that.

An easier approach is to just write decimal(\1.4). The backslash
causes 1.4 to be recognized as a symbol. Then the decimal
operator can handle the symbol. I prefer a single quote operator
to something which has to be matched.

FWIW
Robert
```