| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 19972 |
(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
(FPCore (x y z)
:precision binary64
(if (<= y -1.4e+154)
(* 2.0 (exp (* (- (log (- x)) (log (/ -1.0 y))) 0.5)))
(if (<= y -4.8e-43)
(* 2.0 (/ (sqrt (* (- y z) (+ y z))) (sqrt (/ (- y z) x))))
(if (<= y 5.6e-271)
(* 2.0 (exp (* 0.5 (- (log (- (- y) z)) (log (/ -1.0 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 <= -1.4e+154) {
tmp = 2.0 * exp(((log(-x) - log((-1.0 / y))) * 0.5));
} else if (y <= -4.8e-43) {
tmp = 2.0 * (sqrt(((y - z) * (y + z))) / sqrt(((y - z) / x)));
} else if (y <= 5.6e-271) {
tmp = 2.0 * exp((0.5 * (log((-y - z)) - log((-1.0 / 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 <= (-1.4d+154)) then
tmp = 2.0d0 * exp(((log(-x) - log(((-1.0d0) / y))) * 0.5d0))
else if (y <= (-4.8d-43)) then
tmp = 2.0d0 * (sqrt(((y - z) * (y + z))) / sqrt(((y - z) / x)))
else if (y <= 5.6d-271) then
tmp = 2.0d0 * exp((0.5d0 * (log((-y - z)) - log(((-1.0d0) / 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 <= -1.4e+154) {
tmp = 2.0 * Math.exp(((Math.log(-x) - Math.log((-1.0 / y))) * 0.5));
} else if (y <= -4.8e-43) {
tmp = 2.0 * (Math.sqrt(((y - z) * (y + z))) / Math.sqrt(((y - z) / x)));
} else if (y <= 5.6e-271) {
tmp = 2.0 * Math.exp((0.5 * (Math.log((-y - z)) - Math.log((-1.0 / 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 <= -1.4e+154: tmp = 2.0 * math.exp(((math.log(-x) - math.log((-1.0 / y))) * 0.5)) elif y <= -4.8e-43: tmp = 2.0 * (math.sqrt(((y - z) * (y + z))) / math.sqrt(((y - z) / x))) elif y <= 5.6e-271: tmp = 2.0 * math.exp((0.5 * (math.log((-y - z)) - math.log((-1.0 / 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 <= -1.4e+154) tmp = Float64(2.0 * exp(Float64(Float64(log(Float64(-x)) - log(Float64(-1.0 / y))) * 0.5))); elseif (y <= -4.8e-43) tmp = Float64(2.0 * Float64(sqrt(Float64(Float64(y - z) * Float64(y + z))) / sqrt(Float64(Float64(y - z) / x)))); elseif (y <= 5.6e-271) tmp = Float64(2.0 * exp(Float64(0.5 * Float64(log(Float64(Float64(-y) - z)) - log(Float64(-1.0 / 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 <= -1.4e+154) tmp = 2.0 * exp(((log(-x) - log((-1.0 / y))) * 0.5)); elseif (y <= -4.8e-43) tmp = 2.0 * (sqrt(((y - z) * (y + z))) / sqrt(((y - z) / x))); elseif (y <= 5.6e-271) tmp = 2.0 * exp((0.5 * (log((-y - z)) - log((-1.0 / 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, -1.4e+154], N[(2.0 * N[Exp[N[(N[(N[Log[(-x)], $MachinePrecision] - N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -4.8e-43], N[(2.0 * N[(N[Sqrt[N[(N[(y - z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(y - z), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.6e-271], N[(2.0 * N[Exp[N[(0.5 * N[(N[Log[N[((-y) - z), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / x), $MachinePrecision]], $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 -1.4 \cdot 10^{+154}:\\
\;\;\;\;2 \cdot e^{\left(\log \left(-x\right) - \log \left(\frac{-1}{y}\right)\right) \cdot 0.5}\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-43}:\\
\;\;\;\;2 \cdot \frac{\sqrt{\left(y - z\right) \cdot \left(y + z\right)}}{\sqrt{\frac{y - z}{x}}}\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-271}:\\
\;\;\;\;2 \cdot e^{0.5 \cdot \left(\log \left(\left(-y\right) - z\right) - \log \left(\frac{-1}{x}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\
\end{array}
Results
| Original | 68.7% |
|---|---|
| Target | 82.1% |
| Herbie | 94.8% |
if y < -1.4e154Initial program 0.0%
Simplified0.0%
[Start]0.0 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]0.0 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around inf 0.0%
Applied egg-rr0.0%
[Start]0.0 | \[ 2 \cdot \sqrt{\left(y + z\right) \cdot x}
\] |
|---|---|
pow1/2 [=>]0.0 | \[ 2 \cdot \color{blue}{{\left(\left(y + z\right) \cdot x\right)}^{0.5}}
\] |
pow-to-exp [=>]0.0 | \[ 2 \cdot \color{blue}{e^{\log \left(\left(y + z\right) \cdot x\right) \cdot 0.5}}
\] |
Taylor expanded in y around -inf 87.8%
Simplified87.8%
[Start]87.8 | \[ 2 \cdot e^{\left(-1 \cdot \log \left(\frac{-1}{y}\right) + \log \left(-1 \cdot x\right)\right) \cdot 0.5}
\] |
|---|---|
+-commutative [=>]87.8 | \[ 2 \cdot e^{\color{blue}{\left(\log \left(-1 \cdot x\right) + -1 \cdot \log \left(\frac{-1}{y}\right)\right)} \cdot 0.5}
\] |
mul-1-neg [=>]87.8 | \[ 2 \cdot e^{\left(\log \left(-1 \cdot x\right) + \color{blue}{\left(-\log \left(\frac{-1}{y}\right)\right)}\right) \cdot 0.5}
\] |
unsub-neg [=>]87.8 | \[ 2 \cdot e^{\color{blue}{\left(\log \left(-1 \cdot x\right) - \log \left(\frac{-1}{y}\right)\right)} \cdot 0.5}
\] |
mul-1-neg [=>]87.8 | \[ 2 \cdot e^{\left(\log \color{blue}{\left(-x\right)} - \log \left(\frac{-1}{y}\right)\right) \cdot 0.5}
\] |
if -1.4e154 < y < -4.8000000000000004e-43Initial program 69.6%
Simplified69.6%
[Start]69.6 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]69.6 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around inf 69.5%
Applied egg-rr51.3%
[Start]69.5 | \[ 2 \cdot \sqrt{\left(y + z\right) \cdot x}
\] |
|---|---|
flip-+ [=>]69.5 | \[ 2 \cdot \sqrt{\color{blue}{\frac{y \cdot y - z \cdot z}{y - z}} \cdot x}
\] |
associate-*l/ [=>]51.3 | \[ 2 \cdot \sqrt{\color{blue}{\frac{\left(y \cdot y - z \cdot z\right) \cdot x}{y - z}}}
\] |
Applied egg-rr98.9%
[Start]51.3 | \[ 2 \cdot \sqrt{\frac{\left(y \cdot y - z \cdot z\right) \cdot x}{y - z}}
\] |
|---|---|
associate-/l* [=>]68.8 | \[ 2 \cdot \sqrt{\color{blue}{\frac{y \cdot y - z \cdot z}{\frac{y - z}{x}}}}
\] |
sqrt-div [=>]98.9 | \[ 2 \cdot \color{blue}{\frac{\sqrt{y \cdot y - z \cdot z}}{\sqrt{\frac{y - z}{x}}}}
\] |
difference-of-squares [=>]98.9 | \[ 2 \cdot \frac{\sqrt{\color{blue}{\left(y + z\right) \cdot \left(y - z\right)}}}{\sqrt{\frac{y - z}{x}}}
\] |
*-commutative [=>]98.9 | \[ 2 \cdot \frac{\sqrt{\color{blue}{\left(y - z\right) \cdot \left(y + z\right)}}}{\sqrt{\frac{y - z}{x}}}
\] |
Simplified98.9%
[Start]98.9 | \[ 2 \cdot \frac{\sqrt{\left(y - z\right) \cdot \left(y + z\right)}}{\sqrt{\frac{y - z}{x}}}
\] |
|---|---|
+-commutative [=>]98.9 | \[ 2 \cdot \frac{\sqrt{\left(y - z\right) \cdot \color{blue}{\left(z + y\right)}}}{\sqrt{\frac{y - z}{x}}}
\] |
if -4.8000000000000004e-43 < y < 5.5999999999999995e-271Initial program 93.1%
Simplified93.1%
[Start]93.1 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]93.1 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around inf 91.5%
Applied egg-rr85.6%
[Start]91.5 | \[ 2 \cdot \sqrt{\left(y + z\right) \cdot x}
\] |
|---|---|
pow1/2 [=>]91.5 | \[ 2 \cdot \color{blue}{{\left(\left(y + z\right) \cdot x\right)}^{0.5}}
\] |
pow-to-exp [=>]85.6 | \[ 2 \cdot \color{blue}{e^{\log \left(\left(y + z\right) \cdot x\right) \cdot 0.5}}
\] |
Taylor expanded in x around -inf 88.4%
Simplified88.4%
[Start]88.4 | \[ 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 [=>]88.4 | \[ 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 [=>]88.4 | \[ 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 [=>]88.4 | \[ 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}
\] |
mul-1-neg [=>]88.4 | \[ 2 \cdot e^{\left(\log \color{blue}{\left(-\left(y + z\right)\right)} - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
neg-sub0 [=>]88.4 | \[ 2 \cdot e^{\left(\log \color{blue}{\left(0 - \left(y + z\right)\right)} - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
associate--r+ [=>]88.4 | \[ 2 \cdot e^{\left(\log \color{blue}{\left(\left(0 - y\right) - z\right)} - \log \left(\frac{-1}{x}\right)\right) \cdot 0.5}
\] |
neg-sub0 [<=]88.4 | \[ 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.5999999999999995e-271 < y Initial program 69.1%
Simplified69.1%
[Start]69.1 | \[ 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\] |
|---|---|
distribute-lft-out [=>]69.1 | \[ 2 \cdot \sqrt{\color{blue}{x \cdot \left(y + z\right)} + y \cdot z}
\] |
Taylor expanded in x around 0 66.8%
Applied egg-rr96.7%
[Start]66.8 | \[ 2 \cdot \sqrt{y \cdot z}
\] |
|---|---|
sqrt-prod [=>]96.7 | \[ 2 \cdot \color{blue}{\left(\sqrt{y} \cdot \sqrt{z}\right)}
\] |
*-commutative [=>]96.7 | \[ 2 \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{y}\right)}
\] |
Final simplification94.8%
| Alternative 1 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 19972 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 14665 |
| Alternative 3 | |
|---|---|
| Accuracy | 88.7% |
| Cost | 13892 |
| Alternative 4 | |
|---|---|
| Accuracy | 88.6% |
| Cost | 13764 |
| Alternative 5 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 7108 |
| Alternative 6 | |
|---|---|
| Accuracy | 68.7% |
| Cost | 7104 |
| Alternative 7 | |
|---|---|
| Accuracy | 68.7% |
| Cost | 7104 |
| Alternative 8 | |
|---|---|
| Accuracy | 67.6% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 6980 |
| Alternative 10 | |
|---|---|
| Accuracy | 66.5% |
| Cost | 6852 |
| Alternative 11 | |
|---|---|
| Accuracy | 34.1% |
| Cost | 6720 |
herbie shell --seed 2023135
(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)))))