
(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 7 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) (/ y (- x z))))))
double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) / (y / (x - z))));
}
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) / (y / (x - z))))
end function
public static double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) / (y / (x - z))));
}
def code(x, y, z): return 0.5 * (y + ((x + z) / (y / (x - z))))
function code(x, y, z) return Float64(0.5 * Float64(y + Float64(Float64(x + z) / Float64(y / Float64(x - z))))) end
function tmp = code(x, y, z) tmp = 0.5 * (y + ((x + z) / (y / (x - z)))); end
code[x_, y_, z_] := N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] / N[(y / N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(y + \frac{x + z}{\frac{y}{x - z}}\right)
\end{array}
Initial program 64.0%
Taylor expanded in y around 0 84.4%
distribute-lft-out84.4%
Simplified84.4%
div-inv84.4%
Applied egg-rr84.4%
div-inv84.4%
unpow284.4%
unpow284.4%
difference-of-squares89.5%
associate-/l*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x 2.7e+104) (* 0.5 (+ y (/ (+ x z) (/ (- y) z)))) (* 0.5 (+ y (/ (+ x z) (/ y x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2.7e+104) {
tmp = 0.5 * (y + ((x + z) / (-y / z)));
} else {
tmp = 0.5 * (y + ((x + z) / (y / x)));
}
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 <= 2.7d+104) then
tmp = 0.5d0 * (y + ((x + z) / (-y / z)))
else
tmp = 0.5d0 * (y + ((x + z) / (y / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2.7e+104) {
tmp = 0.5 * (y + ((x + z) / (-y / z)));
} else {
tmp = 0.5 * (y + ((x + z) / (y / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2.7e+104: tmp = 0.5 * (y + ((x + z) / (-y / z))) else: tmp = 0.5 * (y + ((x + z) / (y / x))) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2.7e+104) tmp = Float64(0.5 * Float64(y + Float64(Float64(x + z) / Float64(Float64(-y) / z)))); else tmp = Float64(0.5 * Float64(y + Float64(Float64(x + z) / Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2.7e+104) tmp = 0.5 * (y + ((x + z) / (-y / z))); else tmp = 0.5 * (y + ((x + z) / (y / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2.7e+104], N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] / N[((-y) / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.7 \cdot 10^{+104}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{x + z}{\frac{-y}{z}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{x + z}{\frac{y}{x}}\right)\\
\end{array}
\end{array}
if x < 2.69999999999999985e104Initial program 63.2%
Taylor expanded in y around 0 86.5%
distribute-lft-out86.5%
Simplified86.5%
div-inv86.5%
Applied egg-rr86.5%
div-inv86.5%
unpow286.5%
unpow286.5%
difference-of-squares89.3%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
if 2.69999999999999985e104 < x Initial program 68.4%
Taylor expanded in y around 0 73.1%
distribute-lft-out73.1%
Simplified73.1%
div-inv73.0%
Applied egg-rr73.0%
div-inv73.1%
unpow273.1%
unpow273.1%
difference-of-squares90.6%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 89.0%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (<= z 3.1e+38) (* 0.5 (+ y (/ (+ x z) (/ y x)))) (* 0.5 (/ (* (+ x z) (- x z)) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.1e+38) {
tmp = 0.5 * (y + ((x + z) / (y / x)));
} else {
tmp = 0.5 * (((x + z) * (x - z)) / 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 (z <= 3.1d+38) then
tmp = 0.5d0 * (y + ((x + z) / (y / x)))
else
tmp = 0.5d0 * (((x + z) * (x - z)) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3.1e+38) {
tmp = 0.5 * (y + ((x + z) / (y / x)));
} else {
tmp = 0.5 * (((x + z) * (x - z)) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.1e+38: tmp = 0.5 * (y + ((x + z) / (y / x))) else: tmp = 0.5 * (((x + z) * (x - z)) / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.1e+38) tmp = Float64(0.5 * Float64(y + Float64(Float64(x + z) / Float64(y / x)))); else tmp = Float64(0.5 * Float64(Float64(Float64(x + z) * Float64(x - z)) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.1e+38) tmp = 0.5 * (y + ((x + z) / (y / x))); else tmp = 0.5 * (((x + z) * (x - z)) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.1e+38], N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(N[(x + z), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.1 \cdot 10^{+38}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{x + z}{\frac{y}{x}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\left(x + z\right) \cdot \left(x - z\right)}{y}\\
\end{array}
\end{array}
if z < 3.10000000000000018e38Initial program 64.3%
Taylor expanded in y around 0 87.6%
distribute-lft-out87.6%
Simplified87.6%
div-inv87.6%
Applied egg-rr87.6%
div-inv87.6%
unpow287.6%
unpow287.6%
difference-of-squares90.5%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 75.1%
if 3.10000000000000018e38 < z Initial program 63.0%
Taylor expanded in y around 0 72.4%
distribute-lft-out72.4%
Simplified72.4%
unpow272.4%
unpow272.4%
difference-of-squares85.6%
Applied egg-rr85.6%
Taylor expanded in y around 0 76.4%
Final simplification75.4%
(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 64.0%
Taylor expanded in y around 0 84.4%
distribute-lft-out84.4%
Simplified84.4%
div-inv84.4%
Applied egg-rr84.4%
div-inv84.4%
unpow284.4%
unpow284.4%
difference-of-squares89.5%
associate-/l*99.9%
Applied egg-rr99.9%
associate-/r/99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x 6.2e+43) (* 0.5 y) (* (/ x y) (/ x 2.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= 6.2e+43) {
tmp = 0.5 * y;
} else {
tmp = (x / y) * (x / 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 <= 6.2d+43) then
tmp = 0.5d0 * y
else
tmp = (x / y) * (x / 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 6.2e+43) {
tmp = 0.5 * y;
} else {
tmp = (x / y) * (x / 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 6.2e+43: tmp = 0.5 * y else: tmp = (x / y) * (x / 2.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 6.2e+43) tmp = Float64(0.5 * y); else tmp = Float64(Float64(x / y) * Float64(x / 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 6.2e+43) tmp = 0.5 * y; else tmp = (x / y) * (x / 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 6.2e+43], N[(0.5 * y), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.2 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\
\end{array}
\end{array}
if x < 6.2000000000000003e43Initial program 62.5%
Taylor expanded in y around inf 43.8%
if 6.2000000000000003e43 < x Initial program 70.4%
Taylor expanded in x around inf 66.5%
unpow266.5%
times-frac66.5%
Applied egg-rr66.5%
Final simplification48.2%
(FPCore (x y z) :precision binary64 (* 0.5 (+ y (/ (+ x z) (/ y x)))))
double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) / (y / x)));
}
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) / (y / x)))
end function
public static double code(double x, double y, double z) {
return 0.5 * (y + ((x + z) / (y / x)));
}
def code(x, y, z): return 0.5 * (y + ((x + z) / (y / x)))
function code(x, y, z) return Float64(0.5 * Float64(y + Float64(Float64(x + z) / Float64(y / x)))) end
function tmp = code(x, y, z) tmp = 0.5 * (y + ((x + z) / (y / x))); end
code[x_, y_, z_] := N[(0.5 * N[(y + N[(N[(x + z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(y + \frac{x + z}{\frac{y}{x}}\right)
\end{array}
Initial program 64.0%
Taylor expanded in y around 0 84.4%
distribute-lft-out84.4%
Simplified84.4%
div-inv84.4%
Applied egg-rr84.4%
div-inv84.4%
unpow284.4%
unpow284.4%
difference-of-squares89.5%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 69.1%
Final simplification69.1%
(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 64.0%
Taylor expanded in y around inf 38.9%
Final simplification38.9%
(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 2024034
(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)))