| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 1984 |
(FPCore (t) :precision binary64 (/ (+ 1.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t)))) (+ 2.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t))))))
(FPCore (t) :precision binary64 (if (<= t -0.8) (- 0.8333333333333334 (/ 0.2222222222222222 t)) (if (<= t 0.58) (+ (* t t) 0.5) 0.8333333333333334)))
double code(double t) {
return (1.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t)))) / (2.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t))));
}
double code(double t) {
double tmp;
if (t <= -0.8) {
tmp = 0.8333333333333334 - (0.2222222222222222 / t);
} else if (t <= 0.58) {
tmp = (t * t) + 0.5;
} else {
tmp = 0.8333333333333334;
}
return tmp;
}
real(8) function code(t)
real(8), intent (in) :: t
code = (1.0d0 + (((2.0d0 * t) / (1.0d0 + t)) * ((2.0d0 * t) / (1.0d0 + t)))) / (2.0d0 + (((2.0d0 * t) / (1.0d0 + t)) * ((2.0d0 * t) / (1.0d0 + t))))
end function
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-0.8d0)) then
tmp = 0.8333333333333334d0 - (0.2222222222222222d0 / t)
else if (t <= 0.58d0) then
tmp = (t * t) + 0.5d0
else
tmp = 0.8333333333333334d0
end if
code = tmp
end function
public static double code(double t) {
return (1.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t)))) / (2.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t))));
}
public static double code(double t) {
double tmp;
if (t <= -0.8) {
tmp = 0.8333333333333334 - (0.2222222222222222 / t);
} else if (t <= 0.58) {
tmp = (t * t) + 0.5;
} else {
tmp = 0.8333333333333334;
}
return tmp;
}
def code(t): return (1.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t)))) / (2.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t))))
def code(t): tmp = 0 if t <= -0.8: tmp = 0.8333333333333334 - (0.2222222222222222 / t) elif t <= 0.58: tmp = (t * t) + 0.5 else: tmp = 0.8333333333333334 return tmp
function code(t) return Float64(Float64(1.0 + Float64(Float64(Float64(2.0 * t) / Float64(1.0 + t)) * Float64(Float64(2.0 * t) / Float64(1.0 + t)))) / Float64(2.0 + Float64(Float64(Float64(2.0 * t) / Float64(1.0 + t)) * Float64(Float64(2.0 * t) / Float64(1.0 + t))))) end
function code(t) tmp = 0.0 if (t <= -0.8) tmp = Float64(0.8333333333333334 - Float64(0.2222222222222222 / t)); elseif (t <= 0.58) tmp = Float64(Float64(t * t) + 0.5); else tmp = 0.8333333333333334; end return tmp end
function tmp = code(t) tmp = (1.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t)))) / (2.0 + (((2.0 * t) / (1.0 + t)) * ((2.0 * t) / (1.0 + t)))); end
function tmp_2 = code(t) tmp = 0.0; if (t <= -0.8) tmp = 0.8333333333333334 - (0.2222222222222222 / t); elseif (t <= 0.58) tmp = (t * t) + 0.5; else tmp = 0.8333333333333334; end tmp_2 = tmp; end
code[t_] := N[(N[(1.0 + N[(N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision] * N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision] * N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[t_] := If[LessEqual[t, -0.8], N[(0.8333333333333334 - N[(0.2222222222222222 / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 0.58], N[(N[(t * t), $MachinePrecision] + 0.5), $MachinePrecision], 0.8333333333333334]]
\frac{1 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\begin{array}{l}
\mathbf{if}\;t \leq -0.8:\\
\;\;\;\;0.8333333333333334 - \frac{0.2222222222222222}{t}\\
\mathbf{elif}\;t \leq 0.58:\\
\;\;\;\;t \cdot t + 0.5\\
\mathbf{else}:\\
\;\;\;\;0.8333333333333334\\
\end{array}
Results
if t < -0.80000000000000004Initial program 100.0%
Simplified99.8%
[Start]100.0 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
|---|---|
associate-/l* [=>]100.0 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{1 + t} \cdot t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [<=]100.0 | \[ \frac{1 + \color{blue}{\left(\frac{\frac{2 \cdot t}{1 + t}}{1 + t} \cdot 2\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]100.0 | \[ \frac{1 + \color{blue}{\left(2 \cdot \frac{\frac{2 \cdot t}{1 + t}}{1 + t}\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{2 \cdot \frac{2 \cdot t}{1 + t}}{1 + t}} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]100.0 | \[ \frac{1 + \frac{\color{blue}{\frac{2 \cdot t}{1 + t} \cdot 2}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [=>]99.8 | \[ \frac{1 + \frac{\color{blue}{\frac{\left(2 \cdot t\right) \cdot 2}{1 + t}}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]99.8 | \[ \frac{1 + \frac{\frac{\color{blue}{\left(t \cdot 2\right)} \cdot 2}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l* [=>]99.8 | \[ \frac{1 + \frac{\frac{\color{blue}{t \cdot \left(2 \cdot 2\right)}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
metadata-eval [=>]99.8 | \[ \frac{1 + \frac{\frac{t \cdot \color{blue}{4}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/l* [=>]99.8 | \[ \frac{1 + \frac{\frac{t \cdot 4}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}
\] |
Taylor expanded in t around inf 99.2%
Simplified99.2%
[Start]99.2 | \[ 0.8333333333333334 - 0.2222222222222222 \cdot \frac{1}{t}
\] |
|---|---|
associate-*r/ [=>]99.2 | \[ 0.8333333333333334 - \color{blue}{\frac{0.2222222222222222 \cdot 1}{t}}
\] |
metadata-eval [=>]99.2 | \[ 0.8333333333333334 - \frac{\color{blue}{0.2222222222222222}}{t}
\] |
if -0.80000000000000004 < t < 0.57999999999999996Initial program 100.0%
Simplified100.0%
[Start]100.0 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
|---|---|
associate-/l* [=>]100.0 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{1 + t} \cdot t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [<=]100.0 | \[ \frac{1 + \color{blue}{\left(\frac{\frac{2 \cdot t}{1 + t}}{1 + t} \cdot 2\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]100.0 | \[ \frac{1 + \color{blue}{\left(2 \cdot \frac{\frac{2 \cdot t}{1 + t}}{1 + t}\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]100.0 | \[ \frac{1 + \color{blue}{\frac{2 \cdot \frac{2 \cdot t}{1 + t}}{1 + t}} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]100.0 | \[ \frac{1 + \frac{\color{blue}{\frac{2 \cdot t}{1 + t} \cdot 2}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [=>]100.0 | \[ \frac{1 + \frac{\color{blue}{\frac{\left(2 \cdot t\right) \cdot 2}{1 + t}}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]100.0 | \[ \frac{1 + \frac{\frac{\color{blue}{\left(t \cdot 2\right)} \cdot 2}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l* [=>]100.0 | \[ \frac{1 + \frac{\frac{\color{blue}{t \cdot \left(2 \cdot 2\right)}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
metadata-eval [=>]100.0 | \[ \frac{1 + \frac{\frac{t \cdot \color{blue}{4}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/l* [=>]100.0 | \[ \frac{1 + \frac{\frac{t \cdot 4}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}
\] |
Taylor expanded in t around 0 99.4%
Simplified99.4%
[Start]99.4 | \[ 0.5 + {t}^{2}
\] |
|---|---|
+-commutative [=>]99.4 | \[ \color{blue}{{t}^{2} + 0.5}
\] |
unpow2 [=>]99.4 | \[ \color{blue}{t \cdot t} + 0.5
\] |
if 0.57999999999999996 < t Initial program 99.8%
Simplified99.8%
[Start]99.8 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
|---|---|
associate-/l* [=>]99.8 | \[ \frac{1 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]99.8 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{\frac{1 + t}{t}}}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/r/ [=>]99.8 | \[ \frac{1 + \color{blue}{\frac{\frac{2 \cdot t}{1 + t} \cdot 2}{1 + t} \cdot t}}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [<=]99.8 | \[ \frac{1 + \color{blue}{\left(\frac{\frac{2 \cdot t}{1 + t}}{1 + t} \cdot 2\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]99.8 | \[ \frac{1 + \color{blue}{\left(2 \cdot \frac{\frac{2 \cdot t}{1 + t}}{1 + t}\right)} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*r/ [=>]99.8 | \[ \frac{1 + \color{blue}{\frac{2 \cdot \frac{2 \cdot t}{1 + t}}{1 + t}} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]99.8 | \[ \frac{1 + \frac{\color{blue}{\frac{2 \cdot t}{1 + t} \cdot 2}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l/ [=>]99.8 | \[ \frac{1 + \frac{\color{blue}{\frac{\left(2 \cdot t\right) \cdot 2}{1 + t}}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
*-commutative [=>]99.8 | \[ \frac{1 + \frac{\frac{\color{blue}{\left(t \cdot 2\right)} \cdot 2}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-*l* [=>]99.8 | \[ \frac{1 + \frac{\frac{\color{blue}{t \cdot \left(2 \cdot 2\right)}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
metadata-eval [=>]99.8 | \[ \frac{1 + \frac{\frac{t \cdot \color{blue}{4}}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \frac{2 \cdot t}{1 + t}}
\] |
associate-/l* [=>]99.8 | \[ \frac{1 + \frac{\frac{t \cdot 4}{1 + t}}{1 + t} \cdot t}{2 + \frac{2 \cdot t}{1 + t} \cdot \color{blue}{\frac{2}{\frac{1 + t}{t}}}}
\] |
Taylor expanded in t around inf 97.4%
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 1984 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 584 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 328 |
| Alternative 4 | |
|---|---|
| Accuracy | 59.3% |
| Cost | 64 |
herbie shell --seed 2023147
(FPCore (t)
:name "Kahan p13 Example 1"
:precision binary64
(/ (+ 1.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t)))) (+ 2.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t))))))