
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= (* z z) 2e-136)
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0))
(if (<= (* z z) 1e+304)
(*
0.5
(*
(pow z 2.0)
(+ (/ y (pow z 2.0)) (fma (/ x y) (/ x (pow z 2.0)) (/ -1.0 y)))))
(* 0.5 (* (fma x (* (/ 1.0 z) (/ x z)) -1.0) (* z (* z (/ 1.0 y))))))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2e-136) {
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
} else if ((z * z) <= 1e+304) {
tmp = 0.5 * (pow(z, 2.0) * ((y / pow(z, 2.0)) + fma((x / y), (x / pow(z, 2.0)), (-1.0 / y))));
} else {
tmp = 0.5 * (fma(x, ((1.0 / z) * (x / z)), -1.0) * (z * (z * (1.0 / y))));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 2e-136) tmp = Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)); elseif (Float64(z * z) <= 1e+304) tmp = Float64(0.5 * Float64((z ^ 2.0) * Float64(Float64(y / (z ^ 2.0)) + fma(Float64(x / y), Float64(x / (z ^ 2.0)), Float64(-1.0 / y))))); else tmp = Float64(0.5 * Float64(fma(x, Float64(Float64(1.0 / z) * Float64(x / z)), -1.0) * Float64(z * Float64(z * Float64(1.0 / y))))); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e-136], N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+304], N[(0.5 * N[(N[Power[z, 2.0], $MachinePrecision] * N[(N[(y / N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x / y), $MachinePrecision] * N[(x / N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x * N[(N[(1.0 / z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * N[(z * N[(z * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-136}:\\
\;\;\;\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\
\mathbf{elif}\;z \cdot z \leq 10^{+304}:\\
\;\;\;\;0.5 \cdot \left({z}^{2} \cdot \left(\frac{y}{{z}^{2}} + \mathsf{fma}\left(\frac{x}{y}, \frac{x}{{z}^{2}}, \frac{-1}{y}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\mathsf{fma}\left(x, \frac{1}{z} \cdot \frac{x}{z}, -1\right) \cdot \left(z \cdot \left(z \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2e-136Initial program 79.2%
if 2e-136 < (*.f64 z z) < 9.9999999999999994e303Initial program 75.0%
remove-double-neg75.0%
distribute-lft-neg-out75.0%
distribute-frac-neg275.0%
distribute-frac-neg75.0%
neg-mul-175.0%
distribute-lft-neg-out75.0%
*-commutative75.0%
distribute-lft-neg-in75.0%
times-frac75.0%
metadata-eval75.0%
metadata-eval75.0%
associate--l+75.0%
fma-define75.0%
Simplified75.0%
Taylor expanded in z around inf 87.8%
associate--l+87.8%
unpow287.8%
times-frac98.8%
fmm-def98.8%
distribute-neg-frac98.8%
metadata-eval98.8%
Simplified98.8%
if 9.9999999999999994e303 < (*.f64 z z) Initial program 57.2%
remove-double-neg57.2%
distribute-lft-neg-out57.2%
distribute-frac-neg257.2%
distribute-frac-neg57.2%
neg-mul-157.2%
distribute-lft-neg-out57.2%
*-commutative57.2%
distribute-lft-neg-in57.2%
times-frac57.2%
metadata-eval57.2%
metadata-eval57.2%
associate--l+57.2%
fma-define61.8%
Simplified61.8%
Taylor expanded in z around inf 65.2%
associate--l+65.2%
unpow265.2%
times-frac66.7%
fmm-def66.7%
distribute-neg-frac66.7%
metadata-eval66.7%
Simplified66.7%
Taylor expanded in y around 0 65.2%
*-commutative65.2%
associate-/l*65.2%
unpow265.2%
associate-/l*69.8%
fmm-def69.8%
metadata-eval69.8%
Simplified69.8%
div-inv69.8%
pow269.8%
associate-*l*74.2%
Applied egg-rr74.2%
*-un-lft-identity74.2%
pow274.2%
times-frac89.5%
Applied egg-rr89.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ 1.0 z) (/ x z))))
(if (<= (* z z) 2e-136)
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0))
(if (<= (* z z) 1e+304)
(*
0.5
(* (pow z 2.0) (+ (/ y (pow z 2.0)) (fma (/ x y) t_0 (/ -1.0 y)))))
(* 0.5 (* (fma x t_0 -1.0) (* z (* z (/ 1.0 y)))))))))
double code(double x, double y, double z) {
double t_0 = (1.0 / z) * (x / z);
double tmp;
if ((z * z) <= 2e-136) {
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
} else if ((z * z) <= 1e+304) {
tmp = 0.5 * (pow(z, 2.0) * ((y / pow(z, 2.0)) + fma((x / y), t_0, (-1.0 / y))));
} else {
tmp = 0.5 * (fma(x, t_0, -1.0) * (z * (z * (1.0 / y))));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(1.0 / z) * Float64(x / z)) tmp = 0.0 if (Float64(z * z) <= 2e-136) tmp = Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)); elseif (Float64(z * z) <= 1e+304) tmp = Float64(0.5 * Float64((z ^ 2.0) * Float64(Float64(y / (z ^ 2.0)) + fma(Float64(x / y), t_0, Float64(-1.0 / y))))); else tmp = Float64(0.5 * Float64(fma(x, t_0, -1.0) * Float64(z * Float64(z * Float64(1.0 / y))))); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 / z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * z), $MachinePrecision], 2e-136], N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+304], N[(0.5 * N[(N[Power[z, 2.0], $MachinePrecision] * N[(N[(y / N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x / y), $MachinePrecision] * t$95$0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x * t$95$0 + -1.0), $MachinePrecision] * N[(z * N[(z * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{z} \cdot \frac{x}{z}\\
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-136}:\\
\;\;\;\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\
\mathbf{elif}\;z \cdot z \leq 10^{+304}:\\
\;\;\;\;0.5 \cdot \left({z}^{2} \cdot \left(\frac{y}{{z}^{2}} + \mathsf{fma}\left(\frac{x}{y}, t\_0, \frac{-1}{y}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\mathsf{fma}\left(x, t\_0, -1\right) \cdot \left(z \cdot \left(z \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2e-136Initial program 79.2%
if 2e-136 < (*.f64 z z) < 9.9999999999999994e303Initial program 75.0%
remove-double-neg75.0%
distribute-lft-neg-out75.0%
distribute-frac-neg275.0%
distribute-frac-neg75.0%
neg-mul-175.0%
distribute-lft-neg-out75.0%
*-commutative75.0%
distribute-lft-neg-in75.0%
times-frac75.0%
metadata-eval75.0%
metadata-eval75.0%
associate--l+75.0%
fma-define75.0%
Simplified75.0%
Taylor expanded in z around inf 87.8%
associate--l+87.8%
unpow287.8%
times-frac98.8%
fmm-def98.8%
distribute-neg-frac98.8%
metadata-eval98.8%
Simplified98.8%
*-un-lft-identity69.0%
pow269.0%
times-frac69.0%
Applied egg-rr98.8%
if 9.9999999999999994e303 < (*.f64 z z) Initial program 57.2%
remove-double-neg57.2%
distribute-lft-neg-out57.2%
distribute-frac-neg257.2%
distribute-frac-neg57.2%
neg-mul-157.2%
distribute-lft-neg-out57.2%
*-commutative57.2%
distribute-lft-neg-in57.2%
times-frac57.2%
metadata-eval57.2%
metadata-eval57.2%
associate--l+57.2%
fma-define61.8%
Simplified61.8%
Taylor expanded in z around inf 65.2%
associate--l+65.2%
unpow265.2%
times-frac66.7%
fmm-def66.7%
distribute-neg-frac66.7%
metadata-eval66.7%
Simplified66.7%
Taylor expanded in y around 0 65.2%
*-commutative65.2%
associate-/l*65.2%
unpow265.2%
associate-/l*69.8%
fmm-def69.8%
metadata-eval69.8%
Simplified69.8%
div-inv69.8%
pow269.8%
associate-*l*74.2%
Applied egg-rr74.2%
*-un-lft-identity74.2%
pow274.2%
times-frac89.5%
Applied egg-rr89.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ 1.0 z) (/ x z))))
(if (<= z 1e-64)
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0))
(if (<= z 2.2e+161)
(*
0.5
(* (pow z 2.0) (+ (fma (/ x y) t_0 (/ -1.0 y)) (* (/ 1.0 z) (/ y z)))))
(* 0.5 (* (fma x t_0 -1.0) (* z (* z (/ 1.0 y)))))))))
double code(double x, double y, double z) {
double t_0 = (1.0 / z) * (x / z);
double tmp;
if (z <= 1e-64) {
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
} else if (z <= 2.2e+161) {
tmp = 0.5 * (pow(z, 2.0) * (fma((x / y), t_0, (-1.0 / y)) + ((1.0 / z) * (y / z))));
} else {
tmp = 0.5 * (fma(x, t_0, -1.0) * (z * (z * (1.0 / y))));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(1.0 / z) * Float64(x / z)) tmp = 0.0 if (z <= 1e-64) tmp = Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)); elseif (z <= 2.2e+161) tmp = Float64(0.5 * Float64((z ^ 2.0) * Float64(fma(Float64(x / y), t_0, Float64(-1.0 / y)) + Float64(Float64(1.0 / z) * Float64(y / z))))); else tmp = Float64(0.5 * Float64(fma(x, t_0, -1.0) * Float64(z * Float64(z * Float64(1.0 / y))))); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 / z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 1e-64], N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.2e+161], N[(0.5 * N[(N[Power[z, 2.0], $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] * t$95$0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / z), $MachinePrecision] * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x * t$95$0 + -1.0), $MachinePrecision] * N[(z * N[(z * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{z} \cdot \frac{x}{z}\\
\mathbf{if}\;z \leq 10^{-64}:\\
\;\;\;\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+161}:\\
\;\;\;\;0.5 \cdot \left({z}^{2} \cdot \left(\mathsf{fma}\left(\frac{x}{y}, t\_0, \frac{-1}{y}\right) + \frac{1}{z} \cdot \frac{y}{z}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\mathsf{fma}\left(x, t\_0, -1\right) \cdot \left(z \cdot \left(z \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if z < 9.99999999999999965e-65Initial program 71.9%
if 9.99999999999999965e-65 < z < 2.2e161Initial program 76.3%
remove-double-neg76.3%
distribute-lft-neg-out76.3%
distribute-frac-neg276.3%
distribute-frac-neg76.3%
neg-mul-176.3%
distribute-lft-neg-out76.3%
*-commutative76.3%
distribute-lft-neg-in76.3%
times-frac76.3%
metadata-eval76.3%
metadata-eval76.3%
associate--l+76.3%
fma-define76.3%
Simplified76.3%
Taylor expanded in z around inf 87.4%
associate--l+87.4%
unpow287.4%
times-frac97.8%
fmm-def97.8%
distribute-neg-frac97.8%
metadata-eval97.8%
Simplified97.8%
*-un-lft-identity74.1%
pow274.1%
times-frac74.1%
Applied egg-rr97.8%
*-un-lft-identity97.8%
pow297.8%
times-frac97.7%
Applied egg-rr97.7%
if 2.2e161 < z Initial program 67.1%
remove-double-neg67.1%
distribute-lft-neg-out67.1%
distribute-frac-neg267.1%
distribute-frac-neg67.1%
neg-mul-167.1%
distribute-lft-neg-out67.1%
*-commutative67.1%
distribute-lft-neg-in67.1%
times-frac67.1%
metadata-eval67.1%
metadata-eval67.1%
associate--l+67.1%
fma-define69.9%
Simplified69.9%
Taylor expanded in z around inf 72.7%
associate--l+72.7%
unpow272.7%
times-frac69.9%
fmm-def69.9%
distribute-neg-frac69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in y around 0 72.7%
*-commutative72.7%
associate-/l*72.7%
unpow272.7%
associate-/l*75.5%
fmm-def75.5%
metadata-eval75.5%
Simplified75.5%
div-inv75.5%
pow275.5%
associate-*l*80.5%
Applied egg-rr80.5%
*-un-lft-identity80.5%
pow280.5%
times-frac94.4%
Applied egg-rr94.4%
Final simplification79.8%
(FPCore (x y z)
:precision binary64
(if (<= y 8.6e-241)
(* 0.5 (* (fma x (* (/ 1.0 z) (/ x z)) -1.0) (* z (* z (/ 1.0 y)))))
(if (<= y 1.35e+154)
(* 0.5 (/ (fma x x (- (* y y) (* z z))) y))
(* y 0.5))))
double code(double x, double y, double z) {
double tmp;
if (y <= 8.6e-241) {
tmp = 0.5 * (fma(x, ((1.0 / z) * (x / z)), -1.0) * (z * (z * (1.0 / y))));
} else if (y <= 1.35e+154) {
tmp = 0.5 * (fma(x, x, ((y * y) - (z * z))) / y);
} else {
tmp = y * 0.5;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 8.6e-241) tmp = Float64(0.5 * Float64(fma(x, Float64(Float64(1.0 / z) * Float64(x / z)), -1.0) * Float64(z * Float64(z * Float64(1.0 / y))))); elseif (y <= 1.35e+154) tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y * y) - Float64(z * z))) / y)); else tmp = Float64(y * 0.5); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 8.6e-241], N[(0.5 * N[(N[(x * N[(N[(1.0 / z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * N[(z * N[(z * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e+154], N[(0.5 * N[(N[(x * x + N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.6 \cdot 10^{-241}:\\
\;\;\;\;0.5 \cdot \left(\mathsf{fma}\left(x, \frac{1}{z} \cdot \frac{x}{z}, -1\right) \cdot \left(z \cdot \left(z \cdot \frac{1}{y}\right)\right)\right)\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 8.5999999999999997e-241Initial program 74.8%
remove-double-neg74.8%
distribute-lft-neg-out74.8%
distribute-frac-neg274.8%
distribute-frac-neg74.8%
neg-mul-174.8%
distribute-lft-neg-out74.8%
*-commutative74.8%
distribute-lft-neg-in74.8%
times-frac74.8%
metadata-eval74.8%
metadata-eval74.8%
associate--l+74.8%
fma-define75.6%
Simplified75.6%
Taylor expanded in z around inf 55.5%
associate--l+55.5%
unpow255.5%
times-frac61.1%
fmm-def61.1%
distribute-neg-frac61.1%
metadata-eval61.1%
Simplified61.1%
Taylor expanded in y around 0 50.1%
*-commutative50.1%
associate-/l*50.1%
unpow250.1%
associate-/l*51.7%
fmm-def51.7%
metadata-eval51.7%
Simplified51.7%
div-inv51.7%
pow251.7%
associate-*l*55.7%
Applied egg-rr55.7%
*-un-lft-identity55.7%
pow255.7%
times-frac64.5%
Applied egg-rr64.5%
if 8.5999999999999997e-241 < y < 1.35000000000000003e154Initial program 91.7%
remove-double-neg91.7%
distribute-lft-neg-out91.7%
distribute-frac-neg291.7%
distribute-frac-neg91.7%
neg-mul-191.7%
distribute-lft-neg-out91.7%
*-commutative91.7%
distribute-lft-neg-in91.7%
times-frac91.7%
metadata-eval91.7%
metadata-eval91.7%
associate--l+91.7%
fma-define93.8%
Simplified93.8%
if 1.35000000000000003e154 < y Initial program 14.8%
remove-double-neg14.8%
distribute-lft-neg-out14.8%
distribute-frac-neg214.8%
distribute-frac-neg14.8%
neg-mul-114.8%
distribute-lft-neg-out14.8%
*-commutative14.8%
distribute-lft-neg-in14.8%
times-frac14.8%
metadata-eval14.8%
metadata-eval14.8%
associate--l+14.8%
fma-define14.8%
Simplified14.8%
Taylor expanded in y around inf 64.3%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e+154) (* 0.5 (/ (fma x x (- (* y y) (* z z))) y)) (* y 0.5)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = 0.5 * (fma(x, x, ((y * y) - (z * z))) / y);
} else {
tmp = y * 0.5;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 1.35e+154) tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y * y) - Float64(z * z))) / y)); else tmp = Float64(y * 0.5); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+154], N[(0.5 * N[(N[(x * x + N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.35000000000000003e154Initial program 82.0%
remove-double-neg82.0%
distribute-lft-neg-out82.0%
distribute-frac-neg282.0%
distribute-frac-neg82.0%
neg-mul-182.0%
distribute-lft-neg-out82.0%
*-commutative82.0%
distribute-lft-neg-in82.0%
times-frac82.0%
metadata-eval82.0%
metadata-eval82.0%
associate--l+82.0%
fma-define83.4%
Simplified83.4%
if 1.35000000000000003e154 < y Initial program 14.8%
remove-double-neg14.8%
distribute-lft-neg-out14.8%
distribute-frac-neg214.8%
distribute-frac-neg14.8%
neg-mul-114.8%
distribute-lft-neg-out14.8%
*-commutative14.8%
distribute-lft-neg-in14.8%
times-frac14.8%
metadata-eval14.8%
metadata-eval14.8%
associate--l+14.8%
fma-define14.8%
Simplified14.8%
Taylor expanded in y around inf 64.3%
Final simplification80.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 0.5 (* z (* z (/ -1.0 y))))))
(if (<= x 3.5e-277)
t_0
(if (<= x 5.2e-167)
(* y 0.5)
(if (<= x 3.3e+72) t_0 (* x (* x (/ 0.5 y))))))))
double code(double x, double y, double z) {
double t_0 = 0.5 * (z * (z * (-1.0 / y)));
double tmp;
if (x <= 3.5e-277) {
tmp = t_0;
} else if (x <= 5.2e-167) {
tmp = y * 0.5;
} else if (x <= 3.3e+72) {
tmp = t_0;
} else {
tmp = x * (x * (0.5 / y));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (z * (z * ((-1.0d0) / y)))
if (x <= 3.5d-277) then
tmp = t_0
else if (x <= 5.2d-167) then
tmp = y * 0.5d0
else if (x <= 3.3d+72) then
tmp = t_0
else
tmp = x * (x * (0.5d0 / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 0.5 * (z * (z * (-1.0 / y)));
double tmp;
if (x <= 3.5e-277) {
tmp = t_0;
} else if (x <= 5.2e-167) {
tmp = y * 0.5;
} else if (x <= 3.3e+72) {
tmp = t_0;
} else {
tmp = x * (x * (0.5 / y));
}
return tmp;
}
def code(x, y, z): t_0 = 0.5 * (z * (z * (-1.0 / y))) tmp = 0 if x <= 3.5e-277: tmp = t_0 elif x <= 5.2e-167: tmp = y * 0.5 elif x <= 3.3e+72: tmp = t_0 else: tmp = x * (x * (0.5 / y)) return tmp
function code(x, y, z) t_0 = Float64(0.5 * Float64(z * Float64(z * Float64(-1.0 / y)))) tmp = 0.0 if (x <= 3.5e-277) tmp = t_0; elseif (x <= 5.2e-167) tmp = Float64(y * 0.5); elseif (x <= 3.3e+72) tmp = t_0; else tmp = Float64(x * Float64(x * Float64(0.5 / y))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 0.5 * (z * (z * (-1.0 / y))); tmp = 0.0; if (x <= 3.5e-277) tmp = t_0; elseif (x <= 5.2e-167) tmp = y * 0.5; elseif (x <= 3.3e+72) tmp = t_0; else tmp = x * (x * (0.5 / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.5 * N[(z * N[(z * N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 3.5e-277], t$95$0, If[LessEqual[x, 5.2e-167], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 3.3e+72], t$95$0, N[(x * N[(x * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(z \cdot \left(z \cdot \frac{-1}{y}\right)\right)\\
\mathbf{if}\;x \leq 3.5 \cdot 10^{-277}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-167}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\
\end{array}
\end{array}
if x < 3.49999999999999983e-277 or 5.1999999999999998e-167 < x < 3.3e72Initial program 72.7%
remove-double-neg72.7%
distribute-lft-neg-out72.7%
distribute-frac-neg272.7%
distribute-frac-neg72.7%
neg-mul-172.7%
distribute-lft-neg-out72.7%
*-commutative72.7%
distribute-lft-neg-in72.7%
times-frac72.7%
metadata-eval72.7%
metadata-eval72.7%
associate--l+72.7%
fma-define73.7%
Simplified73.7%
Taylor expanded in z around inf 57.6%
associate--l+57.6%
unpow257.6%
times-frac61.5%
fmm-def61.5%
distribute-neg-frac61.5%
metadata-eval61.5%
Simplified61.5%
Taylor expanded in y around 0 49.5%
*-commutative49.5%
associate-/l*49.4%
unpow249.4%
associate-/l*50.4%
fmm-def50.4%
metadata-eval50.4%
Simplified50.4%
div-inv50.4%
pow250.4%
associate-*l*54.0%
Applied egg-rr54.0%
Taylor expanded in x around 0 40.7%
if 3.49999999999999983e-277 < x < 5.1999999999999998e-167Initial program 76.2%
remove-double-neg76.2%
distribute-lft-neg-out76.2%
distribute-frac-neg276.2%
distribute-frac-neg76.2%
neg-mul-176.2%
distribute-lft-neg-out76.2%
*-commutative76.2%
distribute-lft-neg-in76.2%
times-frac76.2%
metadata-eval76.2%
metadata-eval76.2%
associate--l+76.2%
fma-define76.2%
Simplified76.2%
Taylor expanded in y around inf 63.3%
if 3.3e72 < x Initial program 66.5%
remove-double-neg66.5%
distribute-lft-neg-out66.5%
distribute-frac-neg266.5%
distribute-frac-neg66.5%
neg-mul-166.5%
distribute-lft-neg-out66.5%
*-commutative66.5%
distribute-lft-neg-in66.5%
times-frac66.5%
metadata-eval66.5%
metadata-eval66.5%
associate--l+66.5%
fma-define69.2%
Simplified69.2%
Taylor expanded in x around inf 71.7%
*-commutative71.7%
associate-*l/71.7%
associate-*r/71.7%
Simplified71.7%
pow271.7%
associate-*r/71.7%
clear-num71.8%
pow271.8%
Applied egg-rr71.8%
pow271.8%
clear-num71.7%
associate-*r/71.7%
*-commutative71.7%
associate-*r*83.1%
Applied egg-rr83.1%
Final simplification48.3%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e+154) (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)) (* y 0.5)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 1.35d+154) then
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.35e+154: tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0) else: tmp = y * 0.5 return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.35e+154) tmp = Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.35e+154) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+154], N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.35000000000000003e154Initial program 82.0%
if 1.35000000000000003e154 < y Initial program 14.8%
remove-double-neg14.8%
distribute-lft-neg-out14.8%
distribute-frac-neg214.8%
distribute-frac-neg14.8%
neg-mul-114.8%
distribute-lft-neg-out14.8%
*-commutative14.8%
distribute-lft-neg-in14.8%
times-frac14.8%
metadata-eval14.8%
metadata-eval14.8%
associate--l+14.8%
fma-define14.8%
Simplified14.8%
Taylor expanded in y around inf 64.3%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= (* x x) 1e+112) (* y 0.5) (* x (/ x (* y 2.0)))))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1e+112) {
tmp = y * 0.5;
} else {
tmp = x * (x / (y * 2.0));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * x) <= 1d+112) then
tmp = y * 0.5d0
else
tmp = x * (x / (y * 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1e+112) {
tmp = y * 0.5;
} else {
tmp = x * (x / (y * 2.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 1e+112: tmp = y * 0.5 else: tmp = x * (x / (y * 2.0)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1e+112) tmp = Float64(y * 0.5); else tmp = Float64(x * Float64(x / Float64(y * 2.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 1e+112) tmp = y * 0.5; else tmp = x * (x / (y * 2.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e+112], N[(y * 0.5), $MachinePrecision], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{+112}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\
\end{array}
\end{array}
if (*.f64 x x) < 9.9999999999999993e111Initial program 74.6%
remove-double-neg74.6%
distribute-lft-neg-out74.6%
distribute-frac-neg274.6%
distribute-frac-neg74.6%
neg-mul-174.6%
distribute-lft-neg-out74.6%
*-commutative74.6%
distribute-lft-neg-in74.6%
times-frac74.6%
metadata-eval74.6%
metadata-eval74.6%
associate--l+74.6%
fma-define74.6%
Simplified74.6%
Taylor expanded in y around inf 43.2%
if 9.9999999999999993e111 < (*.f64 x x) Initial program 67.8%
remove-double-neg67.8%
distribute-lft-neg-out67.8%
distribute-frac-neg267.8%
distribute-frac-neg67.8%
neg-mul-167.8%
distribute-lft-neg-out67.8%
*-commutative67.8%
distribute-lft-neg-in67.8%
times-frac67.8%
metadata-eval67.8%
metadata-eval67.8%
associate--l+67.8%
fma-define70.8%
Simplified70.8%
Taylor expanded in x around inf 67.4%
*-commutative67.4%
associate-*l/67.4%
associate-*r/67.4%
Simplified67.4%
pow267.4%
associate-*r/67.4%
clear-num67.4%
pow267.4%
Applied egg-rr67.4%
pow267.4%
clear-num67.4%
associate-*r/67.4%
associate-*l*74.3%
clear-num74.3%
div-inv74.3%
metadata-eval74.3%
add-sqr-sqrt40.1%
pow240.1%
add-cbrt-cube37.4%
add-sqr-sqrt37.4%
cbrt-unprod40.0%
un-div-inv40.0%
cbrt-unprod37.4%
add-sqr-sqrt37.3%
add-cbrt-cube40.1%
Applied egg-rr74.3%
Final simplification55.1%
(FPCore (x y z) :precision binary64 (if (<= x 2e+56) (* y 0.5) (* x (* x (/ 0.5 y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2e+56) {
tmp = y * 0.5;
} else {
tmp = x * (x * (0.5 / y));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= 2d+56) then
tmp = y * 0.5d0
else
tmp = x * (x * (0.5d0 / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2e+56) {
tmp = y * 0.5;
} else {
tmp = x * (x * (0.5 / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2e+56: tmp = y * 0.5 else: tmp = x * (x * (0.5 / y)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2e+56) tmp = Float64(y * 0.5); else tmp = Float64(x * Float64(x * Float64(0.5 / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2e+56) tmp = y * 0.5; else tmp = x * (x * (0.5 / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2e+56], N[(y * 0.5), $MachinePrecision], N[(x * N[(x * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+56}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\
\end{array}
\end{array}
if x < 2.00000000000000018e56Initial program 72.6%
remove-double-neg72.6%
distribute-lft-neg-out72.6%
distribute-frac-neg272.6%
distribute-frac-neg72.6%
neg-mul-172.6%
distribute-lft-neg-out72.6%
*-commutative72.6%
distribute-lft-neg-in72.6%
times-frac72.6%
metadata-eval72.6%
metadata-eval72.6%
associate--l+72.6%
fma-define73.5%
Simplified73.5%
Taylor expanded in y around inf 36.5%
if 2.00000000000000018e56 < x Initial program 69.0%
remove-double-neg69.0%
distribute-lft-neg-out69.0%
distribute-frac-neg269.0%
distribute-frac-neg69.0%
neg-mul-169.0%
distribute-lft-neg-out69.0%
*-commutative69.0%
distribute-lft-neg-in69.0%
times-frac69.0%
metadata-eval69.0%
metadata-eval69.0%
associate--l+69.0%
fma-define71.5%
Simplified71.5%
Taylor expanded in x around inf 71.4%
*-commutative71.4%
associate-*l/71.4%
associate-*r/71.3%
Simplified71.3%
pow271.3%
associate-*r/71.4%
clear-num71.4%
pow271.4%
Applied egg-rr71.4%
pow271.4%
clear-num71.4%
associate-*r/71.3%
*-commutative71.3%
associate-*r*81.9%
Applied egg-rr81.9%
Final simplification43.6%
(FPCore (x y z) :precision binary64 (* y 0.5))
double code(double x, double y, double z) {
return y * 0.5;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * 0.5d0
end function
public static double code(double x, double y, double z) {
return y * 0.5;
}
def code(x, y, z): return y * 0.5
function code(x, y, z) return Float64(y * 0.5) end
function tmp = code(x, y, z) tmp = y * 0.5; end
code[x_, y_, z_] := N[(y * 0.5), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5
\end{array}
Initial program 72.0%
remove-double-neg72.0%
distribute-lft-neg-out72.0%
distribute-frac-neg272.0%
distribute-frac-neg72.0%
neg-mul-172.0%
distribute-lft-neg-out72.0%
*-commutative72.0%
distribute-lft-neg-in72.0%
times-frac72.0%
metadata-eval72.0%
metadata-eval72.0%
associate--l+72.0%
fma-define73.2%
Simplified73.2%
Taylor expanded in y around inf 32.5%
Final simplification32.5%
(FPCore (x y z) :precision binary64 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z): return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z) return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x))) end
function tmp = code(x, y, z) tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x)); end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}
herbie shell --seed 2024157
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:alt
(! :herbie-platform default (- (* y 1/2) (* (* (/ 1/2 y) (+ z x)) (- z x))))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))