
(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 (if (<= (* x x) 2e+245) (fma x x (* (- (* z z) t) (* y -4.0))) (fma x x (* y (* t 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2e+245) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = fma(x, x, (y * (t * 4.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 2e+245) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = fma(x, x, Float64(y * Float64(t * 4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+245], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+245}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(t \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.00000000000000009e245Initial program 94.7%
fma-neg94.7%
distribute-lft-neg-in94.7%
*-commutative94.7%
distribute-rgt-neg-in94.7%
metadata-eval94.7%
Simplified94.7%
if 2.00000000000000009e245 < (*.f64 x x) Initial program 80.6%
Taylor expanded in z around 0 92.4%
*-commutative92.4%
*-commutative92.4%
associate-*l*92.4%
Simplified92.4%
fma-neg96.3%
distribute-rgt-neg-in96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
Applied egg-rr96.3%
Final simplification95.2%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 2e+245) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (fma x x (* y (* t 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2e+245) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = fma(x, x, (y * (t * 4.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 2e+245) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = fma(x, x, Float64(y * Float64(t * 4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+245], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+245}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(t \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.00000000000000009e245Initial program 94.7%
if 2.00000000000000009e245 < (*.f64 x x) Initial program 80.6%
Taylor expanded in z around 0 92.4%
*-commutative92.4%
*-commutative92.4%
associate-*l*92.4%
Simplified92.4%
fma-neg96.3%
distribute-rgt-neg-in96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
Applied egg-rr96.3%
Final simplification95.2%
(FPCore (x y z t)
:precision binary64
(if (or (<= (* z z) 1.28e-17)
(and (not (<= (* z z) 38000000000.0)) (<= (* z z) 3.1e+182)))
(- (* x x) (* y (* t -4.0)))
(* y (* (* z z) -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) <= 1.28e-17) || (!((z * z) <= 38000000000.0) && ((z * z) <= 3.1e+182))) {
tmp = (x * x) - (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 * z) <= 1.28d-17) .or. (.not. ((z * z) <= 38000000000.0d0)) .and. ((z * z) <= 3.1d+182)) then
tmp = (x * x) - (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 * z) <= 1.28e-17) || (!((z * z) <= 38000000000.0) && ((z * z) <= 3.1e+182))) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = y * ((z * z) * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * z) <= 1.28e-17) or (not ((z * z) <= 38000000000.0) and ((z * z) <= 3.1e+182)): tmp = (x * x) - (y * (t * -4.0)) else: tmp = y * ((z * z) * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * z) <= 1.28e-17) || (!(Float64(z * z) <= 38000000000.0) && (Float64(z * z) <= 3.1e+182))) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(y * Float64(Float64(z * z) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * z) <= 1.28e-17) || (~(((z * z) <= 38000000000.0)) && ((z * z) <= 3.1e+182))) tmp = (x * x) - (y * (t * -4.0)); else tmp = y * ((z * z) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * z), $MachinePrecision], 1.28e-17], And[N[Not[LessEqual[N[(z * z), $MachinePrecision], 38000000000.0]], $MachinePrecision], LessEqual[N[(z * z), $MachinePrecision], 3.1e+182]]], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 1.28 \cdot 10^{-17} \lor \neg \left(z \cdot z \leq 38000000000\right) \land z \cdot z \leq 3.1 \cdot 10^{+182}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.28e-17 or 3.8e10 < (*.f64 z z) < 3.09999999999999996e182Initial program 98.7%
Taylor expanded in z around 0 91.5%
*-commutative91.5%
*-commutative91.5%
associate-*l*91.5%
Simplified91.5%
if 1.28e-17 < (*.f64 z z) < 3.8e10 or 3.09999999999999996e182 < (*.f64 z z) Initial program 77.4%
Taylor expanded in z around inf 71.7%
*-commutative71.7%
associate-*l*71.7%
Simplified71.7%
unpow271.7%
Applied egg-rr71.7%
Final simplification83.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= (* z z) 5.7e-18)
(and (not (<= (* z z) 4.8e+46)) (<= (* z z) 1.35e+114)))
(* t (* y 4.0))
(* y (* (* z z) -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) <= 5.7e-18) || (!((z * z) <= 4.8e+46) && ((z * z) <= 1.35e+114))) {
tmp = t * (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) <= 5.7d-18) .or. (.not. ((z * z) <= 4.8d+46)) .and. ((z * z) <= 1.35d+114)) then
tmp = t * (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) <= 5.7e-18) || (!((z * z) <= 4.8e+46) && ((z * z) <= 1.35e+114))) {
tmp = t * (y * 4.0);
} else {
tmp = y * ((z * z) * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * z) <= 5.7e-18) or (not ((z * z) <= 4.8e+46) and ((z * z) <= 1.35e+114)): tmp = t * (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) <= 5.7e-18) || (!(Float64(z * z) <= 4.8e+46) && (Float64(z * z) <= 1.35e+114))) tmp = Float64(t * Float64(y * 4.0)); else tmp = Float64(y * Float64(Float64(z * z) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * z) <= 5.7e-18) || (~(((z * z) <= 4.8e+46)) && ((z * z) <= 1.35e+114))) tmp = t * (y * 4.0); else tmp = y * ((z * z) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * z), $MachinePrecision], 5.7e-18], And[N[Not[LessEqual[N[(z * z), $MachinePrecision], 4.8e+46]], $MachinePrecision], LessEqual[N[(z * z), $MachinePrecision], 1.35e+114]]], N[(t * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5.7 \cdot 10^{-18} \lor \neg \left(z \cdot z \leq 4.8 \cdot 10^{+46}\right) \land z \cdot z \leq 1.35 \cdot 10^{+114}:\\
\;\;\;\;t \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.69999999999999971e-18 or 4.80000000000000017e46 < (*.f64 z z) < 1.35e114Initial program 98.4%
Taylor expanded in t around inf 50.6%
*-commutative50.6%
associate-*r*50.6%
*-commutative50.6%
Simplified50.6%
if 5.69999999999999971e-18 < (*.f64 z z) < 4.80000000000000017e46 or 1.35e114 < (*.f64 z z) Initial program 82.1%
Taylor expanded in z around inf 63.7%
*-commutative63.7%
associate-*l*63.7%
Simplified63.7%
unpow263.7%
Applied egg-rr63.7%
Final simplification57.0%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 8.8e+246) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* y (* t -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 8.8e+246) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (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 ((x * x) <= 8.8d+246) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (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 ((x * x) <= 8.8e+246) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 8.8e+246: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (y * (t * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 8.8e+246) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 8.8e+246) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 8.8e+246], 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[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 8.8 \cdot 10^{+246}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 8.79999999999999952e246Initial program 94.7%
if 8.79999999999999952e246 < (*.f64 x x) Initial program 80.6%
Taylor expanded in z around 0 92.4%
*-commutative92.4%
*-commutative92.4%
associate-*l*92.4%
Simplified92.4%
Final simplification94.0%
(FPCore (x y z t) :precision binary64 (* t (* y 4.0)))
double code(double x, double y, double z, double t) {
return t * (y * 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 = t * (y * 4.0d0)
end function
public static double code(double x, double y, double z, double t) {
return t * (y * 4.0);
}
def code(x, y, z, t): return t * (y * 4.0)
function code(x, y, z, t) return Float64(t * Float64(y * 4.0)) end
function tmp = code(x, y, z, t) tmp = t * (y * 4.0); end
code[x_, y_, z_, t_] := N[(t * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t \cdot \left(y \cdot 4\right)
\end{array}
Initial program 90.4%
Taylor expanded in t around inf 31.7%
*-commutative31.7%
associate-*r*31.7%
*-commutative31.7%
Simplified31.7%
Final simplification31.7%
(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 2024017
(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))))