QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
|
12-11-2013, 05:24 PM
(This post was last modified: 01-31-2018 08:20 PM by Han.)
Post: #1
|
|||
|
|||
QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Jan. 31, 2018: This program now exists in the HP Prime firmware.
This program takes a decimal value and returns a one of the following expressions that is a "close" rational approximation of the specified decimal value: \[ \frac{p}{q}, \quad \frac{a}{b}\cdot\sqrt{\frac{p}{q}}, \quad \frac{p}{q}\cdot \pi, \quad e^{\frac{p}{q}}, \quad \text{ or } \quad \ln \left(\frac{p}{q}\right) \] Also works for complex numbers and lists of real/complex numbers. The main algorithm basically finds the continued fraction representation of a decimal and the process either self-terminates (in the case of a rational value) or terminates due to reaching the accuracy limit. For example, \[ \frac{47}{13} = 3 + \frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{2}}}}} \] To get the continued fraction representation, note that \[ \frac{47}{13} \approx 3.61538461538 \] This decimal is converted to a rational expression \[ \frac{361538461538}{10^{11}} \] which is converted into the continued fraction as follows: \[ \frac{361538461538}{10^{11}} = 3 + \frac{61538461538}{10^{11}} = 3 + \frac{1}{\frac{10^{11}}{61538461538}} = 3 + \frac{1}{1+ \frac{38461538462}{61538461538}} = \dotsm \] and so on. While computing the continued fraction, the algorithm simultaneously reduces the partial continued fraction into a rational value of the form \(\frac{p}{q}\). The other forms are merely variations in which the decimal value is either squared, divided by \(\pi\), etc. Source code below, and also included in attached zip file below. Code: // QPI by Han Duong qpi.zip (Size: 18.24 KB / Downloads: 231) Graph 3D | QPI | SolveSys |
|||
05-31-2014, 09:18 PM
Post: #2
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Thank you very much!!!
|
|||
02-06-2015, 02:57 PM
(This post was last modified: 02-06-2015 04:10 PM by salvomic.)
Post: #3
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Han, I like very much your program!
I'd use it almost everywhere... It, however, should treat also matrices... As I need this, I use QPI with this ancillary program, after your advice: Code:
Do you think to include some routine to handle matrices in your original program or it couldn't work in Home mode with "extension"? Thank you a lot, Salvo *** P.S. a part of π, there is a way to rationalize also √π, π^2...? ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
02-06-2015, 07:54 PM
Post: #4
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
(02-06-2015 02:57 PM)salvomic Wrote: Han, I like very much your program! If you want it to work in Home view, then a workaround is to convert the matrices into lists of lists. There is no getting around the fact that Home view forces all matrices to have numerical (non-symbolic) values. The drawback is that lists of lists are not displayed to look like matrices. Graph 3D | QPI | SolveSys |
|||
02-06-2015, 08:07 PM
Post: #5
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
(02-06-2015 07:54 PM)Han Wrote: If you want it to work in Home view, then a workaround is to convert the matrices into lists of lists. There is no getting around the fact that Home view forces all matrices to have numerical (non-symbolic) values. The drawback is that lists of lists are not displayed to look like matrices. yes, for that I prefer works almost always in CAS (I come from HP50g, with no difference between Home and CAS)... I thought to list of lists, but I prefer real matrices. For now my little program let me to use your QPI also with matrices (in CAS) and works well. Also I'd prefer that QPI could do the job also with matrices... ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
02-06-2015, 08:51 PM
(This post was last modified: 03-05-2015 09:58 AM by salvomic.)
Post: #6
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
please, Han, could you explain if with QPI would be possible to have rational approximation also for √π (1.77245385091), π^2 (9.86960440109), 2/π, and others "classic" irrational numbers?
Thank you! Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
02-12-2015, 03:36 AM
Post: #7
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
This is awesome, Han. Great program!
|
|||
11-05-2016, 09:49 PM
(This post was last modified: 11-27-2018 06:06 PM by compsystems.)
Post: #8
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Request#1: please HP-Prime team adhere this function to the firmware
|
|||
11-06-2016, 10:46 AM
Post: #9
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Hi,
Yes a great good program ! Gérard. |
|||
11-06-2016, 03:02 PM
Post: #10
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
(11-05-2016 09:49 PM)compsystems Wrote: Why this function is not built-in in the CAS? I quote! hoping soon... Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
11-06-2016, 10:51 PM
(This post was last modified: 03-21-2018 04:07 PM by compsystems.)
Post: #11
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Request#2: Please Han, QPI also for symbolic expressions
|
|||
02-12-2017, 04:30 AM
(This post was last modified: 02-12-2017 02:40 PM by Han.)
Post: #12
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
For symbolic expressions you can use this:
Code: #cas When I have more time I may write a version that handles all known object types. But right now I am focusing on other projects. Graph 3D | QPI | SolveSys |
|||
11-19-2017, 10:05 AM
(This post was last modified: 03-21-2018 04:19 PM by compsystems.)
Post: #13
|
|||
|
|||
RE: QPI: convert decimal to p/q, ln(p/q), p/q*pi, e^(p/q), or sqrt(p/q)
Thanks Han
Version QPI_4.4 that includes function with symbolic expressions, available below Observing the source code, I see that the output could return in various formats, Request#3: Please Han adhere a new function called QPIRLNE( EXPR, FORMAT) where FORMAT = 0/1/.../6 case 0: (Default): qpirlne( expr, 0) -> Expression as pi or root or ln or e case 1: output only as a expression of QUOTIENT 1: qpirlne( expr, 1) if it does not find the equivalent to quotient (1), but without pi, root, ln, e, it returns the same value case 2: output only as a expression of QUOTIENT 2: qpirlne( expr, 2) if it does not find the equivalent to quotient (2), but without pi, root, ln, e, it returns the same value case 3: output only as a expression of PI: qpirlne( expr, 3) if it does not find the equivalent to PI, it returns the same value case 4: output only as a expression of ROOT qpirlne( expr, 4) if it does not find the equivalent to ROOT, it returns the same value case 5: output only as a expression of LN qpirlne( expr, 5) if it does not find the equivalent to LN, it returns the same value case 6: output only as a expression of EXPR qpirlne( expr, 6) if it does not find the equivalent to EXP, it returns the same value PHP Code: ex#0: |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)