
(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 6 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
(let* ((t_1 (- (* z z) t)))
(if (<= (* (* y 4.0) t_1) (- INFINITY))
(+ (* x x) (* t (* y (- (/ -1.0 (* 0.25 (/ (/ t z) z))) -4.0))))
(fma x x (* t_1 (* y -4.0))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (((y * 4.0) * t_1) <= -((double) INFINITY)) {
tmp = (x * x) + (t * (y * ((-1.0 / (0.25 * ((t / z) / z))) - -4.0)));
} else {
tmp = fma(x, x, (t_1 * (y * -4.0)));
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(z * z) - t) tmp = 0.0 if (Float64(Float64(y * 4.0) * t_1) <= Float64(-Inf)) tmp = Float64(Float64(x * x) + Float64(t * Float64(y * Float64(Float64(-1.0 / Float64(0.25 * Float64(Float64(t / z) / z))) - -4.0)))); else tmp = fma(x, x, Float64(t_1 * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[N[(N[(y * 4.0), $MachinePrecision] * t$95$1), $MachinePrecision], (-Infinity)], N[(N[(x * x), $MachinePrecision] + N[(t * N[(y * N[(N[(-1.0 / N[(0.25 * N[(N[(t / z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(t$95$1 * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot z - t\\
\mathbf{if}\;\left(y \cdot 4\right) \cdot t\_1 \leq -\infty:\\
\;\;\;\;x \cdot x + t \cdot \left(y \cdot \left(\frac{-1}{0.25 \cdot \frac{\frac{t}{z}}{z}} - -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, t\_1 \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t)) < -inf.0Initial program 86.4%
Taylor expanded in t around inf 86.4%
*-commutative86.4%
associate-/l*86.4%
associate-*r*86.4%
*-commutative86.4%
associate-/l*86.4%
associate-*l*86.4%
associate-/l*86.4%
distribute-lft-out86.4%
Simplified86.4%
add-sqr-sqrt86.4%
*-un-lft-identity86.4%
times-frac86.4%
*-commutative86.4%
sqrt-prod86.4%
sqrt-pow155.0%
metadata-eval55.0%
pow155.0%
metadata-eval55.0%
*-commutative55.0%
sqrt-prod55.0%
sqrt-pow194.7%
metadata-eval94.7%
pow194.7%
metadata-eval94.7%
Applied egg-rr94.7%
clear-num94.7%
clear-num94.7%
frac-times94.8%
metadata-eval94.8%
*-un-lft-identity94.8%
*-commutative94.8%
times-frac94.8%
metadata-eval94.8%
Applied egg-rr94.8%
inv-pow94.8%
associate-*l/94.8%
*-un-lft-identity94.8%
Applied egg-rr94.8%
unpow-194.8%
*-commutative94.8%
times-frac94.8%
metadata-eval94.8%
Simplified94.8%
if -inf.0 < (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t)) Initial program 90.1%
fma-neg93.6%
distribute-lft-neg-in93.6%
*-commutative93.6%
distribute-rgt-neg-in93.6%
metadata-eval93.6%
Simplified93.6%
Final simplification93.8%
(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) (* -4.0 (* y t))))))
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) - (-4.0 * (y * t));
}
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) - (-4.0 * (y * t));
}
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) - (-4.0 * (y * t)) 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(-4.0 * Float64(y * t))); 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) - (-4.0 * (y * t)); 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[(-4.0 * N[(y * t), $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 - -4 \cdot \left(y \cdot t\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 94.1%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in z around 0 30.8%
*-commutative30.8%
Simplified30.8%
Final simplification90.9%
(FPCore (x y z t) :precision binary64 (if (<= z 5e+153) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (+ (* x x) (* t (* y (- (/ -1.0 (* 0.25 (/ (/ t z) z))) -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5e+153) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) + (t * (y * ((-1.0 / (0.25 * ((t / z) / z))) - -4.0)));
}
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 (z <= 5d+153) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) + (t * (y * (((-1.0d0) / (0.25d0 * ((t / z) / z))) - (-4.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5e+153) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) + (t * (y * ((-1.0 / (0.25 * ((t / z) / z))) - -4.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 5e+153: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) + (t * (y * ((-1.0 / (0.25 * ((t / z) / z))) - -4.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 5e+153) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) + Float64(t * Float64(y * Float64(Float64(-1.0 / Float64(0.25 * Float64(Float64(t / z) / z))) - -4.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 5e+153) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) + (t * (y * ((-1.0 / (0.25 * ((t / z) / z))) - -4.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 5e+153], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(t * N[(y * N[(N[(-1.0 / N[(0.25 * N[(N[(t / z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5 \cdot 10^{+153}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + t \cdot \left(y \cdot \left(\frac{-1}{0.25 \cdot \frac{\frac{t}{z}}{z}} - -4\right)\right)\\
\end{array}
\end{array}
if z < 5.00000000000000018e153Initial program 92.7%
if 5.00000000000000018e153 < z Initial program 60.8%
Taylor expanded in t around inf 60.8%
*-commutative60.8%
associate-/l*60.8%
associate-*r*60.8%
*-commutative60.8%
associate-/l*60.8%
associate-*l*60.8%
associate-/l*60.8%
distribute-lft-out60.8%
Simplified60.8%
add-sqr-sqrt60.8%
*-un-lft-identity60.8%
times-frac60.8%
*-commutative60.8%
sqrt-prod60.8%
sqrt-pow160.8%
metadata-eval60.8%
pow160.8%
metadata-eval60.8%
*-commutative60.8%
sqrt-prod60.8%
sqrt-pow178.1%
metadata-eval78.1%
pow178.1%
metadata-eval78.1%
Applied egg-rr78.1%
clear-num78.1%
clear-num78.0%
frac-times78.0%
metadata-eval78.0%
*-un-lft-identity78.0%
*-commutative78.0%
times-frac78.0%
metadata-eval78.0%
Applied egg-rr78.0%
inv-pow78.0%
associate-*l/78.1%
*-un-lft-identity78.1%
Applied egg-rr78.1%
unpow-178.1%
*-commutative78.1%
times-frac78.1%
metadata-eval78.1%
Simplified78.1%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (if (<= z 6.2e+105) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* t (* y (+ -4.0 (* (/ z (/ t z)) 4.0)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 6.2e+105) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (t * (y * (-4.0 + ((z / (t / z)) * 4.0))));
}
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 (z <= 6.2d+105) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (t * (y * ((-4.0d0) + ((z / (t / z)) * 4.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 6.2e+105) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (t * (y * (-4.0 + ((z / (t / z)) * 4.0))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 6.2e+105: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (t * (y * (-4.0 + ((z / (t / z)) * 4.0)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 6.2e+105) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(t * Float64(y * Float64(-4.0 + Float64(Float64(z / Float64(t / z)) * 4.0))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 6.2e+105) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (t * (y * (-4.0 + ((z / (t / z)) * 4.0)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 6.2e+105], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(t * N[(y * N[(-4.0 + N[(N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.2 \cdot 10^{+105}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - t \cdot \left(y \cdot \left(-4 + \frac{z}{\frac{t}{z}} \cdot 4\right)\right)\\
\end{array}
\end{array}
if z < 6.20000000000000008e105Initial program 93.4%
if 6.20000000000000008e105 < z Initial program 60.7%
Taylor expanded in t around inf 60.7%
*-commutative60.7%
associate-/l*60.6%
associate-*r*60.6%
*-commutative60.6%
associate-/l*60.7%
associate-*l*60.7%
associate-/l*60.6%
distribute-lft-out60.6%
Simplified60.6%
add-sqr-sqrt60.6%
*-un-lft-identity60.6%
times-frac60.7%
*-commutative60.7%
sqrt-prod60.7%
sqrt-pow160.7%
metadata-eval60.7%
pow160.7%
metadata-eval60.7%
*-commutative60.7%
sqrt-prod60.7%
sqrt-pow175.2%
metadata-eval75.2%
pow175.2%
metadata-eval75.2%
Applied egg-rr75.2%
clear-num75.2%
clear-num75.2%
frac-times75.2%
metadata-eval75.2%
*-un-lft-identity75.2%
*-commutative75.2%
times-frac75.2%
metadata-eval75.2%
Applied egg-rr75.2%
pow175.2%
associate-*r*74.9%
associate-/r*74.9%
inv-pow74.9%
pow-flip74.9%
metadata-eval74.9%
pow174.9%
Applied egg-rr74.9%
unpow174.9%
associate-*l*75.1%
*-commutative75.1%
times-frac75.1%
metadata-eval75.1%
Simplified75.1%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (- (* x x) (* -4.0 (* y t))))
double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (y * 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 * t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (y * t));
}
def code(x, y, z, t): return (x * x) - (-4.0 * (y * t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(-4.0 * Float64(y * t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (-4.0 * (y * t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - -4 \cdot \left(y \cdot t\right)
\end{array}
Initial program 89.3%
Taylor expanded in z around 0 63.8%
*-commutative63.8%
Simplified63.8%
Final simplification63.8%
(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 89.3%
Taylor expanded in t around inf 32.1%
*-commutative32.1%
Simplified32.1%
Final simplification32.1%
(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 2024060
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))