\[\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(a \cdot b + y\right) + \left(a \cdot t + x\right)\\
t_2 := x + z \cdot y\\
\mathbf{if}\;z \leq -5 \cdot 10^{+82}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-229}:\\
\;\;\;\;\left(a \cdot t + t_2\right) + b \cdot \left(z \cdot a\right)\\
\mathbf{elif}\;z \leq 10^{-76}:\\
\;\;\;\;\left(a \cdot t + a \cdot \left(z \cdot b\right)\right) + 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 (+ (* a b) y)) (+ (* a t) x))) (t_2 (+ x (* z y))))
(if (<= z -5e+82)
t_1
(if (<= z -5e-229)
(+ (+ (* a t) t_2) (* b (* z a)))
(if (<= z 1e-76) (+ (+ (* a t) (* a (* z b))) t_2) t_1)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * ((a * b) + y)) + ((a * t) + x);
double t_2 = x + (z * y);
double tmp;
if (z <= -5e+82) {
tmp = t_1;
} else if (z <= -5e-229) {
tmp = ((a * t) + t_2) + (b * (z * a));
} else if (z <= 1e-76) {
tmp = ((a * t) + (a * (z * b))) + t_2;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x + (y * z)) + (t * a)) + ((a * z) * b)
end function
↓
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (z * ((a * b) + y)) + ((a * t) + x)
t_2 = x + (z * y)
if (z <= (-5d+82)) then
tmp = t_1
else if (z <= (-5d-229)) then
tmp = ((a * t) + t_2) + (b * (z * a))
else if (z <= 1d-76) then
tmp = ((a * t) + (a * (z * b))) + t_2
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
↓
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * ((a * b) + y)) + ((a * t) + x);
double t_2 = x + (z * y);
double tmp;
if (z <= -5e+82) {
tmp = t_1;
} else if (z <= -5e-229) {
tmp = ((a * t) + t_2) + (b * (z * a));
} else if (z <= 1e-76) {
tmp = ((a * t) + (a * (z * b))) + t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b):
return ((x + (y * z)) + (t * a)) + ((a * z) * b)
↓
def code(x, y, z, t, a, b):
t_1 = (z * ((a * b) + y)) + ((a * t) + x)
t_2 = x + (z * y)
tmp = 0
if z <= -5e+82:
tmp = t_1
elif z <= -5e-229:
tmp = ((a * t) + t_2) + (b * (z * a))
elif z <= 1e-76:
tmp = ((a * t) + (a * (z * b))) + t_2
else:
tmp = t_1
return tmp
function code(x, y, z, t, a, b)
return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b))
end
↓
function code(x, y, z, t, a, b)
t_1 = Float64(Float64(z * Float64(Float64(a * b) + y)) + Float64(Float64(a * t) + x))
t_2 = Float64(x + Float64(z * y))
tmp = 0.0
if (z <= -5e+82)
tmp = t_1;
elseif (z <= -5e-229)
tmp = Float64(Float64(Float64(a * t) + t_2) + Float64(b * Float64(z * a)));
elseif (z <= 1e-76)
tmp = Float64(Float64(Float64(a * t) + Float64(a * Float64(z * b))) + t_2);
else
tmp = t_1;
end
return tmp
end
function tmp = code(x, y, z, t, a, b)
tmp = ((x + (y * z)) + (t * a)) + ((a * z) * b);
end
↓
function tmp_2 = code(x, y, z, t, a, b)
t_1 = (z * ((a * b) + y)) + ((a * t) + x);
t_2 = x + (z * y);
tmp = 0.0;
if (z <= -5e+82)
tmp = t_1;
elseif (z <= -5e-229)
tmp = ((a * t) + t_2) + (b * (z * a));
elseif (z <= 1e-76)
tmp = ((a * t) + (a * (z * b))) + t_2;
else
tmp = t_1;
end
tmp_2 = tmp;
end
\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(a \cdot b + y\right) + \left(a \cdot t + x\right)\\
t_2 := x + z \cdot y\\
\mathbf{if}\;z \leq -5 \cdot 10^{+82}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-229}:\\
\;\;\;\;\left(a \cdot t + t_2\right) + b \cdot \left(z \cdot a\right)\\
\mathbf{elif}\;z \leq 10^{-76}:\\
\;\;\;\;\left(a \cdot t + a \cdot \left(z \cdot b\right)\right) + t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Error
Try it out
Results
Enter valid numbers for all inputs
Target
Original
2.0
Target
0.4
Herbie
0.3
\[\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 3 regimes
if z < -5.00000000000000015e82 or 9.99999999999999927e-77 < z
Initial program 4.4
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
Simplified7.0
\[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)}
\]
Proof
(+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 a (*.f64 z b)))): 0 points increase in error, 0 points decrease in error
(+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b)))): 14 points increase in error, 21 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 0.3
\[\leadsto \color{blue}{z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)}
\]
if -5.00000000000000015e82 < z < -5.00000000000000016e-229
Initial program 0.5
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
if -5.00000000000000016e-229 < z < 9.99999999999999927e-77
Initial program 0.7
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\]
Simplified0.0
\[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)}
\]
Proof
(+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 a (*.f64 z b)))): 0 points increase in error, 0 points decrease in error
(+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b)))): 14 points increase in error, 21 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
Recombined 3 regimes into one program.
Final simplification0.3
\[\leadsto \begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+82}:\\
\;\;\;\;z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-229}:\\
\;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\
\mathbf{elif}\;z \leq 10^{-76}:\\
\;\;\;\;\left(a \cdot t + a \cdot \left(z \cdot b\right)\right) + \left(x + z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)\\
\end{array}
\]
herbie shell --seed 2022337
(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)))