| Alternative 1 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 20364 |

(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 2.0 (exp (* (- (log (- (- y) z)) (log (/ -1.0 x))) 0.5)))))
(if (<= y -5.6e+27)
t_0
(if (<= y -6e-221)
(* 2.0 (sqrt (* x (+ y z))))
(if (<= y 6.2e-271) t_0 (* 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 t_0 = 2.0 * exp(((log((-y - z)) - log((-1.0 / x))) * 0.5));
double tmp;
if (y <= -5.6e+27) {
tmp = t_0;
} else if (y <= -6e-221) {
tmp = 2.0 * sqrt((x * (y + z)));
} else if (y <= 6.2e-271) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = 2.0d0 * exp(((log((-y - z)) - log(((-1.0d0) / x))) * 0.5d0))
if (y <= (-5.6d+27)) then
tmp = t_0
else if (y <= (-6d-221)) then
tmp = 2.0d0 * sqrt((x * (y + z)))
else if (y <= 6.2d-271) then
tmp = t_0
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 t_0 = 2.0 * Math.exp(((Math.log((-y - z)) - Math.log((-1.0 / x))) * 0.5));
double tmp;
if (y <= -5.6e+27) {
tmp = t_0;
} else if (y <= -6e-221) {
tmp = 2.0 * Math.sqrt((x * (y + z)));
} else if (y <= 6.2e-271) {
tmp = t_0;
} 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): t_0 = 2.0 * math.exp(((math.log((-y - z)) - math.log((-1.0 / x))) * 0.5)) tmp = 0 if y <= -5.6e+27: tmp = t_0 elif y <= -6e-221: tmp = 2.0 * math.sqrt((x * (y + z))) elif y <= 6.2e-271: tmp = t_0 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) t_0 = Float64(2.0 * exp(Float64(Float64(log(Float64(Float64(-y) - z)) - log(Float64(-1.0 / x))) * 0.5))) tmp = 0.0 if (y <= -5.6e+27) tmp = t_0; elseif (y <= -6e-221) tmp = Float64(2.0 * sqrt(Float64(x * Float64(y + z)))); elseif (y <= 6.2e-271) tmp = t_0; 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) t_0 = 2.0 * exp(((log((-y - z)) - log((-1.0 / x))) * 0.5)); tmp = 0.0; if (y <= -5.6e+27) tmp = t_0; elseif (y <= -6e-221) tmp = 2.0 * sqrt((x * (y + z))); elseif (y <= 6.2e-271) tmp = t_0; 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_] := Block[{t$95$0 = N[(2.0 * N[Exp[N[(N[(N[Log[N[((-y) - z), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.6e+27], t$95$0, If[LessEqual[y, -6e-221], N[(2.0 * N[Sqrt[N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.2e-271], t$95$0, 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}
t_0 := 2 \cdot e^{\left(\log \left(\left(-y\right) - z\right) - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}\\
\mathbf{if}\;y \leq -5.6 \cdot 10^{+27}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-221}:\\
\;\;\;\;2 \cdot \sqrt{x \cdot \left(y + z\right)}\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-271}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 70.2% |
|---|---|
| Target | 82.7% |
| Herbie | 94.7% |
if y < -5.5999999999999999e27 or -6.0000000000000003e-221 < y < 6.1999999999999998e-271Initial program 65.2%
Simplified65.3%
[Start]65.2% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]65.3% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around inf 48.5%
Applied egg-rr45.0%
[Start]48.5% | \[ 2 \cdot \sqrt{\left(y + z\right) \cdot x}
\] |
|---|---|
pow1/2 [=>]48.6% | \[ 2 \cdot \color{blue}{{\left(\left(y + z\right) \cdot x\right)}^{0.5}}
\] |
pow-to-exp [=>]45.0% | \[ 2 \cdot \color{blue}{e^{\log \left(\left(y + z\right) \cdot x\right) \cdot 0.5}}
\] |
*-commutative [=>]45.0% | \[ 2 \cdot e^{\log \color{blue}{\left(x \cdot \left(y + z\right)\right)} \cdot 0.5}
\] |
Taylor expanded in x around -inf 44.2%
Simplified44.2%
[Start]44.2% | \[ 2 \cdot e^{\left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log \left(-1 \cdot \left(y + z\right)\right)\right) \cdot 0.5}
\] |
|---|---|
+-commutative [=>]44.2% | \[ 2 \cdot e^{\color{blue}{\left(\log \left(-1 \cdot \left(y + z\right)\right) + -1 \cdot \log \left(\frac{-1}{x}\right)\right)} \cdot 0.5}
\] |
mul-1-neg [=>]44.2% | \[ 2 \cdot e^{\left(\log \left(-1 \cdot \left(y + z\right)\right) + \color{blue}{\left(-\log \left(\frac{-1}{x}\right)\right)}\right) \cdot 0.5}
\] |
unsub-neg [=>]44.2% | \[ 2 \cdot e^{\color{blue}{\left(\log \left(-1 \cdot \left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)} \cdot 0.5}
\] |
distribute-lft-in [=>]44.2% | \[ 2 \cdot e^{\left(\log \color{blue}{\left(-1 \cdot y + -1 \cdot z\right)} - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
neg-mul-1 [<=]44.2% | \[ 2 \cdot e^{\left(\log \left(-1 \cdot y + \color{blue}{\left(-z\right)}\right) - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
unsub-neg [=>]44.2% | \[ 2 \cdot e^{\left(\log \color{blue}{\left(-1 \cdot y - z\right)} - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
mul-1-neg [=>]44.2% | \[ 2 \cdot e^{\left(\log \left(\color{blue}{\left(-y\right)} - z\right) - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
if -5.5999999999999999e27 < y < -6.0000000000000003e-221Initial program 83.8%
Simplified83.8%
[Start]83.8% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]83.8% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around inf 47.2%
if 6.1999999999999998e-271 < y Initial program 70.3%
Simplified70.3%
[Start]70.3% | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]70.3% | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around 0 28.0%
Applied egg-rr35.7%
[Start]28.0% | \[ 2 \cdot \sqrt{y \cdot z}
\] |
|---|---|
*-commutative [=>]28.0% | \[ 2 \cdot \sqrt{\color{blue}{z \cdot y}}
\] |
sqrt-prod [=>]35.7% | \[ 2 \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{y}\right)}
\] |
Final simplification40.5%
| Alternative 1 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 20364 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.2% |
| Cost | 19972 |
| Alternative 3 | |
|---|---|
| Accuracy | 89.3% |
| Cost | 13892 |
| Alternative 4 | |
|---|---|
| Accuracy | 89.2% |
| Cost | 13892 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 13508 |
| Alternative 6 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 13252 |
| Alternative 7 | |
|---|---|
| Accuracy | 70.3% |
| Cost | 7104 |
| Alternative 8 | |
|---|---|
| Accuracy | 69.0% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Accuracy | 70.2% |
| Cost | 6980 |
| Alternative 10 | |
|---|---|
| Accuracy | 68.0% |
| Cost | 6916 |
| Alternative 11 | |
|---|---|
| Accuracy | 68.0% |
| Cost | 6852 |
| Alternative 12 | |
|---|---|
| Accuracy | 35.2% |
| Cost | 6720 |
herbie shell --seed 2023271
(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)))))