\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\]
↓
\[\begin{array}{l}
t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{+104}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
↓
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (* x x) (* z (* z (* y -4.0))))))
(if (<= z -6.8e+104)
t_1
(if (<= z 1.2e+154) (+ (* x x) (* (- (* z z) t) (* y -4.0))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) + (z * (z * (y * -4.0)));
double tmp;
if (z <= -6.8e+104) {
tmp = t_1;
} else if (z <= 1.2e+154) {
tmp = (x * x) + (((z * z) - t) * (y * -4.0));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
↓
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (x * x) + (z * (z * (y * (-4.0d0))))
if (z <= (-6.8d+104)) then
tmp = t_1
else if (z <= 1.2d+154) then
tmp = (x * x) + (((z * z) - t) * (y * (-4.0d0)))
else
tmp = t_1
end if
code = tmp
end function
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
↓
\begin{array}{l}
t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{+104}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Error
Try it out
Results
Enter valid numbers for all inputs
Target
Original
6.2
Target
6.2
Herbie
0.3
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\]
Derivation
Split input into 2 regimes
if z < -6.7999999999999994e104 or 1.20000000000000007e154 < z
Initial program 45.7
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\]
Taylor expanded in z around inf 47.1
\[\leadsto x \cdot x - \color{blue}{4 \cdot \left(y \cdot {z}^{2}\right)}
\]
Simplified1.6
\[\leadsto x \cdot x - \color{blue}{z \cdot \left(z \cdot \left(4 \cdot y\right)\right)}
\]
Proof
(*.f64 z (*.f64 z (*.f64 4 y))): 0 points increase in error, 0 points decrease in error
(*.f64 z (*.f64 z (Rewrite<= *-commutative_binary64 (*.f64 y 4)))): 0 points increase in error, 0 points decrease in error
(Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (*.f64 y 4))): 71 points increase in error, 26 points decrease in error
(Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (*.f64 z z) y) 4)): 1 points increase in error, 1 points decrease in error
(*.f64 (Rewrite<= *-commutative_binary64 (*.f64 y (*.f64 z z))) 4): 0 points increase in error, 0 points decrease in error
(*.f64 (*.f64 y (Rewrite<= unpow2_binary64 (pow.f64 z 2))) 4): 0 points increase in error, 0 points decrease in error
(Rewrite<= *-commutative_binary64 (*.f64 4 (*.f64 y (pow.f64 z 2)))): 0 points increase in error, 0 points decrease in error
if -6.7999999999999994e104 < z < 1.20000000000000007e154
Initial program 0.1
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\]
Recombined 2 regimes into one program.
Final simplification0.3
\[\leadsto \begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{+104}:\\
\;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\]
Alternatives
Alternative 1
Error
12.6
Cost
1224
\[\begin{array}{l}
t_1 := x \cdot x + \left(4 \cdot y\right) \cdot t\\
\mathbf{if}\;z \cdot z \leq 2.8 \cdot 10^{-21}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \cdot z \leq 1.26 \cdot 10^{+280}:\\
\;\;\;\;x \cdot x - y \cdot \left(4 \cdot \left(z \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
Alternative 2
Error
6.4
Cost
968
\[\begin{array}{l}
t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{if}\;z \leq -2.12 \cdot 10^{-10}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 125000000000:\\
\;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
Alternative 3
Error
18.0
Cost
576
\[x \cdot x + \left(4 \cdot y\right) \cdot t
\]
Error
Reproduce
herbie shell --seed 2022331
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:herbie-target
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))