
(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 (<= (* z z) 4e+301) (fma x x (* (- (* z z) t) (* y -4.0))) (* -4.0 (* t (* y (+ (* z (/ z t)) -1.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+301) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = -4.0 * (t * (y * ((z * (z / t)) + -1.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 4e+301) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(-4.0 * Float64(t * Float64(y * Float64(Float64(z * Float64(z / t)) + -1.0)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 4e+301], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(y * N[(N[(z * N[(z / t), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+301}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(y \cdot \left(z \cdot \frac{z}{t} + -1\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.00000000000000021e301Initial program 97.2%
fma-neg98.8%
distribute-lft-neg-in98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
Simplified98.8%
if 4.00000000000000021e301 < (*.f64 z z) Initial program 67.5%
Taylor expanded in t around inf 67.5%
+-commutative67.5%
*-commutative67.5%
*-commutative67.5%
metadata-eval67.5%
distribute-rgt-neg-in67.5%
distribute-lft-neg-in67.5%
distribute-rgt-out67.5%
unsub-neg67.5%
associate-/l*67.5%
Simplified67.5%
Taylor expanded in y around inf 74.9%
unpow274.9%
*-un-lft-identity74.9%
times-frac85.8%
Applied egg-rr85.8%
Final simplification95.4%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 4e+301) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* -4.0 (* t (* y (+ (* z (/ z t)) -1.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+301) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (t * (y * ((z * (z / t)) + -1.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) <= 4d+301) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (-4.0d0) * (t * (y * ((z * (z / t)) + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+301) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (t * (y * ((z * (z / t)) + -1.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 4e+301: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = -4.0 * (t * (y * ((z * (z / t)) + -1.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 4e+301) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(-4.0 * Float64(t * Float64(y * Float64(Float64(z * Float64(z / t)) + -1.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 4e+301) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = -4.0 * (t * (y * ((z * (z / t)) + -1.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 4e+301], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(y * N[(N[(z * N[(z / t), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+301}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(y \cdot \left(z \cdot \frac{z}{t} + -1\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.00000000000000021e301Initial program 97.2%
if 4.00000000000000021e301 < (*.f64 z z) Initial program 67.5%
Taylor expanded in t around inf 67.5%
+-commutative67.5%
*-commutative67.5%
*-commutative67.5%
metadata-eval67.5%
distribute-rgt-neg-in67.5%
distribute-lft-neg-in67.5%
distribute-rgt-out67.5%
unsub-neg67.5%
associate-/l*67.5%
Simplified67.5%
Taylor expanded in y around inf 74.9%
unpow274.9%
*-un-lft-identity74.9%
times-frac85.8%
Applied egg-rr85.8%
Final simplification94.2%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 3.2e+296) (+ (* 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) <= 3.2e+296) {
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) <= 3.2d+296) 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) <= 3.2e+296) {
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) <= 3.2e+296: 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) <= 3.2e+296) 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) <= 3.2e+296) 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], 3.2e+296], 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 3.2 \cdot 10^{+296}:\\
\;\;\;\;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.1999999999999999e296Initial program 92.9%
if 3.1999999999999999e296 < (*.f64 x x) Initial program 79.7%
Taylor expanded in y around 0 79.7%
Simplified88.4%
--rgt-identity88.4%
Applied egg-rr88.4%
Final simplification91.7%
(FPCore (x y z t) :precision binary64 (if (<= x 5.6e+31) (* 4.0 (* t y)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 5.6e+31) {
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 <= 5.6d+31) 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 <= 5.6e+31) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 5.6e+31: tmp = 4.0 * (t * y) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 5.6e+31) 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 <= 5.6e+31) tmp = 4.0 * (t * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 5.6e+31], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{+31}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 5.60000000000000034e31Initial program 90.7%
Taylor expanded in t around inf 35.3%
*-commutative35.3%
Simplified35.3%
if 5.60000000000000034e31 < x Initial program 84.4%
Taylor expanded in y around 0 84.4%
Simplified63.8%
--rgt-identity63.8%
Applied egg-rr63.8%
Final simplification41.6%
(FPCore (x y z t) :precision binary64 (- (* x x) (* y (* t -4.0))))
double code(double x, double y, double z, double t) {
return (x * x) - (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 = (x * x) - (y * (t * (-4.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
def code(x, y, z, t): return (x * x) - (y * (t * -4.0))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (y * (t * -4.0)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 89.3%
Taylor expanded in z around 0 62.5%
*-commutative62.5%
*-commutative62.5%
associate-*l*62.5%
Simplified62.5%
(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 89.3%
Taylor expanded in y around 0 89.3%
Simplified38.2%
--rgt-identity38.2%
Applied egg-rr38.2%
(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 2024116
(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))))