
(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 8 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+263) (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 * x) <= 2e+263) {
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 (Float64(x * x) <= 2e+263) 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[N[(x * x), $MachinePrecision], 2e+263], 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 \cdot x \leq 2 \cdot 10^{+263}:\\
\;\;\;\;\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 (*.f64 x x) < 2.00000000000000003e263Initial program 94.2%
fma-neg94.2%
distribute-lft-neg-in94.2%
*-commutative94.2%
distribute-rgt-neg-in94.2%
metadata-eval94.2%
Simplified94.2%
if 2.00000000000000003e263 < (*.f64 x x) Initial program 79.5%
cancel-sign-sub-inv79.5%
distribute-lft-neg-out79.5%
+-commutative79.5%
distribute-lft-neg-out79.5%
distribute-lft-neg-in79.5%
distribute-rgt-neg-in79.5%
fma-define80.8%
sub-neg80.8%
+-commutative80.8%
distribute-neg-in80.8%
remove-double-neg80.8%
sub-neg80.8%
Simplified80.8%
Taylor expanded in t around inf 94.9%
Final simplification94.4%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.9e+270) (+ (* 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 * x) <= 1.9e+270) {
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 (Float64(x * x) <= 1.9e+270) 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[N[(x * x), $MachinePrecision], 1.9e+270], 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 \cdot x \leq 1.9 \cdot 10^{+270}:\\
\;\;\;\;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 (*.f64 x x) < 1.90000000000000009e270Initial program 94.2%
if 1.90000000000000009e270 < (*.f64 x x) Initial program 79.5%
cancel-sign-sub-inv79.5%
distribute-lft-neg-out79.5%
+-commutative79.5%
distribute-lft-neg-out79.5%
distribute-lft-neg-in79.5%
distribute-rgt-neg-in79.5%
fma-define80.8%
sub-neg80.8%
+-commutative80.8%
distribute-neg-in80.8%
remove-double-neg80.8%
sub-neg80.8%
Simplified80.8%
Taylor expanded in t around inf 94.9%
Final simplification94.4%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 2.9e-10) (* t (* y (+ 4.0 (/ (* z -4.0) (/ t z))))) (- (* x x) (* -4.0 (* t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2.9e-10) {
tmp = t * (y * (4.0 + ((z * -4.0) / (t / z))));
} else {
tmp = (x * x) - (-4.0 * (t * y));
}
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) <= 2.9d-10) then
tmp = t * (y * (4.0d0 + ((z * (-4.0d0)) / (t / z))))
else
tmp = (x * x) - ((-4.0d0) * (t * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2.9e-10) {
tmp = t * (y * (4.0 + ((z * -4.0) / (t / z))));
} else {
tmp = (x * x) - (-4.0 * (t * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 2.9e-10: tmp = t * (y * (4.0 + ((z * -4.0) / (t / z)))) else: tmp = (x * x) - (-4.0 * (t * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 2.9e-10) tmp = Float64(t * Float64(y * Float64(4.0 + Float64(Float64(z * -4.0) / Float64(t / z))))); else tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 2.9e-10) tmp = t * (y * (4.0 + ((z * -4.0) / (t / z)))); else tmp = (x * x) - (-4.0 * (t * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.9e-10], N[(t * N[(y * N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.9 \cdot 10^{-10}:\\
\;\;\;\;t \cdot \left(y \cdot \left(4 + \frac{z \cdot -4}{\frac{t}{z}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.89999999999999981e-10Initial program 92.8%
Taylor expanded in t around inf 89.4%
+-commutative89.4%
fma-define89.4%
associate-/l*88.6%
*-commutative88.6%
Simplified88.6%
Taylor expanded in y around -inf 82.8%
add-sqr-sqrt40.9%
sqrt-prod51.8%
sqr-neg51.8%
sqrt-prod24.0%
add-sqr-sqrt45.2%
unpow245.2%
*-un-lft-identity45.2%
times-frac45.2%
add-sqr-sqrt24.0%
sqrt-prod55.4%
sqr-neg55.4%
sqrt-prod42.5%
add-sqr-sqrt85.9%
Applied egg-rr85.9%
/-rgt-identity85.9%
associate-*r*85.9%
clear-num85.9%
un-div-inv85.9%
Applied egg-rr85.9%
if 2.89999999999999981e-10 < (*.f64 x x) Initial program 87.3%
Taylor expanded in z around 0 81.8%
*-commutative81.8%
Simplified81.8%
Final simplification83.6%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.95e+270) (+ (* 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) <= 1.95e+270) {
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) <= 1.95d+270) 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) <= 1.95e+270) {
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) <= 1.95e+270: 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) <= 1.95e+270) 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) <= 1.95e+270) 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], 1.95e+270], 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 1.95 \cdot 10^{+270}:\\
\;\;\;\;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) < 1.95e270Initial program 94.2%
if 1.95e270 < (*.f64 x x) Initial program 79.5%
Taylor expanded in y around 0 79.5%
Simplified94.9%
Final simplification94.4%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 3.6e-11) (* y (* t 4.0)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 3.6e-11) {
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 * x) <= 3.6d-11) 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 * x) <= 3.6e-11) {
tmp = y * (t * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 3.6e-11: tmp = y * (t * 4.0) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 3.6e-11) 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 * x) <= 3.6e-11) tmp = y * (t * 4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 3.6e-11], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3.6 \cdot 10^{-11}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.59999999999999985e-11Initial program 92.7%
Taylor expanded in t around inf 49.3%
associate-*r*49.3%
Simplified49.3%
if 3.59999999999999985e-11 < (*.f64 x x) Initial program 87.4%
Taylor expanded in y around 0 87.4%
Simplified74.3%
Final simplification63.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 89.7%
Taylor expanded in z around 0 69.7%
*-commutative69.7%
Simplified69.7%
Final simplification69.7%
(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 89.7%
sub-neg89.7%
flip-+58.0%
pow258.0%
pow258.0%
pow-prod-up58.0%
metadata-eval58.0%
pow258.0%
Applied egg-rr58.0%
clear-num57.9%
un-div-inv57.9%
clear-num57.9%
metadata-eval57.9%
pow-prod-up57.9%
flip-+89.6%
unpow289.6%
fma-define89.6%
add-sqr-sqrt42.2%
sqrt-prod72.7%
sqr-neg72.7%
sqrt-prod36.4%
add-sqr-sqrt66.4%
Applied egg-rr66.4%
Taylor expanded in t around inf 5.5%
*-commutative5.5%
Simplified5.5%
Final simplification5.5%
(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 89.7%
Taylor expanded in t around inf 29.2%
associate-*r*29.2%
Simplified29.2%
Final simplification29.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 2024081
(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))))