diff --git a/brush-strokes/src/lib/Math/Interval.hs b/brush-strokes/src/lib/Math/Interval.hs index 32575ec..0439ed9 100644 --- a/brush-strokes/src/lib/Math/Interval.hs +++ b/brush-strokes/src/lib/Math/Interval.hs @@ -115,7 +115,7 @@ bisect x@( 𝕀 x_inf x_sup ) where x_mid = midpoint x infixl 6 ⊖ -(⊖) :: ( Ring a, Ord a ) => 𝕀 a -> 𝕀 a -> 𝕀 a +(⊖) :: ( AbelianGroup a, Ord a ) => 𝕀 a -> 𝕀 a -> 𝕀 a (⊖) a@( 𝕀 lo1 hi1 ) b@( 𝕀 lo2 hi2 ) | width a >= width b = 𝕀 ( lo1 - lo2 ) ( hi1 - hi2 ) diff --git a/brush-strokes/src/lib/Math/Root/Isolation/GaussSeidel.hs b/brush-strokes/src/lib/Math/Root/Isolation/GaussSeidel.hs index 040e76c..9fad426 100644 --- a/brush-strokes/src/lib/Math/Root/Isolation/GaussSeidel.hs +++ b/brush-strokes/src/lib/Math/Root/Isolation/GaussSeidel.hs @@ -202,7 +202,13 @@ gaussSeidelStep -> [ ( T ( 𝕀ℝ n ), Bool ) ] gaussSeidelStep as b ( T x0 ) = coerce $ forEachCoord @n ( x0, True ) $ \ i ( x, contraction ) -> do - -- x_i' = ( b_i - sum { j /= i } a_ij * x_j ) / a_ii + -- For each i, we have an equation: sum_j a_ij * x_j = b_i + -- + -- Re-arrange this with x_i on the left to get an iteration: + -- x_i' = ( b_i - sum { j /= i } a_ij * x_j ) / a_ii + -- + -- We perform each iteration in turn (for i = 1, ..., n), + -- **using the latest updated value of each x_j** in each iteration. let s = b `index` i - sum [ ( as ! j ) `index` i * x `index` j | j <- toList ( universe @n ), j /= i ] x_i = x `index` i