| Alternative 1 | |
|---|---|
| Error | 1.5 |
| Cost | 7236 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 0.076:\\
\;\;\;\;-6 + \left(x \cdot -6 + \sqrt{x} \cdot 24\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 6}{\left(x + 1\right) + \sqrt{x} \cdot 4}\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
(FPCore (x) :precision binary64 (/ (+ x -1.0) (/ (+ (- -1.0 x) (* (sqrt x) -4.0)) -6.0)))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
double code(double x) {
return (x + -1.0) / (((-1.0 - x) + (sqrt(x) * -4.0)) / -6.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (-1.0d0)) / ((((-1.0d0) - x) + (sqrt(x) * (-4.0d0))) / (-6.0d0))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
public static double code(double x) {
return (x + -1.0) / (((-1.0 - x) + (Math.sqrt(x) * -4.0)) / -6.0);
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
def code(x): return (x + -1.0) / (((-1.0 - x) + (math.sqrt(x) * -4.0)) / -6.0)
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function code(x) return Float64(Float64(x + -1.0) / Float64(Float64(Float64(-1.0 - x) + Float64(sqrt(x) * -4.0)) / -6.0)) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
function tmp = code(x) tmp = (x + -1.0) / (((-1.0 - x) + (sqrt(x) * -4.0)) / -6.0); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x + -1.0), $MachinePrecision] / N[(N[(N[(-1.0 - x), $MachinePrecision] + N[(N[Sqrt[x], $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision] / -6.0), $MachinePrecision]), $MachinePrecision]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\frac{x + -1}{\frac{\left(-1 - x\right) + \sqrt{x} \cdot -4}{-6}}
Results
| Original | 0.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.0 |
Initial program 0.2
Applied egg-rr0.3
Simplified0.1
[Start]0.3 | \[ \left(\left(x + -1\right) \cdot -6\right) \cdot \frac{1}{-1 - \left(x + \sqrt{x \cdot 16}\right)}
\] |
|---|---|
*-commutative [=>]0.3 | \[ \color{blue}{\frac{1}{-1 - \left(x + \sqrt{x \cdot 16}\right)} \cdot \left(\left(x + -1\right) \cdot -6\right)}
\] |
associate-*r* [=>]0.2 | \[ \color{blue}{\left(\frac{1}{-1 - \left(x + \sqrt{x \cdot 16}\right)} \cdot \left(x + -1\right)\right) \cdot -6}
\] |
*-commutative [=>]0.2 | \[ \color{blue}{-6 \cdot \left(\frac{1}{-1 - \left(x + \sqrt{x \cdot 16}\right)} \cdot \left(x + -1\right)\right)}
\] |
associate-*l/ [=>]0.1 | \[ -6 \cdot \color{blue}{\frac{1 \cdot \left(x + -1\right)}{-1 - \left(x + \sqrt{x \cdot 16}\right)}}
\] |
*-lft-identity [=>]0.1 | \[ -6 \cdot \frac{\color{blue}{x + -1}}{-1 - \left(x + \sqrt{x \cdot 16}\right)}
\] |
associate--r+ [=>]0.1 | \[ -6 \cdot \frac{x + -1}{\color{blue}{\left(-1 - x\right) - \sqrt{x \cdot 16}}}
\] |
Applied egg-rr0.0
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 1.5 |
| Cost | 7236 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Error | 2.1 |
| Cost | 7108 |
| Alternative 4 | |
|---|---|
| Error | 2.7 |
| Cost | 2240 |
| Alternative 5 | |
|---|---|
| Error | 2.7 |
| Cost | 576 |
| Alternative 6 | |
|---|---|
| Error | 2.7 |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 2.7 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 2.7 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 2.7 |
| Cost | 196 |
| Alternative 10 | |
|---|---|
| Error | 32.8 |
| Cost | 64 |
herbie shell --seed 2023016
(FPCore (x)
:name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
:precision binary64
:herbie-target
(/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0)))
(/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))