
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
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
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
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
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
(FPCore (x y z t)
:precision binary64
(if (<= (* y 4.0) -5e+59)
(+ (* x x) (* (* y 4.0) (- t (* z z))))
(if (<= (* y 4.0) 0.2)
(- (* x x) (+ (* y (* t -4.0)) (* z (* (* y 4.0) z))))
(fma x x (* (- (* z z) t) (* y -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y * 4.0) <= -5e+59) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else if ((y * 4.0) <= 0.2) {
tmp = (x * x) - ((y * (t * -4.0)) + (z * ((y * 4.0) * z)));
} else {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(y * 4.0) <= -5e+59) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); elseif (Float64(y * 4.0) <= 0.2) tmp = Float64(Float64(x * x) - Float64(Float64(y * Float64(t * -4.0)) + Float64(z * Float64(Float64(y * 4.0) * z)))); else tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(y * 4.0), $MachinePrecision], -5e+59], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * 4.0), $MachinePrecision], 0.2], N[(N[(x * x), $MachinePrecision] - N[(N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(z * N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot 4 \leq -5 \cdot 10^{+59}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{elif}\;y \cdot 4 \leq 0.2:\\
\;\;\;\;x \cdot x - \left(y \cdot \left(t \cdot -4\right) + z \cdot \left(\left(y \cdot 4\right) \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 y 4) < -4.9999999999999997e59Initial program 100.0%
if -4.9999999999999997e59 < (*.f64 y 4) < 0.20000000000000001Initial program 89.4%
Taylor expanded in z around 0 89.4%
Applied egg-rr49.2%
fma-udef49.2%
unpow249.2%
associate-*r*49.2%
Simplified49.2%
associate-*l*49.2%
unpow-prod-down43.6%
metadata-eval43.6%
sqrt-prod43.6%
*-commutative43.6%
pow243.6%
add-sqr-sqrt89.4%
*-commutative89.4%
unpow289.4%
associate-*r*98.5%
*-commutative98.5%
Applied egg-rr98.5%
if 0.20000000000000001 < (*.f64 y 4) Initial program 87.7%
fma-neg96.4%
distribute-lft-neg-in96.4%
*-commutative96.4%
distribute-rgt-neg-in96.4%
metadata-eval96.4%
Simplified96.4%
Final simplification98.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (- (* x x) (* y (* t -4.0))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) + ((y * 4.0) * (t - (z * z))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (x * x) - (y * (t * -4.0)) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) + ((y * 4.0) * (t - (z * z))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 96.1%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in z around 0 50.0%
*-commutative50.0%
*-commutative50.0%
associate-*l*50.0%
Simplified50.0%
Final simplification94.0%
(FPCore (x y z t) :precision binary64 (if (<= t 2e-37) (- (* x x) (+ (* y (* t -4.0)) (* z (* (* y 4.0) z)))) (+ (* x x) (* (* y 4.0) (- t (* z z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 2e-37) {
tmp = (x * x) - ((y * (t * -4.0)) + (z * ((y * 4.0) * z)));
} else {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
}
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
real(8) :: tmp
if (t <= 2d-37) then
tmp = (x * x) - ((y * (t * (-4.0d0))) + (z * ((y * 4.0d0) * z)))
else
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 2e-37) {
tmp = (x * x) - ((y * (t * -4.0)) + (z * ((y * 4.0) * z)));
} else {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 2e-37: tmp = (x * x) - ((y * (t * -4.0)) + (z * ((y * 4.0) * z))) else: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 2e-37) tmp = Float64(Float64(x * x) - Float64(Float64(y * Float64(t * -4.0)) + Float64(z * Float64(Float64(y * 4.0) * z)))); else tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 2e-37) tmp = (x * x) - ((y * (t * -4.0)) + (z * ((y * 4.0) * z))); else tmp = (x * x) + ((y * 4.0) * (t - (z * z))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 2e-37], N[(N[(x * x), $MachinePrecision] - N[(N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(z * N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 2 \cdot 10^{-37}:\\
\;\;\;\;x \cdot x - \left(y \cdot \left(t \cdot -4\right) + z \cdot \left(\left(y \cdot 4\right) \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\end{array}
\end{array}
if t < 2.00000000000000013e-37Initial program 90.8%
Taylor expanded in z around 0 90.8%
Applied egg-rr43.3%
fma-udef43.2%
unpow243.2%
associate-*r*43.2%
Simplified43.2%
associate-*l*43.2%
unpow-prod-down39.5%
metadata-eval39.5%
sqrt-prod39.5%
*-commutative39.5%
pow239.5%
add-sqr-sqrt90.8%
*-commutative90.8%
unpow290.8%
associate-*r*96.6%
*-commutative96.6%
Applied egg-rr96.6%
if 2.00000000000000013e-37 < t Initial program 93.6%
Final simplification95.7%
(FPCore (x y z t) :precision binary64 (- (* x x) (* y (* t -4.0))))
double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
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 * (t * (-4.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
def code(x, y, z, t): return (x * x) - (y * (t * -4.0))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (y * (t * -4.0)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 91.6%
Taylor expanded in z around 0 67.6%
*-commutative67.6%
*-commutative67.6%
associate-*l*67.6%
Simplified67.6%
Final simplification67.6%
(FPCore (x y z t) :precision binary64 (* (* y t) 4.0))
double code(double x, double y, double z, double t) {
return (y * t) * 4.0;
}
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 = (y * t) * 4.0d0
end function
public static double code(double x, double y, double z, double t) {
return (y * t) * 4.0;
}
def code(x, y, z, t): return (y * t) * 4.0
function code(x, y, z, t) return Float64(Float64(y * t) * 4.0) end
function tmp = code(x, y, z, t) tmp = (y * t) * 4.0; end
code[x_, y_, z_, t_] := N[(N[(y * t), $MachinePrecision] * 4.0), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot t\right) \cdot 4
\end{array}
Initial program 91.6%
Taylor expanded in t around inf 29.0%
*-commutative29.0%
Simplified29.0%
Final simplification29.0%
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
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) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t): return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t)))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (4.0 * (y * ((z * z) - t))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}
herbie shell --seed 2024026
(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))))