On 12/01/2013, at 6:30 AM, Raoul Duke wrote: > On Fri, Jan 11, 2013 at 11:25 AM, john skaller > <skal...@users.sourceforge.net> wrote: >> The abstract properties of numbers are defined here: >> http://felix-lang.org/$/usr/local/lib/felix/felix-latest/lib/std//algebraic.flx >> as a mathematician you will understand this code, despite the fact it >> is using type classes. It's just defining groups and rings. The "Float" >> variant is there because floating point math isn't associative. >> Its the best I could think of to mean "approximately" since there's >> no universal way to say that for floats. > > ieee floating point isn't ever going to be real math, right? is it > dangerous to try to pretend it kinda is? :-)
The Float type classes define the operations like + - * / which floats do support, whatever they actually mean. They do obey some laws, for example addition is symmetrical: a + b = b + a even for floats. So you see that rule in FloatAddgrp, and you see Addgrp (additive group) is a FloatAddgrp plus associativity. In fact this is a cheat too if we bind C-land integers (since they overflow). However floats really are "approximately associative most of the time", it's just hard to state. And of course IEEE floats actually do form a finite set of discrete values that are bound by rigid mathematical laws, they're just too complicated to state in the weak logic language supported by Felix, and stating them probably wouldn't be useful (because they're really complicated -- I've actually seen a model) On the other hand the semantic rules for integers are a bit easier to understand, even if they're not easy to state. Integers form a "locally approximate group" which means all the laws hold provided the integer representation is big enough and we look close enough to 0. How big and how close isn't relevant to the maths because its expressed in terms of limits. Also, some laws hold with certain representations like twos-complement, for example: if a + b - b is representable, then it equals a that is, the cancellation law holds, even if an intermediate calculation overflows. You can ignore the overflow. Ultimately we can say that, for example, gmp_z, really obeys all the integer laws because for any practical purposes, although it's actually finite and bounded by address space, it won't give the wrong answer because to do so would not only require more memory than you could possibly have, the failing calculation would probably take more than the expected life of the universe to complete at todays processor speeds :) -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language