
(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) t) 1e+296) (fma (* y 4.0) (- t (* z z)) (* x x)) (* (* y (fma z (/ z t) -1.0)) (* t -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) - t) <= 1e+296) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = (y * fma(z, (z / t), -1.0)) * (t * -4.0);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(z * z) - t) <= 1e+296) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64(y * fma(z, Float64(z / t), -1.0)) * Float64(t * -4.0)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision], 1e+296], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z * N[(z / t), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z - t \leq 10^{+296}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot \mathsf{fma}\left(z, \frac{z}{t}, -1\right)\right) \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 z z) t) < 9.99999999999999981e295Initial program 96.7%
cancel-sign-sub-inv96.7%
distribute-lft-neg-out96.7%
+-commutative96.7%
associate-*l*96.7%
distribute-lft-neg-in96.7%
associate-*l*96.7%
distribute-rgt-neg-in96.7%
fma-define99.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
if 9.99999999999999981e295 < (-.f64 (*.f64 z z) t) Initial program 65.5%
add-cube-cbrt65.5%
pow365.5%
pow265.5%
Applied egg-rr65.5%
Taylor expanded in t around inf 65.5%
unpow265.5%
associate-*r/65.5%
fma-neg65.5%
metadata-eval65.5%
Simplified65.5%
Taylor expanded in x around 0 69.9%
associate-*r*69.9%
*-commutative69.9%
unpow269.9%
associate-*r/79.2%
fma-neg79.2%
metadata-eval79.2%
*-commutative79.2%
Simplified79.2%
Final simplification94.3%
(FPCore (x y z t) :precision binary64 (if (<= x 5e+167) (fma x x (* (- (* z z) t) (* y -4.0))) (fma (* y 4.0) t (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 5e+167) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = fma((y * 4.0), t, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 5e+167) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = fma(Float64(y * 4.0), t, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 5e+167], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * 4.0), $MachinePrecision] * t + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+167}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t, x \cdot x\right)\\
\end{array}
\end{array}
if x < 4.9999999999999997e167Initial program 90.7%
fma-neg92.5%
distribute-lft-neg-in92.5%
*-commutative92.5%
distribute-rgt-neg-in92.5%
metadata-eval92.5%
Simplified92.5%
if 4.9999999999999997e167 < x Initial program 70.0%
cancel-sign-sub-inv70.0%
distribute-lft-neg-out70.0%
+-commutative70.0%
associate-*l*70.0%
distribute-lft-neg-in70.0%
associate-*l*70.0%
distribute-rgt-neg-in70.0%
fma-define86.7%
sub-neg86.7%
+-commutative86.7%
distribute-neg-in86.7%
remove-double-neg86.7%
sub-neg86.7%
Simplified86.7%
Taylor expanded in t around inf 100.0%
Final simplification93.4%
(FPCore (x y z t) :precision binary64 (if (<= x 1.3e+154) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (fma (* y 4.0) t (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1.3e+154) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = fma((y * 4.0), t, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 1.3e+154) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = fma(Float64(y * 4.0), t, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 1.3e+154], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * 4.0), $MachinePrecision] * t + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.3 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t, x \cdot x\right)\\
\end{array}
\end{array}
if x < 1.29999999999999994e154Initial program 91.4%
if 1.29999999999999994e154 < x Initial program 68.6%
cancel-sign-sub-inv68.6%
distribute-lft-neg-out68.6%
+-commutative68.6%
associate-*l*68.6%
distribute-lft-neg-in68.6%
associate-*l*68.6%
distribute-rgt-neg-in68.6%
fma-define82.9%
sub-neg82.9%
+-commutative82.9%
distribute-neg-in82.9%
remove-double-neg82.9%
sub-neg82.9%
Simplified82.9%
Taylor expanded in t around inf 94.3%
Final simplification91.8%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) INFINITY) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= ((double) INFINITY)) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = x * x;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= Double.POSITIVE_INFINITY) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= math.inf: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= Inf) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= Inf) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], Infinity], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq \infty:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < +inf.0Initial program 88.3%
if +inf.0 < (*.f64 x x) Initial program 88.3%
Taylor expanded in y around 0 88.3%
Simplified40.1%
Final simplification88.3%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.7e+308) (- (* x x) (* -4.0 (* t y))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.7e+308) {
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.7d+308) 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.7e+308) {
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.7e+308: 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.7e+308) 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.7e+308) 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.7e+308], 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.7 \cdot 10^{+308}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.6999999999999999e308Initial program 92.7%
Taylor expanded in z around 0 57.4%
*-commutative57.4%
Simplified57.4%
if 1.6999999999999999e308 < (*.f64 x x) Initial program 75.0%
Taylor expanded in y around 0 75.0%
Simplified93.8%
Final simplification66.5%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 7e-22) (* 4.0 (* t y)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 7e-22) {
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) <= 7d-22) 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) <= 7e-22) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 7e-22: tmp = 4.0 * (t * y) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 7e-22) 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) <= 7e-22) 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], 7e-22], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 7 \cdot 10^{-22}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 7.00000000000000011e-22Initial program 93.6%
Taylor expanded in t around inf 46.2%
*-commutative46.2%
Simplified46.2%
if 7.00000000000000011e-22 < (*.f64 x x) Initial program 83.9%
Taylor expanded in y around 0 83.9%
Simplified65.9%
Final simplification56.9%
(FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
double code(double x, double y, double z, double t) {
return 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 = 4.0d0 * (t * y)
end function
public static double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
def code(x, y, z, t): return 4.0 * (t * y)
function code(x, y, z, t) return Float64(4.0 * Float64(t * y)) end
function tmp = code(x, y, z, t) tmp = 4.0 * (t * y); end
code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 88.3%
Taylor expanded in t around inf 31.0%
*-commutative31.0%
Simplified31.0%
Final simplification31.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 2024071
(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))))