niedziela, 20 marca 2011

Za granicą nie wiedzą co to ułamki zwykłe?

Książka Programming in Scala, rozdział Functional Objects, paragraf A specification of class Rational. Czytamy:


A rational number is a number that can be expressed as a ratio n/d , where `n` and `d` are integers, except that `d` cannot be zero. `n` is called the numerator and `d` the denominator. Examples of rational numbers are 1/2 , 2/3 , 112/239 , and 2/1 . Compared to floating-point numbers, rational numbers have the advantage that fractions are represented exactly, without rounding or approximation. 

The class we’ll design in this chapter must model the behavior of rational numbers, including allowing them to be added, subtracted, multiplied, and divided. To add two rationals, you must first obtain a common denominator, then add the two numerators. For example, to add 1/2 + 2/3 , you multiply both parts of the left operand by 3 and both parts of the right operand by 2, which gives you 3/6 + 4/6 . Adding the two numerators yields the result, 7/6 . To multiply two rational numbers, you can simply multiply their numerators and multiply their denominators. Thus, 1/2 ∗ 2/5 gives 2/10 , which can be represented more compactly in its "normalized" form as 1/5 . You divide by swapping the numerator and denominator of the right operand and then multiplying. For instance 1/2 / 3/5 is the same as 1/2 ∗ 5/3 , or 5/6 .

Właśnie, dzięki uprzejmości Panów Ordersky, Spoon, Venners dowiedzieliśmy się czym są ułamki zwykłe, jak je dodawać, mnożyć, dzielić i (uwaga!) skracać. Naprawdę żałuję, że zabrakło miejsca żeby nauczyć nas jak je odejmować.

Zawsze wydawało mi się, że programiści to w miarę inteligentne osoby. Przy okazji raczej uzdolnione matematycznie i w ogóle. Czyżby w Szwajcarii (skąd pochodzi Martin Odersky) ułamki zwykłe były wiedzą tajemną znaną garstce wybrańców (czytaj studentów  École Polytechnique Fédérale de Lausanne, na której M. Ordersky wykłada)?


Mówiąc szczerze bardzo rozbawił mnie ten fragment :)


1 komentarz:

  1. Faktycznie trochę pojechali z tymi ułamkami.

    Ale nie uważam tego za jakąś wadę czy nawet powód do śmiechu. To dość powszechne w książkach pisanych po angielsku. Wyjaśniają często bardzo podstawowe pojęcia. Przeciwieństwem tego jest wiele publikacji polskich które niczego nie wyjaśniają poza zaprezentowaniem wyjątkowej wiedzy autora i uświadomienia czytelnikowi jakim jest durniem i nieukiem.

    Z dwojga złego wolę jak mi wyjaśnią ułamki :P

    OdpowiedzUsuń