I haven't been able to find any information on this, but I think that if someone knows it, it's someone here. I need it for some theoretical knowledge about lambda calculus and compiler optimizations. I'm sorry if this is the wrong stackexchange site, I have been told to go here by some people at stackoverflow.com
1 Answer
If you want to encode arbitrary fractions then a common choice is as a ratio of two arbitrary integers: numerator and denominator. In this case one would keep always cancel the gcd of the two integers to keep it in a simple form. One can keep denominator positive and the sign with the numerator or one can split the sign out and have a triple of (sign,numerator,denominator), in which case the numerator and denominator are natural numbers (though try not to divide by zero...)
If by fractional you mean "non-integer" real number then other choices might be a continued fraction representation, or some successive interval approximation, or even a lazy stream of digits.
- $\begingroup$ By fractional I mean non-integer. $\endgroup$Anonymous– Anonymous2011-03-29 12:30:27 +00:00Commented Mar 29, 2011 at 12:30
- $\begingroup$ Then you could search for how people do "exact real arithmetic", e.g haskell.org/haskellwiki/Exact_real_arithmetic , or search for 'interval "exact real"', etc. $\endgroup$Chris Kuklewicz– Chris Kuklewicz2011-03-29 12:35:47 +00:00Commented Mar 29, 2011 at 12:35
- $\begingroup$ You must understand a representation of the "non-integer" before encoding this chosen representation in the lambda calculus. $\endgroup$Chris Kuklewicz– Chris Kuklewicz2011-03-29 12:50:42 +00:00Commented Mar 29, 2011 at 12:50
- $\begingroup$ I do, but it should be coded so it's as practical as possible. For example, church numerals are encoded as iteration. That's a generic and practical way of encoding them. What would be a generic and practical way of encoding non-integer numbers? $\endgroup$Anonymous– Anonymous2011-03-29 17:07:39 +00:00Commented Mar 29, 2011 at 17:07
- $\begingroup$ Perhaps you have a way to encode pairs, this leads to a way to encode a lazy list, which leads to a lazy list of decimal digits... $\endgroup$Chris Kuklewicz– Chris Kuklewicz2011-03-29 17:09:27 +00:00Commented Mar 29, 2011 at 17:09