Post Reply 
HP50g simplifing a root
10-09-2020, 05:21 PM (This post was last modified: 10-11-2020 11:32 AM by Albert Chan.)
Post: #21
RE: HP50g simplifing a root
I was being stupid. Why solve cubic equation for a Big Grin
This is the way to get cube roots simplified:

\(\sqrt[3]{A ± \sqrt{R}} = a ± \sqrt{r} \quad ⇒ \quad a = \large\frac{\sqrt[3]{A+\sqrt{R}}
\;+\; \sqrt[3]{A-\sqrt{R}}}{2} \)

Round a to closest halves, get r, and double check if it round-trip back to (A, R)

Code:
function simp_cbrt4(A,B,k)  -- simplify cbrt(A + B * sqrt(k))
    local R = B*B*k
    local a = sqrt(abs(R))
    if R<0 then a = (A*A-R)^(1/6) * cos(atan2(a,A)/3)
    else        a = (cbrt(A+a) + cbrt(A-a))/2
    end
    a = a + 0x3p50 - 0x3p50 -- round to halves
    local r = (A/a-a*a)/3
    local b = B/(3*a*a+r)
    if r == b*b*k then return a,b,k end
end

lua> simp_cbrt4(1859814842094, -59687820010, 415)
11589      -145         415
lua> simp_cbrt4(300940299,103940300,101)
99           100          101
lua> simp_cbrt(180, 23, 157)   -- (a,b) can be halves
1.5          0.5          157
lua> simp_cbrt4(-36, 20, -7)    -- work with complex roots too.
3             1             -7
lua> simp_cbrt4(81,30,-3)       -- this is simplest, see comment from previous post.
4.5          0.5          -3
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP50g simplifing a root - peacecalc - 09-29-2020, 09:22 PM
RE: HP50g simplifing a root - Albert Chan - 09-29-2020, 11:47 PM
RE: HP50g simplifing a root - Albert Chan - 09-30-2020, 02:22 AM
RE: HP50g simplifing a root - Albert Chan - 09-30-2020, 10:50 PM
RE: HP50g simplifing a root - Albert Chan - 10-01-2020, 07:31 AM
RE: HP50g simplifing a root - peacecalc - 09-30-2020, 05:33 AM
RE: HP50g simplifing a root - peacecalc - 10-01-2020, 02:20 PM
RE: HP50g simplifing a root - Albert Chan - 10-01-2020, 05:22 PM
RE: HP50g simplifing a root - peacecalc - 10-04-2020, 06:05 PM
RE: HP50g simplifing a root - Albert Chan - 10-04-2020, 11:48 PM
RE: HP50g simplifing a root - peacecalc - 10-04-2020, 07:36 PM
RE: HP50g simplifing a root - peacecalc - 10-05-2020, 11:36 AM
RE: HP50g simplifing a root - Albert Chan - 10-05-2020, 05:01 PM
RE: HP50g simplifing a root - peacecalc - 10-06-2020, 05:25 AM
RE: HP50g simplifing a root - Albert Chan - 10-06-2020, 09:40 AM
RE: HP50g simplifing a root - Albert Chan - 10-06-2020, 12:06 PM
RE: HP50g simplifing a root - Albert Chan - 10-06-2020, 04:13 PM
RE: HP50g simplifing a root - Albert Chan - 10-07-2020, 06:12 PM
RE: HP50g simplifing a root - Albert Chan - 10-09-2020, 12:20 AM
RE: HP50g simplifing a root - Albert Chan - 10-09-2020, 02:31 PM
RE: HP50g simplifing a root - Albert Chan - 10-11-2020, 06:28 PM
RE: HP50g simplifing a root - Albert Chan - 10-12-2020, 03:17 AM
RE: HP50g simplifing a root - Albert Chan - 10-24-2020, 02:19 PM
RE: HP50g simplifing a root - Albert Chan - 10-12-2020, 10:54 PM
RE: HP50g simplifing a root - CMarangon - 10-12-2020, 11:45 PM
RE: HP50g simplifing a root - grsbanks - 10-13-2020, 06:46 AM
RE: HP50g simplifing a root - Albert Chan - 10-09-2020 05:21 PM
RE: HP50g simplifing a root - Albert Chan - 10-10-2020, 03:58 PM
RE: HP50g simplifing a root - Albert Chan - 10-10-2020, 04:49 PM
RE: HP50g simplifing a root - peacecalc - 10-12-2020, 08:49 PM
RE: HP50g simplifing a root - peacecalc - 10-13-2020, 06:30 AM
RE: HP50g simplifing a root - peacecalc - 10-13-2020, 06:36 AM



User(s) browsing this thread: 2 Guest(s)