-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquintic.007
More file actions
50 lines (44 loc) · 1.37 KB
/
Copy pathquintic.007
File metadata and controls
50 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- SPDX-License-Identifier: MPL-2.0
-- CONFIDENTIAL — EXPERIMENTAL — NOT FOR DISTRIBUTION
--
-- Solvable Quintic Equations
--
-- Bring-Jerrard form: x⁵ + x + a = 0
-- Solved numerically via Newton's method:
-- x_{n+1} = x_n - f(x_n) / f'(x_n)
--
-- where f(x) = x⁵ + x + a, f'(x) = 5x⁴ + 1
-- The quintic polynomial
@pure fn quintic(x: Float, a: Float) -> Float {
return pow(x, 5.0) + x + a
}
-- Its derivative
@pure fn quintic_deriv(x: Float) -> Float {
return 5.0 * pow(x, 4.0) + 1.0
}
-- One Newton step
@pure fn newton_step(x: Float, a: Float) -> Float {
let fx = quintic(x, a)
let fpx = quintic_deriv(x)
return x - fx / fpx
}
-- Solve x⁵ + x + 1 = 0 (a = 1)
-- Starting from x₀ = -0.5
@total data a_val = 1.0
@total data x0 = neg(0.5)
@total data x1 = newton_step(x0, a_val)
@total data x2 = newton_step(x1, a_val)
@total data x3 = newton_step(x2, a_val)
@total data x4 = newton_step(x3, a_val)
@total data x5 = newton_step(x4, a_val)
@total data x6 = newton_step(x5, a_val)
-- Verify: f(x6) should be ≈ 0
@total data residual = quintic(x6, a_val)
-- Solve x⁵ + x - 2 = 0 (a = -2, obvious root x = 1)
@total data b_val = neg(2.0)
@total data y0 = 0.5
@total data y1 = newton_step(y0, b_val)
@total data y2 = newton_step(y1, b_val)
@total data y3 = newton_step(y2, b_val)
@total data y4 = newton_step(y3, b_val)
@total data residual_b = quintic(y4, b_val)