| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 27332 |
(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x)
:precision binary64
(let* ((t_0 (* 0.25 (pow x 4.0))))
(if (<= (+ 1.0 x) 2.0)
(/
(+
(* (pow x 4.0) 0.25)
(+
(+
(+ (pow x 2.0) (+ t_0 (* -2.0 x)))
(- (* -0.6666666666666666 (pow x 3.0)) t_0))
t_0))
-2.0)
(log (+ 1.0 x)))))double code(double x) {
return log((1.0 + x));
}
double code(double x) {
double t_0 = 0.25 * pow(x, 4.0);
double tmp;
if ((1.0 + x) <= 2.0) {
tmp = ((pow(x, 4.0) * 0.25) + (((pow(x, 2.0) + (t_0 + (-2.0 * x))) + ((-0.6666666666666666 * pow(x, 3.0)) - t_0)) + t_0)) / -2.0;
} else {
tmp = log((1.0 + x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 + x))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 0.25d0 * (x ** 4.0d0)
if ((1.0d0 + x) <= 2.0d0) then
tmp = (((x ** 4.0d0) * 0.25d0) + ((((x ** 2.0d0) + (t_0 + ((-2.0d0) * x))) + (((-0.6666666666666666d0) * (x ** 3.0d0)) - t_0)) + t_0)) / (-2.0d0)
else
tmp = log((1.0d0 + x))
end if
code = tmp
end function
public static double code(double x) {
return Math.log((1.0 + x));
}
public static double code(double x) {
double t_0 = 0.25 * Math.pow(x, 4.0);
double tmp;
if ((1.0 + x) <= 2.0) {
tmp = ((Math.pow(x, 4.0) * 0.25) + (((Math.pow(x, 2.0) + (t_0 + (-2.0 * x))) + ((-0.6666666666666666 * Math.pow(x, 3.0)) - t_0)) + t_0)) / -2.0;
} else {
tmp = Math.log((1.0 + x));
}
return tmp;
}
def code(x): return math.log((1.0 + x))
def code(x): t_0 = 0.25 * math.pow(x, 4.0) tmp = 0 if (1.0 + x) <= 2.0: tmp = ((math.pow(x, 4.0) * 0.25) + (((math.pow(x, 2.0) + (t_0 + (-2.0 * x))) + ((-0.6666666666666666 * math.pow(x, 3.0)) - t_0)) + t_0)) / -2.0 else: tmp = math.log((1.0 + x)) return tmp
function code(x) return log(Float64(1.0 + x)) end
function code(x) t_0 = Float64(0.25 * (x ^ 4.0)) tmp = 0.0 if (Float64(1.0 + x) <= 2.0) tmp = Float64(Float64(Float64((x ^ 4.0) * 0.25) + Float64(Float64(Float64((x ^ 2.0) + Float64(t_0 + Float64(-2.0 * x))) + Float64(Float64(-0.6666666666666666 * (x ^ 3.0)) - t_0)) + t_0)) / -2.0); else tmp = log(Float64(1.0 + x)); end return tmp end
function tmp = code(x) tmp = log((1.0 + x)); end
function tmp_2 = code(x) t_0 = 0.25 * (x ^ 4.0); tmp = 0.0; if ((1.0 + x) <= 2.0) tmp = (((x ^ 4.0) * 0.25) + ((((x ^ 2.0) + (t_0 + (-2.0 * x))) + ((-0.6666666666666666 * (x ^ 3.0)) - t_0)) + t_0)) / -2.0; else tmp = log((1.0 + x)); end tmp_2 = tmp; end
code[x_] := N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(0.25 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 + x), $MachinePrecision], 2.0], N[(N[(N[(N[Power[x, 4.0], $MachinePrecision] * 0.25), $MachinePrecision] + N[(N[(N[(N[Power[x, 2.0], $MachinePrecision] + N[(t$95$0 + N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.6666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / -2.0), $MachinePrecision], N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]]]
\log \left(1 + x\right)
\begin{array}{l}
t_0 := 0.25 \cdot {x}^{4}\\
\mathbf{if}\;1 + x \leq 2:\\
\;\;\;\;\frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(t_0 + -2 \cdot x\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} - t_0\right)\right) + t_0\right)}{-2}\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}
Results
| Original | 38.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.2 |
if (+.f64 1 x) < 2Initial program 58.6
Taylor expanded in x around 0 0.3
Simplified0.3
[Start]0.3 | \[ -0.5 \cdot {x}^{2} + \left(0.3333333333333333 \cdot {x}^{3} + \left(-0.25 \cdot {x}^{4} + x\right)\right)
\] |
|---|---|
rational_best-simplify-115 [=>]0.3 | \[ -0.5 \cdot {x}^{2} + \color{blue}{\left(-0.25 \cdot {x}^{4} + \left(x + 0.3333333333333333 \cdot {x}^{3}\right)\right)}
\] |
rational_best-simplify-1 [<=]0.3 | \[ -0.5 \cdot {x}^{2} + \left(-0.25 \cdot {x}^{4} + \color{blue}{\left(0.3333333333333333 \cdot {x}^{3} + x\right)}\right)
\] |
rational_best-simplify-115 [=>]0.3 | \[ \color{blue}{-0.25 \cdot {x}^{4} + \left(\left(0.3333333333333333 \cdot {x}^{3} + x\right) + -0.5 \cdot {x}^{2}\right)}
\] |
rational_best-simplify-1 [<=]0.3 | \[ -0.25 \cdot {x}^{4} + \color{blue}{\left(-0.5 \cdot {x}^{2} + \left(0.3333333333333333 \cdot {x}^{3} + x\right)\right)}
\] |
rational_best-simplify-62 [=>]0.3 | \[ \color{blue}{\left(-0.5 \cdot {x}^{2} + \left(0.3333333333333333 \cdot {x}^{3} + x\right)\right) - \left(--0.25 \cdot {x}^{4}\right)}
\] |
rational_best-simplify-1 [=>]0.3 | \[ \left(-0.5 \cdot {x}^{2} + \color{blue}{\left(x + 0.3333333333333333 \cdot {x}^{3}\right)}\right) - \left(--0.25 \cdot {x}^{4}\right)
\] |
rational_best-simplify-52 [=>]0.3 | \[ \left(-0.5 \cdot {x}^{2} + \left(x + 0.3333333333333333 \cdot {x}^{3}\right)\right) - \color{blue}{{x}^{4} \cdot \left(--0.25\right)}
\] |
metadata-eval [=>]0.3 | \[ \left(-0.5 \cdot {x}^{2} + \left(x + 0.3333333333333333 \cdot {x}^{3}\right)\right) - {x}^{4} \cdot \color{blue}{0.25}
\] |
Applied egg-rr0.3
Taylor expanded in x around 0 0.3
Simplified0.3
[Start]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(0.25 \cdot {x}^{4} + \left(-2 \cdot x + \left(-0.6666666666666666 \cdot {x}^{3} + {x}^{2}\right)\right)\right)}{-2}
\] |
|---|---|
rational_best-simplify-1 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \color{blue}{\left(\left(-2 \cdot x + \left(-0.6666666666666666 \cdot {x}^{3} + {x}^{2}\right)\right) + 0.25 \cdot {x}^{4}\right)}}{-2}
\] |
rational_best-simplify-3 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(-2 \cdot x + \left(\color{blue}{{x}^{3} \cdot -0.6666666666666666} + {x}^{2}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-116 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\color{blue}{\left({x}^{2} + \left(-2 \cdot x + {x}^{3} \cdot -0.6666666666666666\right)\right)} + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-3 [<=]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left({x}^{2} + \left(-2 \cdot x + \color{blue}{-0.6666666666666666 \cdot {x}^{3}}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left(-0.6666666666666666 \cdot {x}^{3} + -0.25 \cdot {x}^{4}\right) - \left(-\left({x}^{2} + \left(x \cdot -2 + 0.25 \cdot {x}^{4}\right)\right)\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
|---|---|
rational_best-simplify-63 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\color{blue}{\left(\left({x}^{2} + \left(x \cdot -2 + 0.25 \cdot {x}^{4}\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} + -0.25 \cdot {x}^{4}\right)\right)} + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-1 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \color{blue}{\left(0.25 \cdot {x}^{4} + x \cdot -2\right)}\right) + \left(-0.6666666666666666 \cdot {x}^{3} + -0.25 \cdot {x}^{4}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-3 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + \color{blue}{-2 \cdot x}\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} + -0.25 \cdot {x}^{4}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-1 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + -2 \cdot x\right)\right) + \color{blue}{\left(-0.25 \cdot {x}^{4} + -0.6666666666666666 \cdot {x}^{3}\right)}\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-62 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + -2 \cdot x\right)\right) + \color{blue}{\left(-0.6666666666666666 \cdot {x}^{3} - \left(--0.25 \cdot {x}^{4}\right)\right)}\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-52 [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + -2 \cdot x\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} - \color{blue}{{x}^{4} \cdot \left(--0.25\right)}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
metadata-eval [=>]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + -2 \cdot x\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} - {x}^{4} \cdot \color{blue}{0.25}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
rational_best-simplify-3 [<=]0.3 | \[ \frac{{x}^{4} \cdot 0.25 + \left(\left(\left({x}^{2} + \left(0.25 \cdot {x}^{4} + -2 \cdot x\right)\right) + \left(-0.6666666666666666 \cdot {x}^{3} - \color{blue}{0.25 \cdot {x}^{4}}\right)\right) + 0.25 \cdot {x}^{4}\right)}{-2}
\] |
if 2 < (+.f64 1 x) Initial program 0.0
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 27332 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 20484 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 13764 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 7044 |
| Alternative 5 | |
|---|---|
| Error | 0.8 |
| Cost | 6852 |
| Alternative 6 | |
|---|---|
| Error | 21.5 |
| Cost | 64 |
herbie shell --seed 2023104
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))