
(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 (<= (* x x) 4e+298) (+ (* 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) <= 4e+298) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} 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) <= 4d+298) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
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) <= 4e+298) {
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) <= 4e+298: 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) <= 4e+298) 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) <= 4e+298) 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], 4e+298], 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 4 \cdot 10^{+298}:\\
\;\;\;\;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) < 3.9999999999999998e298Initial program 94.2%
if 3.9999999999999998e298 < (*.f64 x x) Initial program 87.7%
Taylor expanded in y around 0 87.7%
Simplified94.7%
--rgt-identity94.7%
Applied egg-rr94.7%
Final simplification94.3%
(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 92.8%
fmm-def93.9%
distribute-lft-neg-in93.9%
*-commutative93.9%
distribute-rgt-neg-in93.9%
metadata-eval93.9%
Simplified93.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* 4.0 (* t y))))
(if (<= z 6.5e-276)
t_1
(if (<= z 5.8e-109)
(* x x)
(if (<= z 5.8e+44) t_1 (* (* z z) (* y -4.0)))))))
double code(double x, double y, double z, double t) {
double t_1 = 4.0 * (t * y);
double tmp;
if (z <= 6.5e-276) {
tmp = t_1;
} else if (z <= 5.8e-109) {
tmp = x * x;
} else if (z <= 5.8e+44) {
tmp = t_1;
} else {
tmp = (z * z) * (y * -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) :: t_1
real(8) :: tmp
t_1 = 4.0d0 * (t * y)
if (z <= 6.5d-276) then
tmp = t_1
else if (z <= 5.8d-109) then
tmp = x * x
else if (z <= 5.8d+44) then
tmp = t_1
else
tmp = (z * z) * (y * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = 4.0 * (t * y);
double tmp;
if (z <= 6.5e-276) {
tmp = t_1;
} else if (z <= 5.8e-109) {
tmp = x * x;
} else if (z <= 5.8e+44) {
tmp = t_1;
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): t_1 = 4.0 * (t * y) tmp = 0 if z <= 6.5e-276: tmp = t_1 elif z <= 5.8e-109: tmp = x * x elif z <= 5.8e+44: tmp = t_1 else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) t_1 = Float64(4.0 * Float64(t * y)) tmp = 0.0 if (z <= 6.5e-276) tmp = t_1; elseif (z <= 5.8e-109) tmp = Float64(x * x); elseif (z <= 5.8e+44) tmp = t_1; else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = 4.0 * (t * y); tmp = 0.0; if (z <= 6.5e-276) tmp = t_1; elseif (z <= 5.8e-109) tmp = x * x; elseif (z <= 5.8e+44) tmp = t_1; else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 6.5e-276], t$95$1, If[LessEqual[z, 5.8e-109], N[(x * x), $MachinePrecision], If[LessEqual[z, 5.8e+44], t$95$1, N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 4 \cdot \left(t \cdot y\right)\\
\mathbf{if}\;z \leq 6.5 \cdot 10^{-276}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{-109}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 6.49999999999999981e-276 or 5.8e-109 < z < 5.8000000000000004e44Initial program 94.0%
fmm-def95.2%
distribute-lft-neg-in95.2%
*-commutative95.2%
distribute-rgt-neg-in95.2%
metadata-eval95.2%
Simplified95.2%
Taylor expanded in t around inf 35.7%
*-commutative35.7%
Simplified35.7%
if 6.49999999999999981e-276 < z < 5.8e-109Initial program 97.3%
Taylor expanded in y around 0 97.3%
Simplified62.0%
--rgt-identity62.0%
Applied egg-rr62.0%
if 5.8000000000000004e44 < z Initial program 85.6%
fmm-def87.5%
distribute-lft-neg-in87.5%
*-commutative87.5%
distribute-rgt-neg-in87.5%
metadata-eval87.5%
Simplified87.5%
Taylor expanded in z around inf 76.5%
associate-*r*76.5%
*-commutative76.5%
Simplified76.5%
unpow276.5%
Applied egg-rr76.5%
Final simplification48.0%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 7.5e+158) (- (* x x) (* y (* t -4.0))) (* (* z z) (* y -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 7.5e+158) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (y * -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) <= 7.5d+158) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (z * z) * (y * (-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) <= 7.5e+158) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 7.5e+158: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 7.5e+158) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 7.5e+158) tmp = (x * x) - (y * (t * -4.0)); else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 7.5e+158], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 7.5 \cdot 10^{+158}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 7.5000000000000004e158Initial program 98.8%
Taylor expanded in z around 0 86.9%
*-commutative86.9%
*-commutative86.9%
associate-*l*86.9%
Simplified86.9%
if 7.5000000000000004e158 < (*.f64 z z) Initial program 80.5%
fmm-def84.1%
distribute-lft-neg-in84.1%
*-commutative84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
Simplified84.1%
Taylor expanded in z around inf 78.3%
associate-*r*78.3%
*-commutative78.3%
Simplified78.3%
unpow278.3%
Applied egg-rr78.3%
Final simplification84.1%
(FPCore (x y z t) :precision binary64 (if (<= x 2.6e+54) (* y (* t 4.0)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.6e+54) {
tmp = y * (t * 4.0);
} 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 <= 2.6d+54) then
tmp = y * (t * 4.0d0)
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 <= 2.6e+54) {
tmp = y * (t * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 2.6e+54: tmp = y * (t * 4.0) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 2.6e+54) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 2.6e+54) tmp = y * (t * 4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 2.6e+54], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.6 \cdot 10^{+54}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 2.60000000000000007e54Initial program 93.8%
*-commutative93.8%
add-sqr-sqrt47.7%
sqrt-unprod50.6%
swap-sqr50.6%
metadata-eval50.6%
metadata-eval50.6%
swap-sqr50.6%
sqrt-unprod16.7%
add-sqr-sqrt29.8%
add-cube-cbrt29.8%
pow329.8%
Applied egg-rr93.2%
Taylor expanded in t around inf 33.1%
rem-cube-cbrt33.5%
associate-*r*33.5%
*-commutative33.5%
associate-*r*33.5%
metadata-eval33.5%
distribute-lft-neg-in33.5%
distribute-lft-neg-in33.5%
*-commutative33.5%
distribute-rgt-neg-in33.5%
distribute-lft-neg-in33.5%
metadata-eval33.5%
Simplified33.5%
if 2.60000000000000007e54 < x Initial program 86.8%
Taylor expanded in y around 0 86.8%
Simplified84.9%
--rgt-identity84.9%
Applied egg-rr84.9%
Final simplification41.1%
(FPCore (x y z t) :precision binary64 (if (<= x 1.8e+54) (* 4.0 (* t y)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1.8e+54) {
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 <= 1.8d+54) 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 <= 1.8e+54) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 1.8e+54: tmp = 4.0 * (t * y) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 1.8e+54) 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 <= 1.8e+54) tmp = 4.0 * (t * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 1.8e+54], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.8 \cdot 10^{+54}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.8000000000000001e54Initial program 93.8%
fmm-def94.7%
distribute-lft-neg-in94.7%
*-commutative94.7%
distribute-rgt-neg-in94.7%
metadata-eval94.7%
Simplified94.7%
Taylor expanded in t around inf 33.5%
*-commutative33.5%
Simplified33.5%
if 1.8000000000000001e54 < x Initial program 86.8%
Taylor expanded in y around 0 86.8%
Simplified84.9%
--rgt-identity84.9%
Applied egg-rr84.9%
Final simplification41.1%
(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 92.8%
Taylor expanded in y around 0 92.8%
Simplified41.4%
--rgt-identity41.4%
Applied egg-rr41.4%
(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 2024184
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))