
(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 (fma x x (* (- (* z z) t) (* y -4.0))))
double code(double x, double y, double z, double t) {
return fma(x, x, (((z * z) - t) * (y * -4.0)));
}
function code(x, y, z, t) return fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))) end
code[x_, y_, z_, t_] := N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)
\end{array}
Initial program 91.4%
fma-neg95.8%
distribute-lft-neg-in95.8%
*-commutative95.8%
distribute-rgt-neg-in95.8%
metadata-eval95.8%
Simplified95.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- (* x x) (* (- (* z z) t) (* y 4.0))))) (if (<= t_1 INFINITY) t_1 (* (* y -4.0) (pow z 2.0)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (y * -4.0) * pow(z, 2.0);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (y * -4.0) * Math.pow(z, 2.0);
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) - (((z * z) - t) * (y * 4.0)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (y * -4.0) * math.pow(z, 2.0) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) - Float64(Float64(Float64(z * z) - t) * Float64(y * 4.0))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(y * -4.0) * (z ^ 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) - (((z * z) - t) * (y * 4.0)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (y * -4.0) * (z ^ 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] - N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(y * -4.0), $MachinePrecision] * N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x - \left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot {z}^{2}\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 97.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 inf 67.3%
associate-*r*67.3%
*-commutative67.3%
Simplified67.3%
Final simplification95.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- (* x x) (* (- (* z z) t) (* y 4.0))))) (if (<= t_1 INFINITY) t_1 (* -4.0 (* t y)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = -4.0 * (t * y);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = -4.0 * (t * y);
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) - (((z * z) - t) * (y * 4.0)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = -4.0 * (t * y) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) - Float64(Float64(Float64(z * z) - t) * Float64(y * 4.0))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(-4.0 * Float64(t * y)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) - (((z * z) - t) * (y * 4.0)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = -4.0 * (t * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] - N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x - \left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot y\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 97.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 6.7%
*-commutative6.7%
Simplified6.7%
associate-*r*6.7%
*-commutative6.7%
add-sqr-sqrt0.0%
sqrt-unprod13.3%
swap-sqr13.3%
metadata-eval13.3%
metadata-eval13.3%
swap-sqr13.3%
sqrt-unprod20.0%
add-sqr-sqrt26.7%
*-commutative26.7%
associate-*r*26.7%
metadata-eval26.7%
distribute-lft-neg-in26.7%
Applied egg-rr26.7%
Taylor expanded in x around 0 27.4%
*-commutative27.4%
Simplified27.4%
Final simplification93.1%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.35e+235) (- (* x x) (* -4.0 (* t y))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.35e+235) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = x * x;
}
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 ((x * x) <= 1.35d+235) then
tmp = (x * x) - ((-4.0d0) * (t * y))
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.35e+235) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 1.35e+235: tmp = (x * x) - (-4.0 * (t * y)) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1.35e+235) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 1.35e+235) tmp = (x * x) - (-4.0 * (t * y)); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.35e+235], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.35 \cdot 10^{+235}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.3499999999999999e235Initial program 96.4%
Taylor expanded in z around 0 66.4%
*-commutative66.4%
Simplified66.4%
if 1.3499999999999999e235 < (*.f64 x x) Initial program 82.6%
Taylor expanded in x around inf 84.3%
pow284.3%
Applied egg-rr84.3%
Final simplification72.8%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1450000.0) (* 4.0 (* t y)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1450000.0) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
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 ((x * x) <= 1450000.0d0) then
tmp = 4.0d0 * (t * y)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1450000.0) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 1450000.0: tmp = 4.0 * (t * y) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1450000.0) tmp = Float64(4.0 * Float64(t * y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 1450000.0) tmp = 4.0 * (t * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1450000.0], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1450000:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.45e6Initial program 98.4%
Taylor expanded in t around inf 53.1%
*-commutative53.1%
Simplified53.1%
if 1.45e6 < (*.f64 x x) Initial program 85.2%
Taylor expanded in x around inf 74.6%
pow274.6%
Applied egg-rr74.6%
Final simplification64.5%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 91.4%
Taylor expanded in x around inf 46.2%
pow246.2%
Applied egg-rr46.2%
(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 2024091
(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))))