\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
↓
\[\begin{array}{l}
t_1 := z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\
t_2 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+301}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
(FPCore (x y z t a b)
:precision binary64
(+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
↓
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (* z (+ y (* a b))) (+ x (* t a))))
(t_2 (+ (+ (* t a) (+ x (* y z))) (* (* z a) b))))
(if (<= t_2 (- INFINITY)) t_1 (if (<= t_2 5e+301) t_2 t_1))))
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
↓
\begin{array}{l}
t_1 := z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\
t_2 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+301}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Error
Try it out
Results
Enter valid numbers for all inputs
Target
Original
2.2
Target
0.3
Herbie
0.4
\[\begin{array}{l}
\mathbf{if}\;z < -11820553527347888000:\\
\;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\
\mathbf{elif}\;z < 4.7589743188364287 \cdot 10^{-122}:\\
\;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\
\end{array}
\]
Derivation
Split input into 2 regimes
if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < -inf.0 or 5.0000000000000004e301 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))
Initial program 46.4
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
(fma.f64 y z (fma.f64 a (fma.f64 z b t) x)): 0 points increase in error, 0 points decrease in error
(fma.f64 y z (fma.f64 a (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z b) t)) x)): 2 points increase in error, 0 points decrease in error
(fma.f64 y z (fma.f64 a (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
(fma.f64 y z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (+.f64 t (*.f64 z b))) x))): 0 points increase in error, 0 points decrease in error
(fma.f64 y z (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 a t) (*.f64 a (*.f64 z b)))) x)): 0 points increase in error, 5 points decrease in error
(fma.f64 y z (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 t a)) (*.f64 a (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
(fma.f64 y z (+.f64 (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b))) x)): 12 points increase in error, 10 points decrease in error
(fma.f64 y z (Rewrite<= +-commutative_binary64 (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
(Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
(Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y z) x) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b)))): 0 points increase in error, 0 points decrease in error
(+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y z))) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
(Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
Taylor expanded in z around 0 2.6
\[\leadsto \color{blue}{z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)}
\]
if -inf.0 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 5.0000000000000004e301
Initial program 0.3
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
Recombined 2 regimes into one program.
Final simplification0.4
\[\leadsto \begin{array}{l}
\mathbf{if}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq -\infty:\\
\;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\
\mathbf{elif}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq 5 \cdot 10^{+301}:\\
\;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\
\end{array}
\]
herbie shell --seed 2022300
(FPCore (x y z t a b)
:name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
:precision binary64
:herbie-target
(if (< z -11820553527347888000.0) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))
(+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))