meromorph
Chieftain
Ok.
The motivation behind this question were symbolic calculation programs like Mathematica. I was wondering, how they handle with numbers, and thought they could think numbers as "multidimensional": having "rational dimension" and "irrational dimensions".
I mean, suppose you sum numbers like 4+2sqrt(5) and 3 +4\pi. The machine would sum rationals separately and irrationals separately, so that the number would be (7,2,4), where first digit is "rational dimension", the second one "sqrt(5) dimension" and the third one "\pi dimension". Otherwise the machine would have to operate with rounded numbers, and I suppose that won't do in symbolic maths program.
This was just something I though upon when walking to school at morning.
Mathematica stores symbolic expressions as nested functions. For example, 1 + 2 Pi would be stored as:
Plus[1, Times[2, Pi]]
Expressions with rational powers like 4 + 2 sqrt(5) expand to:
Plus[1, Times[2, Power[5, Rational[1,2] ] ] ]
Nested functions can be visualized as trees, f[a,b] becomes a parent node f with two child nodes a and b.
nc-1701 said:The same thing happens with rational numbers that don't easily simplify. It will keep them as symbolic values and do arithmetic with them, but it can't perform boolean tests on them or treat them as numeric values.
To my knowledge there is no other way to handle this, and it may even be impossible to improve on it at all.
Interesting. In mathematica, constants like Pi are kept as symbols but have an attribute marking that they can be evaluated to a number, and the tests 4 > Pi and 4.0 > Pi both return true. Mathematica uses dynamic typing, so if an expression combines symbols and floating-point like 2 + 2.0 then the result is output as floating-point 4.0 instead of returning a type error.