
(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 (if (<= (* z z) 4e+300) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* (/ y (/ 1.0 z)) (/ 4.0 (/ 1.0 z))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+300) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / 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 ((z * z) <= 4d+300) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - ((y / (1.0d0 / z)) * (4.0d0 / (1.0d0 / z)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+300) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 4e+300: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 4e+300) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(Float64(y / Float64(1.0 / z)) * Float64(4.0 / Float64(1.0 / z)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 4e+300) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 4e+300], 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[(N[(y / N[(1.0 / z), $MachinePrecision]), $MachinePrecision] * N[(4.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+300}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \frac{y}{\frac{1}{z}} \cdot \frac{4}{\frac{1}{z}}\\
\end{array}
\end{array}
if (*.f64 z z) < 4.0000000000000002e300Initial program 97.9%
if 4.0000000000000002e300 < (*.f64 z z) Initial program 77.6%
sub-neg77.6%
flip-+0.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
Applied egg-rr0.0%
clear-num0.0%
un-div-inv0.0%
clear-num0.0%
metadata-eval0.0%
pow-sqr0.0%
sqr-neg0.0%
sub-neg0.0%
remove-double-neg0.0%
flip--77.6%
unpow277.6%
fma-neg77.6%
add-sqr-sqrt29.7%
sqrt-prod76.1%
sqr-neg76.1%
sqrt-prod47.9%
add-sqr-sqrt77.6%
Applied egg-rr77.6%
Taylor expanded in z around inf 77.6%
add-sqr-sqrt77.6%
times-frac77.6%
sqrt-div77.6%
metadata-eval77.6%
unpow277.6%
sqrt-prod38.1%
add-sqr-sqrt41.4%
sqrt-div41.4%
metadata-eval41.4%
unpow241.4%
sqrt-prod47.5%
add-sqr-sqrt90.0%
Applied egg-rr90.0%
Final simplification96.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 93.0%
fma-neg95.4%
distribute-lft-neg-in95.4%
*-commutative95.4%
distribute-rgt-neg-in95.4%
metadata-eval95.4%
Simplified95.4%
Final simplification95.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 4.0) (/ 1.0 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) - ((y * 4.0) / (1.0 / 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) - ((y * 4.0) / (1.0 / 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) - ((y * 4.0) / (1.0 / 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(Float64(y * 4.0) / Float64(1.0 / 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) - ((y * 4.0) / (1.0 / 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[(N[(y * 4.0), $MachinePrecision] / N[(1.0 / 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 - \frac{y \cdot 4}{\frac{1}{t}}\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 97.6%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) Initial program 0.0%
sub-neg0.0%
flip-+0.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
Applied egg-rr0.0%
clear-num0.0%
un-div-inv0.0%
clear-num0.0%
metadata-eval0.0%
pow-sqr0.0%
sqr-neg0.0%
sub-neg0.0%
remove-double-neg0.0%
flip--0.0%
unpow20.0%
fma-neg0.0%
add-sqr-sqrt0.0%
sqrt-prod8.3%
sqr-neg8.3%
sqrt-prod8.3%
add-sqr-sqrt8.3%
Applied egg-rr8.3%
Taylor expanded in z around 0 50.0%
Final simplification95.4%
(FPCore (x y z t) :precision binary64 (if (<= z 1.45e+102) (- (* x x) (* -4.0 (* t y))) (- (* x x) (/ (* y 4.0) (/ 1.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+102) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = (x * x) - ((y * 4.0) / (1.0 / t));
}
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.45d+102) then
tmp = (x * x) - ((-4.0d0) * (t * y))
else
tmp = (x * x) - ((y * 4.0d0) / (1.0d0 / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+102) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = (x * x) - ((y * 4.0) / (1.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.45e+102: tmp = (x * x) - (-4.0 * (t * y)) else: tmp = (x * x) - ((y * 4.0) / (1.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.45e+102) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); else tmp = Float64(Float64(x * x) - Float64(Float64(y * 4.0) / Float64(1.0 / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.45e+102) tmp = (x * x) - (-4.0 * (t * y)); else tmp = (x * x) - ((y * 4.0) / (1.0 / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.45e+102], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] / N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+102}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \frac{y \cdot 4}{\frac{1}{t}}\\
\end{array}
\end{array}
if z < 1.4500000000000001e102Initial program 95.2%
Taylor expanded in z around 0 67.5%
*-commutative67.5%
Simplified67.5%
if 1.4500000000000001e102 < z Initial program 82.7%
sub-neg82.7%
flip-+7.3%
pow27.3%
pow27.3%
pow-prod-up7.3%
metadata-eval7.3%
pow27.3%
Applied egg-rr7.3%
clear-num7.3%
un-div-inv7.3%
clear-num7.3%
metadata-eval7.3%
pow-sqr7.3%
sqr-neg7.3%
sub-neg7.3%
remove-double-neg7.3%
flip--82.8%
unpow282.8%
fma-neg82.8%
add-sqr-sqrt42.4%
sqrt-prod72.5%
sqr-neg72.5%
sqrt-prod40.3%
add-sqr-sqrt80.5%
Applied egg-rr80.5%
Taylor expanded in z around 0 15.5%
Final simplification58.3%
(FPCore (x y z t) :precision binary64 (- (* x x) (* -4.0 (* t y))))
double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (t * y));
}
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) * (t * y))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (t * y));
}
def code(x, y, z, t): return (x * x) - (-4.0 * (t * y))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (-4.0 * (t * y)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - -4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 93.0%
Taylor expanded in z around 0 58.5%
*-commutative58.5%
Simplified58.5%
Final simplification58.5%
(FPCore (x y z t) :precision binary64 (if (<= z 1.9e+102) (* y (* t 4.0)) (* y (* t -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.9e+102) {
tmp = y * (t * 4.0);
} else {
tmp = y * (t * -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.9d+102) then
tmp = y * (t * 4.0d0)
else
tmp = y * (t * (-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.9e+102) {
tmp = y * (t * 4.0);
} else {
tmp = y * (t * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.9e+102: tmp = y * (t * 4.0) else: tmp = y * (t * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.9e+102) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(y * Float64(t * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.9e+102) tmp = y * (t * 4.0); else tmp = y * (t * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.9e+102], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.9 \cdot 10^{+102}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if z < 1.89999999999999989e102Initial program 95.2%
Taylor expanded in t around inf 32.7%
*-commutative32.7%
*-commutative32.7%
associate-*l*32.7%
Simplified32.7%
if 1.89999999999999989e102 < z Initial program 82.7%
Taylor expanded in t around inf 7.6%
*-commutative7.6%
*-commutative7.6%
Simplified7.6%
add-sqr-sqrt3.6%
sqrt-unprod12.8%
*-commutative12.8%
*-commutative12.8%
swap-sqr12.8%
metadata-eval12.8%
metadata-eval12.8%
swap-sqr12.8%
*-commutative12.8%
*-commutative12.8%
sqrt-unprod3.1%
add-log-exp11.6%
add-sqr-sqrt19.2%
associate-*r*19.2%
exp-prod12.6%
Applied egg-rr12.6%
log-pow12.6%
rem-log-exp6.5%
Simplified6.5%
Final simplification28.1%
(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 93.0%
Taylor expanded in t around inf 28.3%
*-commutative28.3%
*-commutative28.3%
Simplified28.3%
add-sqr-sqrt15.4%
sqrt-unprod20.0%
*-commutative20.0%
*-commutative20.0%
swap-sqr20.0%
metadata-eval20.0%
metadata-eval20.0%
swap-sqr20.0%
*-commutative20.0%
*-commutative20.0%
sqrt-unprod4.7%
add-log-exp11.4%
add-sqr-sqrt17.1%
associate-*r*17.1%
exp-prod14.7%
Applied egg-rr14.7%
log-pow14.4%
rem-log-exp7.9%
Simplified7.9%
Final simplification7.9%
(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 2023301
(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))))