| Alternative 1 | |
|---|---|
| Error | 17.75% |
| Cost | 13508 |
(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
(FPCore (x y z) :precision binary64 (if (<= y -5e-310) (* 2.0 (/ (sqrt (- y)) (sqrt (/ -1.0 (+ z x))))) (* 2.0 (* (sqrt z) (sqrt 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 <= -5e-310) {
tmp = 2.0 * (sqrt(-y) / sqrt((-1.0 / (z + x))));
} else {
tmp = 2.0 * (sqrt(z) * sqrt(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 <= (-5d-310)) then
tmp = 2.0d0 * (sqrt(-y) / sqrt(((-1.0d0) / (z + x))))
else
tmp = 2.0d0 * (sqrt(z) * sqrt(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 <= -5e-310) {
tmp = 2.0 * (Math.sqrt(-y) / Math.sqrt((-1.0 / (z + x))));
} else {
tmp = 2.0 * (Math.sqrt(z) * Math.sqrt(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 <= -5e-310: tmp = 2.0 * (math.sqrt(-y) / math.sqrt((-1.0 / (z + x)))) else: tmp = 2.0 * (math.sqrt(z) * math.sqrt(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 <= -5e-310) tmp = Float64(2.0 * Float64(sqrt(Float64(-y)) / sqrt(Float64(-1.0 / Float64(z + x))))); else tmp = Float64(2.0 * Float64(sqrt(z) * sqrt(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 <= -5e-310) tmp = 2.0 * (sqrt(-y) / sqrt((-1.0 / (z + x)))); else tmp = 2.0 * (sqrt(z) * sqrt(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, -5e-310], N[(2.0 * N[(N[Sqrt[(-y)], $MachinePrecision] / N[Sqrt[N[(-1.0 / N[(z + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[z], $MachinePrecision] * N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-310}:\\
\;\;\;\;2 \cdot \frac{\sqrt{-y}}{\sqrt{\frac{-1}{z + x}}}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\
\end{array}
Results
| Original | 31.93% |
|---|---|
| Target | 18.6% |
| Herbie | 3.51% |
if y < -4.999999999999985e-310Initial program 31.84
Simplified31.83
[Start]31.84 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
associate-+l+ [=>]31.84 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot y + \left(x \cdot z + y \cdot z\right)}}
\] |
fma-def [=>]31.83 | \[ 2 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(x, y, x \cdot z + y \cdot z\right)}}
\] |
distribute-rgt-out [=>]31.83 | \[ 2 \cdot \sqrt{\mathsf{fma}\left(x, y, \color{blue}{z \cdot \left(x + y\right)}\right)}
\] |
Applied egg-rr31.83
Applied egg-rr63.47
Simplified74.93
[Start]63.47 | \[ 2 \cdot \sqrt{\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - {\left(z \cdot \left(x + y\right)\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
|---|---|
associate-*r* [=>]68.26 | \[ 2 \cdot \sqrt{\frac{\color{blue}{\left(\left(x \cdot y\right) \cdot x\right) \cdot y} - {\left(z \cdot \left(x + y\right)\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
*-commutative [=>]68.26 | \[ 2 \cdot \sqrt{\frac{\color{blue}{y \cdot \left(\left(x \cdot y\right) \cdot x\right)} - {\left(z \cdot \left(x + y\right)\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
*-commutative [<=]68.26 | \[ 2 \cdot \sqrt{\frac{y \cdot \left(\color{blue}{\left(y \cdot x\right)} \cdot x\right) - {\left(z \cdot \left(x + y\right)\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
associate-*l* [=>]74.93 | \[ 2 \cdot \sqrt{\frac{y \cdot \color{blue}{\left(y \cdot \left(x \cdot x\right)\right)} - {\left(z \cdot \left(x + y\right)\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
+-commutative [=>]74.93 | \[ 2 \cdot \sqrt{\frac{y \cdot \left(y \cdot \left(x \cdot x\right)\right) - {\left(z \cdot \color{blue}{\left(y + x\right)}\right)}^{2}}{x \cdot y - z \cdot \left(x + y\right)}}
\] |
*-commutative [<=]74.93 | \[ 2 \cdot \sqrt{\frac{y \cdot \left(y \cdot \left(x \cdot x\right)\right) - {\left(z \cdot \left(y + x\right)\right)}^{2}}{\color{blue}{y \cdot x} - z \cdot \left(x + y\right)}}
\] |
+-commutative [=>]74.93 | \[ 2 \cdot \sqrt{\frac{y \cdot \left(y \cdot \left(x \cdot x\right)\right) - {\left(z \cdot \left(y + x\right)\right)}^{2}}{y \cdot x - z \cdot \color{blue}{\left(y + x\right)}}}
\] |
Taylor expanded in y around inf 69.53
Simplified63.36
[Start]69.53 | \[ 2 \cdot \sqrt{\frac{y \cdot \left({x}^{2} - {z}^{2}\right)}{x - z}}
\] |
|---|---|
associate-/l* [=>]63.36 | \[ 2 \cdot \sqrt{\color{blue}{\frac{y}{\frac{x - z}{{x}^{2} - {z}^{2}}}}}
\] |
unpow2 [=>]63.36 | \[ 2 \cdot \sqrt{\frac{y}{\frac{x - z}{\color{blue}{x \cdot x} - {z}^{2}}}}
\] |
unpow2 [=>]63.36 | \[ 2 \cdot \sqrt{\frac{y}{\frac{x - z}{x \cdot x - \color{blue}{z \cdot z}}}}
\] |
Applied egg-rr3.62
Simplified3.62
[Start]3.62 | \[ 2 \cdot \frac{\sqrt{-y}}{\sqrt{\frac{-1}{x + z}}}
\] |
|---|---|
+-commutative [=>]3.62 | \[ 2 \cdot \frac{\sqrt{-y}}{\sqrt{\frac{-1}{\color{blue}{z + x}}}}
\] |
if -4.999999999999985e-310 < y Initial program 32.03
Simplified32.04
[Start]32.03 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
associate-+l+ [=>]32.03 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot y + \left(x \cdot z + y \cdot z\right)}}
\] |
fma-def [=>]32.03 | \[ 2 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(x, y, x \cdot z + y \cdot z\right)}}
\] |
distribute-rgt-out [=>]32.04 | \[ 2 \cdot \sqrt{\mathsf{fma}\left(x, y, \color{blue}{z \cdot \left(x + y\right)}\right)}
\] |
Applied egg-rr76.68
Simplified74.35
[Start]76.68 | \[ 2 \cdot \sqrt{\mathsf{fma}\left(x, y, \frac{\left(z \cdot z\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(z \cdot z\right)}{z \cdot \left(x - y\right)}\right)}
\] |
|---|---|
unswap-sqr [=>]76.72 | \[ 2 \cdot \sqrt{\mathsf{fma}\left(x, y, \frac{\color{blue}{\left(z \cdot x\right) \cdot \left(z \cdot x\right)} - \left(y \cdot y\right) \cdot \left(z \cdot z\right)}{z \cdot \left(x - y\right)}\right)}
\] |
associate-*l* [=>]74.35 | \[ 2 \cdot \sqrt{\mathsf{fma}\left(x, y, \frac{\left(z \cdot x\right) \cdot \left(z \cdot x\right) - \color{blue}{y \cdot \left(y \cdot \left(z \cdot z\right)\right)}}{z \cdot \left(x - y\right)}\right)}
\] |
Taylor expanded in x around 0 34.11
Simplified34.11
[Start]34.11 | \[ 2 \cdot \sqrt{y \cdot z}
\] |
|---|---|
*-commutative [<=]34.11 | \[ 2 \cdot \sqrt{\color{blue}{z \cdot y}}
\] |
Applied egg-rr3.4
Final simplification3.51
| Alternative 1 | |
|---|---|
| Error | 17.75% |
| Cost | 13508 |
| Alternative 2 | |
|---|---|
| Error | 17.87% |
| Cost | 13252 |
| Alternative 3 | |
|---|---|
| Error | 30.54% |
| Cost | 7876 |
| Alternative 4 | |
|---|---|
| Error | 32.05% |
| Cost | 7108 |
| Alternative 5 | |
|---|---|
| Error | 31.93% |
| Cost | 7104 |
| Alternative 6 | |
|---|---|
| Error | 31.93% |
| Cost | 7104 |
| Alternative 7 | |
|---|---|
| Error | 33.23% |
| Cost | 6980 |
| Alternative 8 | |
|---|---|
| Error | 32.05% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Error | 34.05% |
| Cost | 6916 |
| Alternative 10 | |
|---|---|
| Error | 34.05% |
| Cost | 6852 |
| Alternative 11 | |
|---|---|
| Error | 65.31% |
| Cost | 6720 |
herbie shell --seed 2023121
(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)))))