
(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}
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 7.6e+195) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (* z (* z (* y 4.0))))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 7.6e+195) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (z <= 7.6e+195) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 7.6e+195], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.6 \cdot 10^{+195}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if z < 7.6e195Initial program 94.0%
fma-neg96.2%
distribute-lft-neg-in96.2%
*-commutative96.2%
distribute-rgt-neg-in96.2%
metadata-eval96.2%
Simplified96.2%
if 7.6e195 < z Initial program 77.7%
add-cube-cbrt77.7%
pow377.7%
pow277.7%
Applied egg-rr77.7%
Taylor expanded in t around 0 77.7%
unpow1/377.7%
Simplified77.7%
remove-double-div77.7%
rem-cube-cbrt77.7%
associate-*l/77.7%
*-un-lft-identity77.7%
*-commutative77.7%
associate-/r*77.7%
metadata-eval77.7%
Applied egg-rr77.7%
pow277.7%
clear-num77.7%
associate-/r/77.7%
clear-num77.7%
div-inv77.7%
metadata-eval77.7%
associate-*r*86.4%
Applied egg-rr86.4%
Final simplification95.3%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= (* z z) 1.6e+21) (- (* x x) (* y (* t -4.0))) (- (* x x) (* (* z z) (* y 4.0)))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1.6e+21) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - ((z * z) * (y * 4.0));
}
return tmp;
}
NOTE: z should be positive before calling this function
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.6d+21) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (x * x) - ((z * z) * (y * 4.0d0))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1.6e+21) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - ((z * z) * (y * 4.0));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if (z * z) <= 1.6e+21: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (x * x) - ((z * z) * (y * 4.0)) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1.6e+21) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(x * x) - Float64(Float64(z * z) * Float64(y * 4.0))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1.6e+21) tmp = (x * x) - (y * (t * -4.0)); else tmp = (x * x) - ((z * z) * (y * 4.0)); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1.6e+21], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * z), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 1.6 \cdot 10^{+21}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.6e21Initial program 99.1%
Taylor expanded in z around 0 92.0%
*-commutative92.0%
*-commutative92.0%
associate-*l*92.0%
Simplified92.0%
if 1.6e21 < (*.f64 z z) Initial program 86.8%
add-cube-cbrt86.5%
pow386.6%
pow286.6%
Applied egg-rr86.6%
Taylor expanded in t around 0 81.5%
unpow1/382.3%
Simplified82.3%
rem-cube-cbrt82.5%
unpow282.5%
Applied egg-rr82.5%
Final simplification87.0%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+20) (- (* x x) (* y (* t -4.0))) (- (* x x) (* z (* z (* y 4.0))))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+20) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
NOTE: z should be positive before calling this function
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) <= 1d+20) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (x * x) - (z * (z * (y * 4.0d0)))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+20) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if (z * z) <= 1e+20: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (x * x) - (z * (z * (y * 4.0))) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+20) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1e+20) tmp = (x * x) - (y * (t * -4.0)); else tmp = (x * x) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+20], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+20}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e20Initial program 99.1%
Taylor expanded in z around 0 92.0%
*-commutative92.0%
*-commutative92.0%
associate-*l*92.0%
Simplified92.0%
if 1e20 < (*.f64 z z) Initial program 86.8%
add-cube-cbrt86.5%
pow386.6%
pow286.6%
Applied egg-rr86.6%
Taylor expanded in t around 0 81.5%
unpow1/382.3%
Simplified82.3%
remove-double-div82.3%
rem-cube-cbrt82.5%
associate-*l/82.5%
*-un-lft-identity82.5%
*-commutative82.5%
associate-/r*82.5%
metadata-eval82.5%
Applied egg-rr82.5%
pow282.5%
clear-num82.5%
associate-/r/82.5%
clear-num82.5%
div-inv82.5%
metadata-eval82.5%
associate-*r*89.0%
Applied egg-rr89.0%
Final simplification90.4%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 1.45e+104) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* z (* z (* y 4.0))))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+104) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
NOTE: z should be positive before calling this function
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 <= 1.45d+104) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (z * (z * (y * 4.0d0)))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+104) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if z <= 1.45e+104: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (z * (z * (y * 4.0))) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (z <= 1.45e+104) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.45e+104) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 1.45e+104], 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[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+104}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if z < 1.4499999999999999e104Initial program 95.3%
if 1.4499999999999999e104 < z Initial program 80.1%
add-cube-cbrt80.0%
pow380.0%
pow280.0%
Applied egg-rr80.0%
Taylor expanded in t around 0 79.6%
unpow1/380.0%
Simplified80.0%
remove-double-div80.0%
rem-cube-cbrt80.1%
associate-*l/80.2%
*-un-lft-identity80.2%
*-commutative80.2%
associate-/r*80.2%
metadata-eval80.2%
Applied egg-rr80.2%
pow280.2%
clear-num80.2%
associate-/r/80.1%
clear-num80.1%
div-inv80.1%
metadata-eval80.1%
associate-*r*86.6%
Applied egg-rr86.6%
Final simplification93.8%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (- (* x x) (* y (* t -4.0))))
z = abs(z);
double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
NOTE: z should be positive before calling this function
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
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
z = abs(z) def code(x, y, z, t): return (x * x) - (y * (t * -4.0))
z = abs(z) function code(x, y, z, t) return Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))) end
z = abs(z) function tmp = code(x, y, z, t) tmp = (x * x) - (y * (t * -4.0)); end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z = |z|\\
\\
x \cdot x - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 92.6%
Taylor expanded in z around 0 67.8%
*-commutative67.8%
*-commutative67.8%
associate-*l*67.8%
Simplified67.8%
Final simplification67.8%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
z = abs(z);
double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
NOTE: z should be positive before calling this function
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
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
z = abs(z) def code(x, y, z, t): return 4.0 * (t * y)
z = abs(z) function code(x, y, z, t) return Float64(4.0 * Float64(t * y)) end
z = abs(z) function tmp = code(x, y, z, t) tmp = 4.0 * (t * y); end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z = |z|\\
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 92.6%
Taylor expanded in t around inf 26.4%
*-commutative26.4%
Simplified26.4%
Final simplification26.4%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (* y (* t 4.0)))
z = abs(z);
double code(double x, double y, double z, double t) {
return y * (t * 4.0);
}
NOTE: z should be positive before calling this function
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
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
return y * (t * 4.0);
}
z = abs(z) def code(x, y, z, t): return y * (t * 4.0)
z = abs(z) function code(x, y, z, t) return Float64(y * Float64(t * 4.0)) end
z = abs(z) function tmp = code(x, y, z, t) tmp = y * (t * 4.0); end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z = |z|\\
\\
y \cdot \left(t \cdot 4\right)
\end{array}
Initial program 92.6%
Taylor expanded in t around inf 26.4%
associate-*r*26.8%
*-commutative26.8%
Simplified26.8%
Final simplification26.8%
(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 2023306
(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))))