Re: forcing representation of denominator 1?
- From: verec <verec@xxxxxxx>
- Date: Wed, 10 May 2006 03:50:57 +0100
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
.
- Follow-Ups:
- Re: forcing representation of denominator 1?
- From: Gareth McCaughan
- Re: forcing representation of denominator 1?
- References:
- forcing representation of denominator 1?
- From: verec
- Re: forcing representation of denominator 1?
- From: Gareth McCaughan
- forcing representation of denominator 1?
- Prev by Date: Re: best way of assigning slot values from parent class instances to child class instances
- Next by Date: Re: Lisp stream to file descriptor conversion ?
- Previous by thread: Re: forcing representation of denominator 1?
- Next by thread: Re: forcing representation of denominator 1?
- Index(es):
Relevant Pages
|