| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 26436 |

(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -7.2e+53)
(* 2.0 (pow (exp (* 0.25 (- (log (- x)) (log (/ -1.0 y))))) 2.0))
(if (<= y 6.5e-257)
(* 2.0 (sqrt (+ (* x z) (* y (+ x z)))))
(* 2.0 (* (sqrt (+ y x)) (sqrt z))))))double code(double x, double y, double z) {
return 2.0 * sqrt((((x * y) + (x * z)) + (y * z)));
}
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+53) {
tmp = 2.0 * pow(exp((0.25 * (log(-x) - log((-1.0 / y))))), 2.0);
} else if (y <= 6.5e-257) {
tmp = 2.0 * sqrt(((x * z) + (y * (x + z))));
} else {
tmp = 2.0 * (sqrt((y + x)) * sqrt(z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 2.0d0 * sqrt((((x * y) + (x * z)) + (y * z)))
end function
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-7.2d+53)) then
tmp = 2.0d0 * (exp((0.25d0 * (log(-x) - log(((-1.0d0) / y))))) ** 2.0d0)
else if (y <= 6.5d-257) then
tmp = 2.0d0 * sqrt(((x * z) + (y * (x + z))))
else
tmp = 2.0d0 * (sqrt((y + x)) * sqrt(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return 2.0 * Math.sqrt((((x * y) + (x * z)) + (y * z)));
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+53) {
tmp = 2.0 * Math.pow(Math.exp((0.25 * (Math.log(-x) - Math.log((-1.0 / y))))), 2.0);
} else if (y <= 6.5e-257) {
tmp = 2.0 * Math.sqrt(((x * z) + (y * (x + z))));
} else {
tmp = 2.0 * (Math.sqrt((y + x)) * Math.sqrt(z));
}
return tmp;
}
def code(x, y, z): return 2.0 * math.sqrt((((x * y) + (x * z)) + (y * z)))
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -7.2e+53: tmp = 2.0 * math.pow(math.exp((0.25 * (math.log(-x) - math.log((-1.0 / y))))), 2.0) elif y <= 6.5e-257: tmp = 2.0 * math.sqrt(((x * z) + (y * (x + z)))) else: tmp = 2.0 * (math.sqrt((y + x)) * math.sqrt(z)) return tmp
function code(x, y, z) return Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)))) end
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -7.2e+53) tmp = Float64(2.0 * (exp(Float64(0.25 * Float64(log(Float64(-x)) - log(Float64(-1.0 / y))))) ^ 2.0)); elseif (y <= 6.5e-257) tmp = Float64(2.0 * sqrt(Float64(Float64(x * z) + Float64(y * Float64(x + z))))); else tmp = Float64(2.0 * Float64(sqrt(Float64(y + x)) * sqrt(z))); end return tmp end
function tmp = code(x, y, z) tmp = 2.0 * sqrt((((x * y) + (x * z)) + (y * z))); end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -7.2e+53)
tmp = 2.0 * (exp((0.25 * (log(-x) - log((-1.0 / y))))) ^ 2.0);
elseif (y <= 6.5e-257)
tmp = 2.0 * sqrt(((x * z) + (y * (x + z))));
else
tmp = 2.0 * (sqrt((y + x)) * sqrt(z));
end
tmp_2 = tmp;
end
code[x_, y_, z_] := N[(2.0 * N[Sqrt[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -7.2e+53], N[(2.0 * N[Power[N[Exp[N[(0.25 * N[(N[Log[(-x)], $MachinePrecision] - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.5e-257], N[(2.0 * N[Sqrt[N[(N[(x * z), $MachinePrecision] + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[N[(y + x), $MachinePrecision]], $MachinePrecision] * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+53}:\\
\;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(-x\right) - \log \left(\frac{-1}{y}\right)\right)}\right)}^{2}\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-257}:\\
\;\;\;\;2 \cdot \sqrt{x \cdot z + y \cdot \left(x + z\right)}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{y + x} \cdot \sqrt{z}\right)\\
\end{array}
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 70.2% |
|---|---|
| Target | 82.7% |
| Herbie | 95.6% |
if y < -7.2e53Initial program 58.9%
Simplified58.9%
[Start]58.9% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]58.9% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Applied egg-rr58.7%
[Start]58.9% | \[ 2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}
\] |
|---|---|
flip-+ [=>]12.6% | \[ 2 \cdot \sqrt{\color{blue}{\frac{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) - \left(y \cdot z\right) \cdot \left(y \cdot z\right)}{x \cdot \left(y + z\right) - y \cdot z}}}
\] |
flip-+ [<=]58.9% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right) + y \cdot z}}
\] |
distribute-lft-in [=>]58.9% | \[ 2 \cdot \sqrt{\color{blue}{\left(x \cdot y + x \cdot z\right)} + y \cdot z}
\] |
add-sqr-sqrt [=>]58.5% | \[ 2 \cdot \color{blue}{\left(\sqrt{\sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}} \cdot \sqrt{\sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}}\right)}
\] |
pow2 [=>]58.5% | \[ 2 \cdot \color{blue}{{\left(\sqrt{\sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}}\right)}^{2}}
\] |
pow1/2 [=>]58.5% | \[ 2 \cdot {\left(\sqrt{\color{blue}{{\left(\left(x \cdot y + x \cdot z\right) + y \cdot z\right)}^{0.5}}}\right)}^{2}
\] |
sqrt-pow1 [=>]58.5% | \[ 2 \cdot {\color{blue}{\left({\left(\left(x \cdot y + x \cdot z\right) + y \cdot z\right)}^{\left(\frac{0.5}{2}\right)}\right)}}^{2}
\] |
associate-+l+ [=>]58.5% | \[ 2 \cdot {\left({\color{blue}{\left(x \cdot y + \left(x \cdot z + y \cdot z\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2}
\] |
distribute-rgt-in [<=]58.5% | \[ 2 \cdot {\left({\left(x \cdot y + \color{blue}{z \cdot \left(x + y\right)}\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}
\] |
fma-udef [<=]58.7% | \[ 2 \cdot {\left({\color{blue}{\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2}
\] |
metadata-eval [=>]58.7% | \[ 2 \cdot {\left({\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}^{\color{blue}{0.25}}\right)}^{2}
\] |
Taylor expanded in z around 0 31.7%
Taylor expanded in y around -inf 48.0%
if -7.2e53 < y < 6.5000000000000002e-257Initial program 87.4%
Simplified87.4%
[Start]87.4% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]87.4% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in y around 0 87.4%
if 6.5000000000000002e-257 < y Initial program 64.3%
Simplified64.4%
[Start]64.3% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]64.4% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in z around inf 39.4%
Applied egg-rr44.5%
[Start]39.4% | \[ 2 \cdot \sqrt{\left(y + x\right) \cdot z}
\] |
|---|---|
sqrt-prod [=>]44.5% | \[ 2 \cdot \color{blue}{\left(\sqrt{y + x} \cdot \sqrt{z}\right)}
\] |
+-commutative [=>]44.5% | \[ 2 \cdot \left(\sqrt{\color{blue}{x + y}} \cdot \sqrt{z}\right)
\] |
Simplified44.5%
[Start]44.5% | \[ 2 \cdot \left(\sqrt{x + y} \cdot \sqrt{z}\right)
\] |
|---|---|
+-commutative [=>]44.5% | \[ 2 \cdot \left(\sqrt{\color{blue}{y + x}} \cdot \sqrt{z}\right)
\] |
Final simplification60.4%
| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 26436 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.8% |
| Cost | 26564 |
| Alternative 3 | |
|---|---|
| Accuracy | 84.4% |
| Cost | 13380 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 13252 |
| Alternative 5 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 7172 |
| Alternative 6 | |
|---|---|
| Accuracy | 70.3% |
| Cost | 7104 |
| Alternative 7 | |
|---|---|
| Accuracy | 70.2% |
| Cost | 7104 |
| Alternative 8 | |
|---|---|
| Accuracy | 69.0% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Accuracy | 70.4% |
| Cost | 6980 |
| Alternative 10 | |
|---|---|
| Accuracy | 68.2% |
| Cost | 6852 |
| Alternative 11 | |
|---|---|
| Accuracy | 35.5% |
| Cost | 6720 |
herbie shell --seed 2023167
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:descartes from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(if (< z 7.636950090573675e+176) (* 2.0 (sqrt (+ (* (+ x y) z) (* x y)))) (* (* (+ (* 0.25 (* (* (pow y -0.75) (* (pow z -0.75) x)) (+ y z))) (* (pow z 0.25) (pow y 0.25))) (+ (* 0.25 (* (* (pow y -0.75) (* (pow z -0.75) x)) (+ y z))) (* (pow z 0.25) (pow y 0.25)))) 2.0))
(* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))