Elektrine lite

← Feed

@screwlisp@gamerplus.org

Post #1782126

2026-04-27 06:45 UTC

@simon_brooke When I was looking at what it said on the back of the coalton can, I think it says "pow's default return type is the type of its arguments". This made me think about using pow on rational inputs. Well, rightly it says "hey I have no idea how you are planning to get a rational type out of this without you telling me something" ! Which is, I guess what one wants from a type theory.

Replies (2)

  • @simon_brooke@mastodon.scot 2026-04-27 06:58

    @screwlisp AH! OK, now that would be interesting! OK, so the way I'm doing arithmetic at present is if the args are rational and integer, I convert to rational, so the result will be rational, but if any of the args is float the result will be float. I notice that SBCL does not do this: CL-USER[1]: (expt 1/2 3/4) 0.59460354 But, my naive implementation of `expt` does not handle rationals... There's a good discussion of the issue here: https://www.lispworks.com/documentation/HyperSpec/Issues/iss153_w.htm #Lisp

    Open ##1782127

  • @vnikolov@ieji.de 2026-04-27 17:51

    @screwlisp wrote: «This made me think about using pow on rational inputs. Well, rightly it says "hey I have no idea how you are planning to get a rational type out of this without you telling me something" ! Which is, I guess what one wants from a type theory.» The traditional approach is to go a few extra miles and compute exact roots of integers (and hence rationals) where they exist. Thus, for example, compute the fifth root of integer 243 as integer 3, rather than floating-point 3.0. (It's not neurosurgery, but in many cases the extra effort is difficult to justify.) I don't know whether type theory can help here. @simon_brooke

    Open ##1782150