| Alternative 1 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 13444 |
(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
(FPCore (x y z) :precision binary64 (if (<= y -2e-310) (* 2.0 (* (sqrt (- y)) (sqrt (- z x)))) (* 2.0 (/ (sqrt (+ z x)) (sqrt (/ 1.0 y))))))
double code(double x, double y, double z) {
return 2.0 * sqrt((((x * y) + (x * z)) + (y * z)));
}
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-310) {
tmp = 2.0 * (sqrt(-y) * sqrt((z - x)));
} else {
tmp = 2.0 * (sqrt((z + x)) / sqrt((1.0 / 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
code = 2.0d0 * sqrt((((x * y) + (x * z)) + (y * z)))
end 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 <= (-2d-310)) then
tmp = 2.0d0 * (sqrt(-y) * sqrt((z - x)))
else
tmp = 2.0d0 * (sqrt((z + x)) / sqrt((1.0d0 / y)))
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)));
}
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2e-310) {
tmp = 2.0 * (Math.sqrt(-y) * Math.sqrt((z - x)));
} else {
tmp = 2.0 * (Math.sqrt((z + x)) / Math.sqrt((1.0 / y)));
}
return tmp;
}
def code(x, y, z): return 2.0 * math.sqrt((((x * y) + (x * z)) + (y * z)))
def code(x, y, z): tmp = 0 if y <= -2e-310: tmp = 2.0 * (math.sqrt(-y) * math.sqrt((z - x))) else: tmp = 2.0 * (math.sqrt((z + x)) / math.sqrt((1.0 / y))) return tmp
function code(x, y, z) return Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)))) end
function code(x, y, z) tmp = 0.0 if (y <= -2e-310) tmp = Float64(2.0 * Float64(sqrt(Float64(-y)) * sqrt(Float64(z - x)))); else tmp = Float64(2.0 * Float64(sqrt(Float64(z + x)) / sqrt(Float64(1.0 / y)))); end return tmp end
function tmp = code(x, y, z) tmp = 2.0 * sqrt((((x * y) + (x * z)) + (y * z))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e-310) tmp = 2.0 * (sqrt(-y) * sqrt((z - x))); else tmp = 2.0 * (sqrt((z + x)) / sqrt((1.0 / y))); 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]
code[x_, y_, z_] := If[LessEqual[y, -2e-310], N[(2.0 * N[(N[Sqrt[(-y)], $MachinePrecision] * N[Sqrt[N[(z - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[N[(z + x), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-310}:\\
\;\;\;\;2 \cdot \left(\sqrt{-y} \cdot \sqrt{z - x}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{\sqrt{z + x}}{\sqrt{\frac{1}{y}}}\\
\end{array}
Results
| Original | 69.0% |
|---|---|
| Target | 82.7% |
| Herbie | 96.4% |
if y < -1.999999999999994e-310Initial program 70.1%
Simplified70.1%
[Start]70.1 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]70.1 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Applied egg-rr69.7%
[Start]70.1 | \[ 2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}
\] |
|---|---|
flip3-+ [=>]25.9 | \[ 2 \cdot \sqrt{\color{blue}{\frac{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}}}
\] |
clear-num [=>]25.9 | \[ 2 \cdot \sqrt{\color{blue}{\frac{1}{\frac{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}}}}
\] |
*-un-lft-identity [=>]25.9 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\color{blue}{1 \cdot \left(\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)\right)}}{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}}}
\] |
associate-/l* [=>]25.9 | \[ 2 \cdot \sqrt{\frac{1}{\color{blue}{\frac{1}{\frac{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}}}}}
\] |
flip3-+ [<=]69.7 | \[ 2 \cdot \sqrt{\frac{1}{\frac{1}{\color{blue}{x \cdot \left(y + z\right) + y \cdot z}}}}
\] |
fma-def [=>]69.7 | \[ 2 \cdot \sqrt{\frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(x, y + z, y \cdot z\right)}}}}
\] |
Taylor expanded in y around -inf 67.4%
Simplified67.3%
[Start]67.4 | \[ 2 \cdot \sqrt{\frac{1}{\frac{-1}{y \cdot \left(-1 \cdot z + -1 \cdot x\right)}}}
\] |
|---|---|
associate-/r* [=>]67.3 | \[ 2 \cdot \sqrt{\frac{1}{\color{blue}{\frac{\frac{-1}{y}}{-1 \cdot z + -1 \cdot x}}}}
\] |
mul-1-neg [=>]67.3 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{-1 \cdot z + \color{blue}{\left(-x\right)}}}}
\] |
unsub-neg [=>]67.3 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\color{blue}{-1 \cdot z - x}}}}
\] |
mul-1-neg [=>]67.3 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\color{blue}{\left(-z\right)} - x}}}
\] |
Applied egg-rr96.5%
[Start]67.3 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\left(-z\right) - x}}}
\] |
|---|---|
associate-/r/ [=>]67.6 | \[ 2 \cdot \sqrt{\color{blue}{\frac{1}{\frac{-1}{y}} \cdot \left(\left(-z\right) - x\right)}}
\] |
sqrt-prod [=>]96.5 | \[ 2 \cdot \color{blue}{\left(\sqrt{\frac{1}{\frac{-1}{y}}} \cdot \sqrt{\left(-z\right) - x}\right)}
\] |
associate-/r/ [=>]96.5 | \[ 2 \cdot \left(\sqrt{\color{blue}{\frac{1}{-1} \cdot y}} \cdot \sqrt{\left(-z\right) - x}\right)
\] |
metadata-eval [=>]96.5 | \[ 2 \cdot \left(\sqrt{\color{blue}{-1} \cdot y} \cdot \sqrt{\left(-z\right) - x}\right)
\] |
neg-mul-1 [<=]96.5 | \[ 2 \cdot \left(\sqrt{\color{blue}{-y}} \cdot \sqrt{\left(-z\right) - x}\right)
\] |
add-sqr-sqrt [=>]47.6 | \[ 2 \cdot \left(\sqrt{-y} \cdot \sqrt{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}} - x}\right)
\] |
sqrt-unprod [=>]95.3 | \[ 2 \cdot \left(\sqrt{-y} \cdot \sqrt{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}} - x}\right)
\] |
sqr-neg [=>]95.3 | \[ 2 \cdot \left(\sqrt{-y} \cdot \sqrt{\sqrt{\color{blue}{z \cdot z}} - x}\right)
\] |
sqrt-unprod [<=]48.9 | \[ 2 \cdot \left(\sqrt{-y} \cdot \sqrt{\color{blue}{\sqrt{z} \cdot \sqrt{z}} - x}\right)
\] |
add-sqr-sqrt [<=]96.5 | \[ 2 \cdot \left(\sqrt{-y} \cdot \sqrt{\color{blue}{z} - x}\right)
\] |
if -1.999999999999994e-310 < y Initial program 67.9%
Simplified67.9%
[Start]67.9 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]67.9 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Applied egg-rr67.5%
[Start]67.9 | \[ 2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}
\] |
|---|---|
flip3-+ [=>]24.9 | \[ 2 \cdot \sqrt{\color{blue}{\frac{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}}}
\] |
clear-num [=>]24.9 | \[ 2 \cdot \sqrt{\color{blue}{\frac{1}{\frac{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}}}}
\] |
*-un-lft-identity [=>]24.9 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\color{blue}{1 \cdot \left(\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)\right)}}{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}}}
\] |
associate-/l* [=>]24.9 | \[ 2 \cdot \sqrt{\frac{1}{\color{blue}{\frac{1}{\frac{{\left(x \cdot \left(y + z\right)\right)}^{3} + {\left(y \cdot z\right)}^{3}}{\left(x \cdot \left(y + z\right)\right) \cdot \left(x \cdot \left(y + z\right)\right) + \left(\left(y \cdot z\right) \cdot \left(y \cdot z\right) - \left(x \cdot \left(y + z\right)\right) \cdot \left(y \cdot z\right)\right)}}}}}
\] |
flip3-+ [<=]67.5 | \[ 2 \cdot \sqrt{\frac{1}{\frac{1}{\color{blue}{x \cdot \left(y + z\right) + y \cdot z}}}}
\] |
fma-def [=>]67.5 | \[ 2 \cdot \sqrt{\frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(x, y + z, y \cdot z\right)}}}}
\] |
Taylor expanded in y around -inf 65.1%
Simplified65.0%
[Start]65.1 | \[ 2 \cdot \sqrt{\frac{1}{\frac{-1}{y \cdot \left(-1 \cdot z + -1 \cdot x\right)}}}
\] |
|---|---|
associate-/r* [=>]65.0 | \[ 2 \cdot \sqrt{\frac{1}{\color{blue}{\frac{\frac{-1}{y}}{-1 \cdot z + -1 \cdot x}}}}
\] |
mul-1-neg [=>]65.0 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{-1 \cdot z + \color{blue}{\left(-x\right)}}}}
\] |
unsub-neg [=>]65.0 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\color{blue}{-1 \cdot z - x}}}}
\] |
mul-1-neg [=>]65.0 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\color{blue}{\left(-z\right)} - x}}}
\] |
Applied egg-rr96.2%
[Start]65.0 | \[ 2 \cdot \sqrt{\frac{1}{\frac{\frac{-1}{y}}{\left(-z\right) - x}}}
\] |
|---|---|
sqrt-div [=>]66.4 | \[ 2 \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\frac{-1}{y}}{\left(-z\right) - x}}}}
\] |
metadata-eval [=>]66.4 | \[ 2 \cdot \frac{\color{blue}{1}}{\sqrt{\frac{\frac{-1}{y}}{\left(-z\right) - x}}}
\] |
frac-2neg [=>]66.4 | \[ 2 \cdot \frac{1}{\sqrt{\color{blue}{\frac{-\frac{-1}{y}}{-\left(\left(-z\right) - x\right)}}}}
\] |
distribute-neg-frac [=>]66.4 | \[ 2 \cdot \frac{1}{\sqrt{\frac{\color{blue}{\frac{--1}{y}}}{-\left(\left(-z\right) - x\right)}}}
\] |
metadata-eval [=>]66.4 | \[ 2 \cdot \frac{1}{\sqrt{\frac{\frac{\color{blue}{1}}{y}}{-\left(\left(-z\right) - x\right)}}}
\] |
sqrt-div [=>]96.2 | \[ 2 \cdot \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{-\left(\left(-z\right) - x\right)}}}}
\] |
neg-sub0 [=>]96.2 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\color{blue}{0 - \left(\left(-z\right) - x\right)}}}}
\] |
metadata-eval [<=]96.2 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\color{blue}{\log 1} - \left(\left(-z\right) - x\right)}}}
\] |
add-sqr-sqrt [=>]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\log 1 - \left(\color{blue}{\sqrt{-z} \cdot \sqrt{-z}} - x\right)}}}
\] |
sqrt-unprod [=>]0.1 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\log 1 - \left(\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}} - x\right)}}}
\] |
sqr-neg [=>]0.1 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\log 1 - \left(\sqrt{\color{blue}{z \cdot z}} - x\right)}}}
\] |
sqrt-unprod [<=]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\log 1 - \left(\color{blue}{\sqrt{z} \cdot \sqrt{z}} - x\right)}}}
\] |
add-sqr-sqrt [<=]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\log 1 - \left(\color{blue}{z} - x\right)}}}
\] |
associate-+l- [<=]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\color{blue}{\left(\log 1 - z\right) + x}}}}
\] |
metadata-eval [=>]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\left(\color{blue}{0} - z\right) + x}}}
\] |
neg-sub0 [<=]0.0 | \[ 2 \cdot \frac{1}{\frac{\sqrt{\frac{1}{y}}}{\sqrt{\color{blue}{\left(-z\right)} + x}}}
\] |
Simplified96.3%
[Start]96.2 | \[ 2 \cdot \left(\frac{1}{\sqrt{{y}^{-1}}} \cdot \sqrt{z + x}\right)
\] |
|---|---|
associate-*l/ [=>]96.3 | \[ 2 \cdot \color{blue}{\frac{1 \cdot \sqrt{z + x}}{\sqrt{{y}^{-1}}}}
\] |
*-lft-identity [=>]96.3 | \[ 2 \cdot \frac{\color{blue}{\sqrt{z + x}}}{\sqrt{{y}^{-1}}}
\] |
+-commutative [=>]96.3 | \[ 2 \cdot \frac{\sqrt{\color{blue}{x + z}}}{\sqrt{{y}^{-1}}}
\] |
unpow-1 [=>]96.3 | \[ 2 \cdot \frac{\sqrt{x + z}}{\sqrt{\color{blue}{\frac{1}{y}}}}
\] |
Final simplification96.4%
| Alternative 1 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 13444 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 13384 |
| Alternative 3 | |
|---|---|
| Accuracy | 70.5% |
| Cost | 7876 |
| Alternative 4 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 7305 |
| Alternative 5 | |
|---|---|
| Accuracy | 69.5% |
| Cost | 7236 |
| Alternative 6 | |
|---|---|
| Accuracy | 68.0% |
| Cost | 7044 |
| Alternative 7 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 6980 |
| Alternative 8 | |
|---|---|
| Accuracy | 68.7% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Accuracy | 66.4% |
| Cost | 6852 |
| Alternative 10 | |
|---|---|
| Accuracy | 35.1% |
| Cost | 6720 |
herbie shell --seed 2023141
(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)))))