Lisp HUG Maillist Archive

Re: The rational function

Well, rational only takes one argument, but the reasoning is sound. What the OP wants to use is “rationalize” which will pick the closest rational to the FP representation.


  *   (rationalize 7.2)
  *   36/5

From: <owner-lisp-hug@lispworks.com> on behalf of Christopher Riesbeck <c-riesbeck@northwestern.edu>
Reply-To: Christopher Riesbeck <c-riesbeck@northwestern.edu>
Date: Monday, April 6, 2020 at 3:49 PM
To: Ramamoorthi Bhaskar <bhaskar51@gmail.com>
Cc: "lisp-hug@lispworks.com" <lisp-hug@lispworks.com>
Subject: EXT: Re: The rational function

(rational 72 100) does what I’m guessing you expected.

7.2 is a different number with a much longer binary fraction

On Apr 6, 2020, at 2:36 PM, Ramamoorthi Bhaskar <bhaskar51@gmail.com<mailto:bhaskar51@gmail.com>> wrote:



I can't figure out why (rational 7.2) or (rational 7.20) should produce

7549747/1048576

Any ideas?


Thanks
Bhaskar

------------------
Christopher Riesbeck (he/him/his)
Associate Professor, Computer Science,
McCormick School of Engineering, Northwestern

Director, MS in Computer Science
Co-director, The Center for Computer Science and Learning Sciences

Home page: https://users.cs.northwestern.edu/~riesbeck
Calendar: https://users.cs.northwestern.edu/~riesbeck/calendar-weekly.html


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: The rational function


Hi:

(rationalize 7.2) does the trick! Hurray.

Thanks so much. FYI, I'm messing with continued fractions in an attempt to ward off the pandemic from coming to Cambridge, but we have already had cases in our neighborhood!

Thanks,
Bhaskar



On Mon, Apr 6, 2020 at 4:44 PM Miller, Bradford W (GE Research, US) <millerb@ge.com> wrote:
Well, rational only takes one argument, but the reasoning is sound. What the OP wants to use is “rationalize” which will pick the closest rational to the FP representation.


  *   (rationalize 7.2)
  *   36/5

From: <owner-lisp-hug@lispworks.com> on behalf of Christopher Riesbeck <c-riesbeck@northwestern.edu>
Reply-To: Christopher Riesbeck <c-riesbeck@northwestern.edu>
Date: Monday, April 6, 2020 at 3:49 PM
To: Ramamoorthi Bhaskar <bhaskar51@gmail.com>
Cc: "lisp-hug@lispworks.com" <lisp-hug@lispworks.com>
Subject: EXT: Re: The rational function

(rational 72 100) does what I’m guessing you expected.

7.2 is a different number with a much longer binary fraction

On Apr 6, 2020, at 2:36 PM, Ramamoorthi Bhaskar <bhaskar51@gmail.com<mailto:bhaskar51@gmail.com>> wrote:



I can't figure out why (rational 7.2) or (rational 7.20) should produce

7549747/1048576

Any ideas?


Thanks
Bhaskar

------------------
Christopher Riesbeck (he/him/his)
Associate Professor, Computer Science,
McCormick School of Engineering, Northwestern

Director, MS in Computer Science
Co-director, The Center for Computer Science and Learning Sciences

Home page: https://users.cs.northwestern.edu/~riesbeck
Calendar: https://users.cs.northwestern.edu/~riesbeck/calendar-weekly.html

Re: The rational function

Hi Bhaskar,

Stay safe and well!

I’d like to add, in case you’re not aware of it, that you might want to set your default float read format to double-float. Single-float rarely makes sense these days.

If you do, you’ll get an even more unreadable fraction when using RATIONAL:

