
(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 7 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 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (- (* z (* z (* y (- 4.0)))) (* -4.0 (* t y))))))
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 = (z * (z * (y * -4.0))) - (-4.0 * (t * y));
}
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 = (z * (z * (y * -4.0))) - (-4.0 * (t * y));
}
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 = (z * (z * (y * -4.0))) - (-4.0 * (t * y)) 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(z * Float64(z * Float64(y * Float64(-4.0)))) - Float64(-4.0 * Float64(t * y))); 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 = (z * (z * (y * -4.0))) - (-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[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(z * N[(z * N[(y * (-4.0)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-4.0 * N[(t * y), $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}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot \left(-4\right)\right)\right) - -4 \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 97.2%
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 0.0%
Taylor expanded in x around 0 57.1%
+-commutative57.1%
add-sqr-sqrt50.0%
*-commutative50.0%
fma-def50.0%
sqrt-prod50.0%
metadata-eval50.0%
*-commutative50.0%
sqrt-prod42.9%
unpow242.9%
sqrt-prod21.4%
add-sqr-sqrt35.7%
sqrt-prod35.7%
metadata-eval35.7%
*-commutative35.7%
sqrt-prod35.7%
unpow235.7%
sqrt-prod21.4%
add-sqr-sqrt42.9%
*-commutative42.9%
Applied egg-rr42.9%
fma-udef42.9%
unpow242.9%
associate-*r*42.9%
associate-*r*42.9%
*-commutative42.9%
*-commutative42.9%
Simplified42.9%
unpow242.9%
*-commutative42.9%
*-commutative42.9%
associate-*r*42.9%
metadata-eval42.9%
sqrt-prod42.9%
associate-*r*42.9%
metadata-eval42.9%
sqrt-prod42.9%
unswap-sqr42.9%
add-sqr-sqrt57.1%
associate-*r*57.2%
Applied egg-rr57.2%
Final simplification95.0%
(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.9%
fma-neg95.0%
distribute-lft-neg-in95.0%
*-commutative95.0%
distribute-rgt-neg-in95.0%
metadata-eval95.0%
Simplified95.0%
Final simplification95.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* y (* z (* z -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 = y * (z * (z * -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 = y * (z * (z * -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 = y * (z * (z * -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(y * Float64(z * Float64(z * -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 = y * (z * (z * -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[(y * N[(z * N[(z * -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}:\\
\;\;\;\;y \cdot \left(z \cdot \left(z \cdot -4\right)\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 97.2%
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 inf 36.1%
*-commutative36.1%
associate-*l*36.1%
Simplified36.1%
add-cube-cbrt36.1%
pow336.1%
*-commutative36.1%
Applied egg-rr36.1%
rem-cube-cbrt36.1%
unpow236.1%
associate-*r*36.1%
Applied egg-rr36.1%
Final simplification93.9%
(FPCore (x y z t)
:precision binary64
(if (<= (* z z) 2e+54)
(- (* x x) (* -4.0 (* t y)))
(if (<= (* z z) 1e+303)
(- (* x x) (* (* z z) (* y 4.0)))
(* y (* z (* z -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+54) {
tmp = (x * x) - (-4.0 * (t * y));
} else if ((z * z) <= 1e+303) {
tmp = (x * x) - ((z * z) * (y * 4.0));
} else {
tmp = y * (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 * z) <= 2d+54) then
tmp = (x * x) - ((-4.0d0) * (t * y))
else if ((z * z) <= 1d+303) then
tmp = (x * x) - ((z * z) * (y * 4.0d0))
else
tmp = y * (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 * z) <= 2e+54) {
tmp = (x * x) - (-4.0 * (t * y));
} else if ((z * z) <= 1e+303) {
tmp = (x * x) - ((z * z) * (y * 4.0));
} else {
tmp = y * (z * (z * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 2e+54: tmp = (x * x) - (-4.0 * (t * y)) elif (z * z) <= 1e+303: tmp = (x * x) - ((z * z) * (y * 4.0)) else: tmp = y * (z * (z * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+54) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); elseif (Float64(z * z) <= 1e+303) tmp = Float64(Float64(x * x) - Float64(Float64(z * z) * Float64(y * 4.0))); else tmp = Float64(y * Float64(z * Float64(z * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 2e+54) tmp = (x * x) - (-4.0 * (t * y)); elseif ((z * z) <= 1e+303) tmp = (x * x) - ((z * z) * (y * 4.0)); else tmp = y * (z * (z * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+54], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+303], N[(N[(x * x), $MachinePrecision] - N[(N[(z * z), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+54}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{elif}\;z \cdot z \leq 10^{+303}:\\
\;\;\;\;x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(z \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000002e54Initial program 96.5%
Taylor expanded in z around 0 90.2%
*-commutative90.2%
Simplified90.2%
if 2.0000000000000002e54 < (*.f64 z z) < 1e303Initial program 91.9%
add-cube-cbrt91.3%
pow391.3%
pow291.3%
Applied egg-rr91.3%
Taylor expanded in t around 0 75.7%
unpow1/378.6%
Simplified78.6%
unpow378.6%
add-cube-cbrt79.1%
unpow279.1%
Applied egg-rr79.1%
if 1e303 < (*.f64 z z) Initial program 80.1%
Taylor expanded in z around inf 87.0%
*-commutative87.0%
associate-*l*87.0%
Simplified87.0%
add-cube-cbrt87.0%
pow387.0%
*-commutative87.0%
Applied egg-rr87.0%
rem-cube-cbrt87.0%
unpow287.0%
associate-*r*87.0%
Applied egg-rr87.0%
Final simplification87.2%
(FPCore (x y z t) :precision binary64 (if (<= z 3.2e+114) (- (* x x) (* -4.0 (* t y))) (* y (* z (* z -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.2e+114) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = y * (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 <= 3.2d+114) then
tmp = (x * x) - ((-4.0d0) * (t * y))
else
tmp = y * (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 <= 3.2e+114) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = y * (z * (z * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.2e+114: tmp = (x * x) - (-4.0 * (t * y)) else: tmp = y * (z * (z * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.2e+114) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); else tmp = Float64(y * Float64(z * Float64(z * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.2e+114) tmp = (x * x) - (-4.0 * (t * y)); else tmp = y * (z * (z * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.2e+114], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.2 \cdot 10^{+114}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(z \cdot -4\right)\right)\\
\end{array}
\end{array}
if z < 3.2e114Initial program 92.8%
Taylor expanded in z around 0 74.5%
*-commutative74.5%
Simplified74.5%
if 3.2e114 < z Initial program 86.4%
Taylor expanded in z around inf 92.0%
*-commutative92.0%
associate-*l*92.0%
Simplified92.0%
add-cube-cbrt92.0%
pow392.0%
*-commutative92.0%
Applied egg-rr92.0%
rem-cube-cbrt92.0%
unpow292.0%
associate-*r*92.0%
Applied egg-rr92.0%
Final simplification77.0%
(FPCore (x y z t) :precision binary64 (if (<= z 1.95e+27) (* y (* t 4.0)) (* y (* z (* z -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.95e+27) {
tmp = y * (t * 4.0);
} else {
tmp = y * (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 <= 1.95d+27) then
tmp = y * (t * 4.0d0)
else
tmp = y * (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 <= 1.95e+27) {
tmp = y * (t * 4.0);
} else {
tmp = y * (z * (z * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.95e+27: tmp = y * (t * 4.0) else: tmp = y * (z * (z * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.95e+27) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(y * Float64(z * Float64(z * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.95e+27) tmp = y * (t * 4.0); else tmp = y * (z * (z * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.95e+27], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.95 \cdot 10^{+27}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(z \cdot -4\right)\right)\\
\end{array}
\end{array}
if z < 1.9499999999999999e27Initial program 92.8%
Taylor expanded in t around inf 33.9%
*-commutative33.9%
*-commutative33.9%
associate-*l*33.9%
Simplified33.9%
if 1.9499999999999999e27 < z Initial program 88.1%
Taylor expanded in z around inf 78.5%
*-commutative78.5%
associate-*l*78.5%
Simplified78.5%
add-cube-cbrt78.3%
pow378.3%
*-commutative78.3%
Applied egg-rr78.3%
rem-cube-cbrt78.5%
unpow278.5%
associate-*r*78.5%
Applied egg-rr78.5%
Final simplification42.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(y * Float64(t * 4.0)) end
function tmp = code(x, y, z, t) tmp = y * (t * 4.0); end
code[x_, y_, z_, t_] := N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(t \cdot 4\right)
\end{array}
Initial program 91.9%
Taylor expanded in t around inf 30.0%
*-commutative30.0%
*-commutative30.0%
associate-*l*30.0%
Simplified30.0%
Final simplification30.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 2023302
(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))))