1

I'm doing some Linear programming exercises for the course of Algorithms, and in doing this I'm solving manually many operations with fractions. In doing this I realized that a human being don't suffer from numeric instability: we just keep values in fractional representation, and we finally evaluate (possibly by using a calculator) the value of expressions.

Is there any technique that does this automatically?

Im thinking of something which achieves some kind of symbolic computation, simplifies the numbers internally and finally yields the value only during the evaluation of an expression.

Dacav
  • 13,590
  • 11
  • 60
  • 87
  • 2
    There are lots and lots of rational fraction libraries. What language would you like to know about? – S.Lott Jan 26 '11 at 15:24
  • Actually I'm more interested in knowing if this kind of techniques has a specific name. If the library is implemented in some language, it's pretty likely that there's an implementation for any other. – Dacav Jan 26 '11 at 15:29
  • "I'm more interested in knowing if this kind of techniques has a specific name." "Is there any library (any language will do) that does this automatically?" Please **update** your question to be complete and consistent. – S.Lott Jan 26 '11 at 15:31
  • @S.Lott, good point, I hope that the edit better gives the idea... :) – Dacav Jan 26 '11 at 15:34

2 Answers2

1

Boost contains a rational number library here which might be of help.

Kernow Steve
  • 196
  • 4
1

In Python you can have a look at fractions:

import fractions
a = fractions.Fraction(2,3)

a*2
# Fraction(4, 3)

a**2
# Fraction(4, 9)

'Value: %.2f' % a
# 'Value: 0.67'
eumiro
  • 207,213
  • 34
  • 299
  • 261