Re: forcing representation of denominator 1?



On 2006-05-10 00:29:32 +0100, Gareth McCaughan <Gareth.McCaughan@xxxxxxxxx> said:

"verec" wrote:

(defun risk-reward-to-pay-win (odds)
"Transforms a ratio such as 5/1 to 5/6, that is, from 'risk 5 and proft 1'
to 'pay 5 win 6'"
(let ((n (numerator odds))
(d (denominator odds)))
(/ n (+ n d))))

(defun pay-win-to-risk-reward (odds)
"Transfors a ratio such as Pay 5 Win 6 to a risk reward ratio such as 5/1"
(let* ((n (numerator odds))
(d (denominator odds))
(k (- d n)))
(/ n k)))

Eww :-).

(defun risk-reward-to-pay-win (odds)
(/ (1+ odds)))

(defun pay-win-to-risk-reward (odds)
(/ (- 1 (/ odds))))

Almost :-(

CL-USER 1 > (risk-reward-to-pay-win 5/1)
1/6

CL-USER 2 > (pay-win-to-risk-reward 5/6)
-5

More seriously ... do you actually do arithmetic on both
sorts of ratio?

No.

I'll make a guess: you sometimes do arithmetic
on "pay-win" figures,

Yes.

but never on "risk-reward" ones, but
you always want to report results in "risk-reward" terms[1].
If that's right, then instead of representing both as
CL rational numbers you could use rationals for pay-win
figures (for which you want arithmetic but don't care about
representation) and a class, or struct, of your own for
risk-reward figures (for which you care about representation
but don't need arithmetic).

Pascal Bourguignon suggested something similar, but that's
probably overkill: the part of the code that deals with odds
is about 100 lines or so (I know: I should count S-Exps instead :-)

It's just that I hoped there would be a magic way to "do what I mean",
either with some rational subtype I didn't know of, or with some
pretty-printer controlling variables (all of the *print-xyz* kind).

I have been to the CHLS with both requests in mind and failed
to find an answer. That's why I asked.

Many thanks.
--
JFB

.



Relevant Pages

  • Re: forcing representation of denominator 1?
    ... (d (denominator odds))) ... (let* ((n (numerator odds)) ... risk-reward figures (for which you care about representation ... not on whichever one is a ratio: ...
    (comp.lang.lisp)
  • Re: PL/I, COBOL, Advantages, Equivalence, et al
    ... Richard Riehle explained how using numerator and denominator to represent ... rationals eliminates truncation or rounding error in intermediate results. ... Let me be clear that Tom is not wrong in his assertion that, ...
    (comp.lang.pl1)
  • Re: rational arithmetic library?
    ... taltman> rationals (due to the numerator and/or the denominator being ... store rationals: resources are not infinite. ...
    (comp.lang.lisp)
  • Re: Conflicting needs for __init__ method
    ... single integer, another Rational instance, and perhaps floats, Decimal ... And when initializing from a pair of integers---a numerator ... sure that the denominator is positive. ... like negation or raising to a positive integer power, ...
    (comp.lang.python)
  • Re: Surrogate Factoring Theorem
    ... > Nora Baron wrote: ... The important thing here is the numerator of the rational. ... > Instead of trying to make a social point, try mathematics. ... > representing a full set of possibilities over rationals. ...
    (sci.crypt)

Loading