CL-USER 7 > (setf *read-default-float-format* 'double-float)
DOUBLE-FLOAT

CL-USER 8 > (rational 7.2)
8106479329266893/1125899906842624

Regards,
  Espen Vestre

On 6 Apr 2020, at 22:56, Ramamoorthi Bhaskar <bhaskar51@gmail.com> wrote:


Hi:

(rationalize 7.2) does the trick! Hurray.

Thanks so much. FYI, I'm messing with continued fractions in an attempt to ward off the pandemic from coming to Cambridge, but we have already had cases in our neighborhood!

Thanks,
Bhaskar



On Mon, Apr 6, 2020 at 4:44 PM Miller, Bradford W (GE Research, US) <millerb@ge.com> wrote:
Well, rational only takes one argument, but the reasoning is sound. What the OP wants to use is “rationalize” which will pick the closest rational to the FP representation.


  *   (rationalize 7.2)
  *   36/5

From: <owner-lisp-hug@lispworks.com> on behalf of Christopher Riesbeck <c-riesbeck@northwestern.edu>
Reply-To: Christopher Riesbeck <c-riesbeck@northwestern.edu>
Date: Monday, April 6, 2020 at 3:49 PM
To: Ramamoorthi Bhaskar <bhaskar51@gmail.com>
Cc: "lisp-hug@lispworks.com" <lisp-hug@lispworks.com>
Subject: EXT: Re: The rational function

(rational 72 100) does what I’m guessing you expected.

7.2 is a different number with a much longer binary fraction

On Apr 6, 2020, at 2:36 PM, Ramamoorthi Bhaskar <bhaskar51@gmail.com<mailto:bhaskar51@gmail.com>> wrote:



I can't figure out why (rational 7.2) or (rational 7.20) should produce

7549747/1048576

Any ideas?


Thanks
Bhaskar

------------------
Christopher Riesbeck (he/him/his)
Associate Professor, Computer Science,
McCormick School of Engineering, Northwestern

Director, MS in Computer Science
Co-director, The Center for Computer Science and Learning Sciences

Home page: https://users.cs.northwestern.edu/~riesbeck
Calendar: https://users.cs.northwestern.edu/~riesbeck/calendar-weekly.html


Re: The rational function

typo - I meant (rationalize 72/100)

On Apr 6, 2020, at 3:44 PM, Miller, Bradford W (GE Research, US) <millerb@ge.com> wrote:

Well, rational only takes one argument, but the reasoning is sound. What the OP wants to use is “rationalize” which will pick the closest rational to the FP representation.


 *   (rationalize 7.2)
 *   36/5

From: <owner-lisp-hug@lispworks.com> on behalf of Christopher Riesbeck <c-riesbeck@northwestern.edu>
Reply-To: Christopher Riesbeck <c-riesbeck@northwestern.edu>
Date: Monday, April 6, 2020 at 3:49 PM
To: Ramamoorthi Bhaskar <bhaskar51@gmail.com>
Cc: "lisp-hug@lispworks.com" <lisp-hug@lispworks.com>
Subject: EXT: Re: The rational function

(rational 72 100) does what I’m guessing you expected.

7..2 is a different number with a much longer binary fraction

On Apr 6, 2020, at 2:36 PM, Ramamoorthi Bhaskar <bhaskar51@gmail.com<mailto:bhaskar51@gmail.com>> wrote:



I can't figure out why (rational 7.2) or (rational 7.20) should produce

7549747/1048576

Any ideas?


Thanks
Bhaskar

------------------
Christopher Riesbeck (he/him/his)
Associate Professor, Computer Science,
McCormick School of Engineering, Northwestern

Director, MS in Computer Science
Co-director, The Center for Computer Science and Learning Sciences

Home page: https://users.cs.northwestern.edu/~riesbeck
Calendar: https://users.cs.northwestern.edu/~riesbeck/calendar-weekly.html


------------------
Christopher Riesbeck (he/him/his)
Associate Professor, Computer Science, 
McCormick School of Engineering, Northwestern

Director, MS in Computer Science
Co-director, The Center for Computer Science and Learning Sciences

Home page: https://users.cs.northwestern.edu/~riesbeck
Calendar: https://users.cs.northwestern.edu/~riesbeck/calendar-weekly.html


Updated at: 2020-12-10 08:29 UTC