
(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 (- (* y (- (cbrt -0.125))) (/ (cbrt -0.125) (/ (/ y (- x z)) (+ x z)))))
double code(double x, double y, double z) {
return (y * -cbrt(-0.125)) - (cbrt(-0.125) / ((y / (x - z)) / (x + z)));
}
public static double code(double x, double y, double z) {
return (y * -Math.cbrt(-0.125)) - (Math.cbrt(-0.125) / ((y / (x - z)) / (x + z)));
}
function code(x, y, z) return Float64(Float64(y * Float64(-cbrt(-0.125))) - Float64(cbrt(-0.125) / Float64(Float64(y / Float64(x - z)) / Float64(x + z)))) end
code[x_, y_, z_] := N[(N[(y * (-N[Power[-0.125, 1/3], $MachinePrecision])), $MachinePrecision] - N[(N[Power[-0.125, 1/3], $MachinePrecision] / N[(N[(y / N[(x - z), $MachinePrecision]), $MachinePrecision] / N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(-\sqrt[3]{-0.125}\right) - \frac{\sqrt[3]{-0.125}}{\frac{\frac{y}{x - z}}{x + z}}
\end{array}
Initial program 71.3%
add-cbrt-cube53.5%
pow353.6%
div-inv53.6%
add-sqr-sqrt53.6%
pow253.6%
hypot-def53.6%
pow253.6%
*-commutative53.6%
associate-/r*53.6%
metadata-eval53.6%
Applied egg-rr53.6%
Taylor expanded in y around -inf 84.5%
mul-1-neg84.5%
unsub-neg84.5%
mul-1-neg84.5%
distribute-rgt-neg-in84.5%
associate-/l*84.6%
Simplified84.6%
unpow284.6%
unpow284.6%
difference-of-squares90.1%
Applied egg-rr90.1%
expm1-log1p-u77.7%
expm1-udef34.8%
Applied egg-rr34.8%
expm1-def77.7%
expm1-log1p90.1%
*-lft-identity90.1%
times-frac99.2%
associate-*l/99.2%
*-lft-identity99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (+ (* 0.5 (* (- y z) (* (+ y z) (/ 1.0 y)))) (* 0.5 (* x (/ x y)))))
double code(double x, double y, double z) {
return (0.5 * ((y - z) * ((y + z) * (1.0 / y)))) + (0.5 * (x * (x / 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 - z) * ((y + z) * (1.0d0 / y)))) + (0.5d0 * (x * (x / y)))
end function
public static double code(double x, double y, double z) {
return (0.5 * ((y - z) * ((y + z) * (1.0 / y)))) + (0.5 * (x * (x / y)));
}
def code(x, y, z): return (0.5 * ((y - z) * ((y + z) * (1.0 / y)))) + (0.5 * (x * (x / y)))
function code(x, y, z) return Float64(Float64(0.5 * Float64(Float64(y - z) * Float64(Float64(y + z) * Float64(1.0 / y)))) + Float64(0.5 * Float64(x * Float64(x / y)))) end
function tmp = code(x, y, z) tmp = (0.5 * ((y - z) * ((y + z) * (1.0 / y)))) + (0.5 * (x * (x / y))); end
code[x_, y_, z_] := N[(N[(0.5 * N[(N[(y - z), $MachinePrecision] * N[(N[(y + z), $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\left(y - z\right) \cdot \left(\left(y + z\right) \cdot \frac{1}{y}\right)\right) + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)
\end{array}
Initial program 71.3%
associate--l+71.3%
+-commutative71.3%
sqr-neg71.3%
difference-of-squares72.3%
fma-def77.0%
sub-neg77.0%
sub-neg77.0%
remove-double-neg77.0%
Simplified77.0%
Taylor expanded in x around 0 67.3%
div-inv67.2%
*-commutative67.2%
associate-*l*86.0%
Applied egg-rr86.0%
unpow286.0%
*-un-lft-identity86.0%
times-frac90.8%
Applied egg-rr90.8%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (* 0.5 (* (+ y z) (/ (- y z) y))))
double code(double x, double y, double z) {
return 0.5 * ((y + z) * ((y - 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 + z) * ((y - z) / y))
end function
public static double code(double x, double y, double z) {
return 0.5 * ((y + z) * ((y - z) / y));
}
def code(x, y, z): return 0.5 * ((y + z) * ((y - z) / y))
function code(x, y, z) return Float64(0.5 * Float64(Float64(y + z) * Float64(Float64(y - z) / y))) end
function tmp = code(x, y, z) tmp = 0.5 * ((y + z) * ((y - z) / y)); end
code[x_, y_, z_] := N[(0.5 * N[(N[(y + z), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)
\end{array}
Initial program 71.3%
associate--l+71.3%
+-commutative71.3%
sqr-neg71.3%
difference-of-squares72.3%
fma-def77.0%
sub-neg77.0%
sub-neg77.0%
remove-double-neg77.0%
Simplified77.0%
Taylor expanded in x around 0 67.3%
Taylor expanded in x around 0 45.6%
associate-*r/63.5%
Simplified63.5%
Final simplification63.5%
(FPCore (x y z) :precision binary64 (/ 1.0 (/ (/ y x) (* x 0.5))))
double code(double x, double y, double z) {
return 1.0 / ((y / x) / (x * 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 = 1.0d0 / ((y / x) / (x * 0.5d0))
end function
public static double code(double x, double y, double z) {
return 1.0 / ((y / x) / (x * 0.5));
}
def code(x, y, z): return 1.0 / ((y / x) / (x * 0.5))
function code(x, y, z) return Float64(1.0 / Float64(Float64(y / x) / Float64(x * 0.5))) end
function tmp = code(x, y, z) tmp = 1.0 / ((y / x) / (x * 0.5)); end
code[x_, y_, z_] := N[(1.0 / N[(N[(y / x), $MachinePrecision] / N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\frac{y}{x}}{x \cdot 0.5}}
\end{array}
Initial program 71.3%
Taylor expanded in x around inf 34.9%
div-inv34.9%
*-commutative34.9%
associate-/r*34.9%
metadata-eval34.9%
unpow234.9%
associate-*l*37.3%
Applied egg-rr37.3%
associate-*r/37.3%
metadata-eval37.3%
div-inv37.3%
div-inv37.3%
associate-*l*34.9%
*-commutative34.9%
div-inv34.9%
associate-/l*37.4%
clear-num37.3%
div-inv37.3%
metadata-eval37.3%
Applied egg-rr37.3%
Final simplification37.3%
(FPCore (x y z) :precision binary64 (* x (* x (/ 0.5 y))))
double code(double x, double y, double z) {
return x * (x * (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 = x * (x * (0.5d0 / y))
end function
public static double code(double x, double y, double z) {
return x * (x * (0.5 / y));
}
def code(x, y, z): return x * (x * (0.5 / y))
function code(x, y, z) return Float64(x * Float64(x * Float64(0.5 / y))) end
function tmp = code(x, y, z) tmp = x * (x * (0.5 / y)); end
code[x_, y_, z_] := N[(x * N[(x * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \frac{0.5}{y}\right)
\end{array}
Initial program 71.3%
Taylor expanded in x around inf 34.9%
div-inv34.9%
*-commutative34.9%
associate-/r*34.9%
metadata-eval34.9%
unpow234.9%
associate-*l*37.3%
Applied egg-rr37.3%
Final simplification37.3%
(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 71.3%
Taylor expanded in y around inf 30.1%
Final simplification30.1%
(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 2024033
(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)))