
(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 6 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 (* 0.5 (+ y (* (+ x z) (/ (- x z) y)))))
double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) * ((x - z) / y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * (y + ((x + z) * ((x - z) / y)))
end function
public static double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) * ((x - z) / y)));
}
def code(x, y, z): return 0.5 * (y + ((x + z) * ((x - z) / y)))
function code(x, y, z) return Float64(0.5 * Float64(y + Float64(Float64(x + z) * Float64(Float64(x - z) / y)))) end
function tmp = code(x, y, z) tmp = 0.5 * (y + ((x + z) * ((x - z) / y))); end
code[x_, y_, z_] := N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(y + \left(x + z\right) \cdot \frac{x - z}{y}\right)
\end{array}
Initial program 71.5%
Taylor expanded in y around 0 86.7%
distribute-lft-out86.7%
Simplified86.7%
unpow286.7%
unpow286.7%
difference-of-squares90.0%
Applied egg-rr90.0%
div-inv89.9%
associate-*l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.4%
+-commutative98.4%
mul-1-neg98.4%
sub-neg98.4%
div-sub99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y 6.6e+108) (and (not (<= y 7.8e+150)) (<= y 3.2e+166))) (* 0.5 (* (+ x z) (/ (- x z) y))) (* 0.5 y)))
double code(double x, double y, double z) {
double tmp;
if ((y <= 6.6e+108) || (!(y <= 7.8e+150) && (y <= 3.2e+166))) {
tmp = 0.5 * ((x + z) * ((x - z) / y));
} else {
tmp = 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 ((y <= 6.6d+108) .or. (.not. (y <= 7.8d+150)) .and. (y <= 3.2d+166)) then
tmp = 0.5d0 * ((x + z) * ((x - z) / y))
else
tmp = 0.5d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= 6.6e+108) || (!(y <= 7.8e+150) && (y <= 3.2e+166))) {
tmp = 0.5 * ((x + z) * ((x - z) / y));
} else {
tmp = 0.5 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 6.6e+108) or (not (y <= 7.8e+150) and (y <= 3.2e+166)): tmp = 0.5 * ((x + z) * ((x - z) / y)) else: tmp = 0.5 * y return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 6.6e+108) || (!(y <= 7.8e+150) && (y <= 3.2e+166))) tmp = Float64(0.5 * Float64(Float64(x + z) * Float64(Float64(x - z) / y))); else tmp = Float64(0.5 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= 6.6e+108) || (~((y <= 7.8e+150)) && (y <= 3.2e+166))) tmp = 0.5 * ((x + z) * ((x - z) / y)); else tmp = 0.5 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 6.6e+108], And[N[Not[LessEqual[y, 7.8e+150]], $MachinePrecision], LessEqual[y, 3.2e+166]]], N[(0.5 * N[(N[(x + z), $MachinePrecision] * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.6 \cdot 10^{+108} \lor \neg \left(y \leq 7.8 \cdot 10^{+150}\right) \land y \leq 3.2 \cdot 10^{+166}:\\
\;\;\;\;0.5 \cdot \left(\left(x + z\right) \cdot \frac{x - z}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 6.60000000000000038e108 or 7.79999999999999981e150 < y < 3.19999999999999968e166Initial program 78.1%
Taylor expanded in y around 0 89.0%
distribute-lft-out89.0%
Simplified89.0%
unpow289.0%
unpow289.0%
difference-of-squares92.7%
Applied egg-rr92.7%
Taylor expanded in y around 0 69.3%
associate-*r/73.2%
+-commutative73.2%
Simplified73.2%
if 6.60000000000000038e108 < y < 7.79999999999999981e150 or 3.19999999999999968e166 < y Initial program 28.0%
Taylor expanded in y around inf 77.2%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= y 1.5e+70) (* 0.5 (* (+ x z) (/ (- x z) y))) (* 0.5 (+ y (* (+ x z) (/ x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.5e+70) {
tmp = 0.5 * ((x + z) * ((x - z) / y));
} else {
tmp = 0.5 * (y + ((x + z) * (x / 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 (y <= 1.5d+70) then
tmp = 0.5d0 * ((x + z) * ((x - z) / y))
else
tmp = 0.5d0 * (y + ((x + z) * (x / y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.5e+70) {
tmp = 0.5 * ((x + z) * ((x - z) / y));
} else {
tmp = 0.5 * (y + ((x + z) * (x / y)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.5e+70: tmp = 0.5 * ((x + z) * ((x - z) / y)) else: tmp = 0.5 * (y + ((x + z) * (x / y))) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.5e+70) tmp = Float64(0.5 * Float64(Float64(x + z) * Float64(Float64(x - z) / y))); else tmp = Float64(0.5 * Float64(y + Float64(Float64(x + z) * Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.5e+70) tmp = 0.5 * ((x + z) * ((x - z) / y)); else tmp = 0.5 * (y + ((x + z) * (x / y))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.5e+70], N[(0.5 * N[(N[(x + z), $MachinePrecision] * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \left(\left(x + z\right) \cdot \frac{x - z}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y + \left(x + z\right) \cdot \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 1.49999999999999988e70Initial program 78.7%
Taylor expanded in y around 0 89.3%
distribute-lft-out89.3%
Simplified89.3%
unpow289.3%
unpow289.3%
difference-of-squares92.7%
Applied egg-rr92.7%
Taylor expanded in y around 0 71.2%
associate-*r/74.9%
+-commutative74.9%
Simplified74.9%
if 1.49999999999999988e70 < y Initial program 38.3%
Taylor expanded in y around 0 75.3%
distribute-lft-out75.3%
Simplified75.3%
unpow275.3%
unpow275.3%
difference-of-squares77.4%
Applied egg-rr77.4%
div-inv77.4%
associate-*l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 82.7%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= y 1.18e+76) (* x (* x (/ 0.5 y))) (* 0.5 y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.18e+76) {
tmp = x * (x * (0.5 / y));
} else {
tmp = 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 (y <= 1.18d+76) then
tmp = x * (x * (0.5d0 / y))
else
tmp = 0.5d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.18e+76) {
tmp = x * (x * (0.5 / y));
} else {
tmp = 0.5 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.18e+76: tmp = x * (x * (0.5 / y)) else: tmp = 0.5 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.18e+76) tmp = Float64(x * Float64(x * Float64(0.5 / y))); else tmp = Float64(0.5 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.18e+76) tmp = x * (x * (0.5 / y)); else tmp = 0.5 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.18e+76], N[(x * N[(x * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.18 \cdot 10^{+76}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 1.17999999999999997e76Initial program 78.8%
Taylor expanded in x around inf 35.6%
div-inv35.5%
*-commutative35.5%
associate-/r*35.5%
metadata-eval35.5%
unpow235.5%
associate-*l*37.4%
Applied egg-rr37.4%
if 1.17999999999999997e76 < y Initial program 36.9%
Taylor expanded in y around inf 71.3%
Final simplification43.4%
(FPCore (x y z) :precision binary64 (if (<= y 6e+76) (/ (* 0.5 x) (/ y x)) (* 0.5 y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 6e+76) {
tmp = (0.5 * x) / (y / x);
} else {
tmp = 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 (y <= 6d+76) then
tmp = (0.5d0 * x) / (y / x)
else
tmp = 0.5d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 6e+76) {
tmp = (0.5 * x) / (y / x);
} else {
tmp = 0.5 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 6e+76: tmp = (0.5 * x) / (y / x) else: tmp = 0.5 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 6e+76) tmp = Float64(Float64(0.5 * x) / Float64(y / x)); else tmp = Float64(0.5 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 6e+76) tmp = (0.5 * x) / (y / x); else tmp = 0.5 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 6e+76], N[(N[(0.5 * x), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{+76}:\\
\;\;\;\;\frac{0.5 \cdot x}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 5.9999999999999996e76Initial program 78.8%
Taylor expanded in x around inf 35.6%
div-inv35.5%
*-commutative35.5%
associate-/r*35.5%
metadata-eval35.5%
unpow235.5%
associate-*l*37.4%
Applied egg-rr37.4%
associate-*r/37.4%
metadata-eval37.4%
div-inv37.4%
associate-*r/35.5%
*-commutative35.5%
associate-/l*37.5%
div-inv37.5%
metadata-eval37.5%
Applied egg-rr37.5%
if 5.9999999999999996e76 < y Initial program 36.9%
Taylor expanded in y around inf 71.3%
Final simplification43.4%
(FPCore (x y z) :precision binary64 (* 0.5 y))
double code(double x, double y, double z) {
return 0.5 * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * y
end function
public static double code(double x, double y, double z) {
return 0.5 * y;
}
def code(x, y, z): return 0.5 * y
function code(x, y, z) return Float64(0.5 * y) end
function tmp = code(x, y, z) tmp = 0.5 * y; end
code[x_, y_, z_] := N[(0.5 * y), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot y
\end{array}
Initial program 71.5%
Taylor expanded in y around inf 34.7%
Final simplification34.7%
(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 2024027
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:herbie-target
(- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))