| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 576 |
(FPCore (i) :precision binary64 (/ (/ (* (* i i) (* i i)) (* (* 2.0 i) (* 2.0 i))) (- (* (* 2.0 i) (* 2.0 i)) 1.0)))
(FPCore (i) :precision binary64 (if (<= i 0.5) (* (* i i) -0.25) (+ 0.0625 (/ 0.015625 (* i i)))))
double code(double i) {
return (((i * i) * (i * i)) / ((2.0 * i) * (2.0 * i))) / (((2.0 * i) * (2.0 * i)) - 1.0);
}
double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = (i * i) * -0.25;
} else {
tmp = 0.0625 + (0.015625 / (i * i));
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
code = (((i * i) * (i * i)) / ((2.0d0 * i) * (2.0d0 * i))) / (((2.0d0 * i) * (2.0d0 * i)) - 1.0d0)
end function
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 0.5d0) then
tmp = (i * i) * (-0.25d0)
else
tmp = 0.0625d0 + (0.015625d0 / (i * i))
end if
code = tmp
end function
public static double code(double i) {
return (((i * i) * (i * i)) / ((2.0 * i) * (2.0 * i))) / (((2.0 * i) * (2.0 * i)) - 1.0);
}
public static double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = (i * i) * -0.25;
} else {
tmp = 0.0625 + (0.015625 / (i * i));
}
return tmp;
}
def code(i): return (((i * i) * (i * i)) / ((2.0 * i) * (2.0 * i))) / (((2.0 * i) * (2.0 * i)) - 1.0)
def code(i): tmp = 0 if i <= 0.5: tmp = (i * i) * -0.25 else: tmp = 0.0625 + (0.015625 / (i * i)) return tmp
function code(i) return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / Float64(Float64(2.0 * i) * Float64(2.0 * i))) / Float64(Float64(Float64(2.0 * i) * Float64(2.0 * i)) - 1.0)) end
function code(i) tmp = 0.0 if (i <= 0.5) tmp = Float64(Float64(i * i) * -0.25); else tmp = Float64(0.0625 + Float64(0.015625 / Float64(i * i))); end return tmp end
function tmp = code(i) tmp = (((i * i) * (i * i)) / ((2.0 * i) * (2.0 * i))) / (((2.0 * i) * (2.0 * i)) - 1.0); end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.5) tmp = (i * i) * -0.25; else tmp = 0.0625 + (0.015625 / (i * i)); end tmp_2 = tmp; end
code[i_] := N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[i_] := If[LessEqual[i, 0.5], N[(N[(i * i), $MachinePrecision] * -0.25), $MachinePrecision], N[(0.0625 + N[(0.015625 / N[(i * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\begin{array}{l}
\mathbf{if}\;i \leq 0.5:\\
\;\;\;\;\left(i \cdot i\right) \cdot -0.25\\
\mathbf{else}:\\
\;\;\;\;0.0625 + \frac{0.015625}{i \cdot i}\\
\end{array}
Results
if i < 0.5Initial program 28.9%
Simplified84.3%
[Start]28.9 | \[ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
|---|---|
times-frac [=>]99.9 | \[ \frac{\color{blue}{\frac{i \cdot i}{2 \cdot i} \cdot \frac{i \cdot i}{2 \cdot i}}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
associate-/l* [=>]99.7 | \[ \color{blue}{\frac{\frac{i \cdot i}{2 \cdot i}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}}}}
\] |
associate-/l* [=>]99.8 | \[ \frac{\color{blue}{\frac{i}{\frac{2 \cdot i}{i}}}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}}}
\] |
associate-/l/ [=>]99.8 | \[ \color{blue}{\frac{i}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}} \cdot \frac{2 \cdot i}{i}}}
\] |
associate-/r/ [=>]98.9 | \[ \frac{i}{\color{blue}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right)} \cdot \frac{2 \cdot i}{i}}
\] |
associate-/l* [=>]98.9 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \color{blue}{\frac{2}{\frac{i}{i}}}}
\] |
*-inverses [=>]98.9 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \frac{2}{\color{blue}{1}}}
\] |
metadata-eval [=>]98.9 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \color{blue}{2}}
\] |
associate-*l* [=>]98.9 | \[ \frac{i}{\color{blue}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(\left(2 \cdot i\right) \cdot 2\right)}}
\] |
*-commutative [<=]98.9 | \[ \frac{i}{\color{blue}{\left(\left(2 \cdot i\right) \cdot 2\right) \cdot \frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i}}}
\] |
associate-/r* [=>]99.0 | \[ \color{blue}{\frac{\frac{i}{\left(2 \cdot i\right) \cdot 2}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i}}}
\] |
Taylor expanded in i around 0 98.9%
Simplified98.9%
[Start]98.9 | \[ -0.25 \cdot {i}^{2}
\] |
|---|---|
*-commutative [=>]98.9 | \[ \color{blue}{{i}^{2} \cdot -0.25}
\] |
unpow2 [=>]98.9 | \[ \color{blue}{\left(i \cdot i\right)} \cdot -0.25
\] |
if 0.5 < i Initial program 24.1%
Simplified100.0%
[Start]24.1 | \[ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right)}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
|---|---|
times-frac [=>]48.7 | \[ \frac{\color{blue}{\frac{i \cdot i}{2 \cdot i} \cdot \frac{i \cdot i}{2 \cdot i}}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
associate-/l* [=>]48.7 | \[ \color{blue}{\frac{\frac{i \cdot i}{2 \cdot i}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}}}}
\] |
associate-/l* [=>]48.8 | \[ \frac{\color{blue}{\frac{i}{\frac{2 \cdot i}{i}}}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}}}
\] |
associate-/l/ [=>]48.8 | \[ \color{blue}{\frac{i}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{\frac{i \cdot i}{2 \cdot i}} \cdot \frac{2 \cdot i}{i}}}
\] |
associate-/r/ [=>]48.8 | \[ \frac{i}{\color{blue}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right)} \cdot \frac{2 \cdot i}{i}}
\] |
associate-/l* [=>]48.8 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \color{blue}{\frac{2}{\frac{i}{i}}}}
\] |
*-inverses [=>]48.8 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \frac{2}{\color{blue}{1}}}
\] |
metadata-eval [=>]48.8 | \[ \frac{i}{\left(\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(2 \cdot i\right)\right) \cdot \color{blue}{2}}
\] |
associate-*l* [=>]48.8 | \[ \frac{i}{\color{blue}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i} \cdot \left(\left(2 \cdot i\right) \cdot 2\right)}}
\] |
*-commutative [<=]48.8 | \[ \frac{i}{\color{blue}{\left(\left(2 \cdot i\right) \cdot 2\right) \cdot \frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i}}}
\] |
associate-/r* [=>]48.8 | \[ \color{blue}{\frac{\frac{i}{\left(2 \cdot i\right) \cdot 2}}{\frac{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}{i \cdot i}}}
\] |
Taylor expanded in i around inf 99.7%
Simplified99.7%
[Start]99.7 | \[ 0.0625 + 0.015625 \cdot \frac{1}{{i}^{2}}
\] |
|---|---|
associate-*r/ [=>]99.7 | \[ 0.0625 + \color{blue}{\frac{0.015625 \cdot 1}{{i}^{2}}}
\] |
metadata-eval [=>]99.7 | \[ 0.0625 + \frac{\color{blue}{0.015625}}{{i}^{2}}
\] |
unpow2 [=>]99.7 | \[ 0.0625 + \frac{0.015625}{\color{blue}{i \cdot i}}
\] |
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 452 |
| Alternative 3 | |
|---|---|
| Accuracy | 51.1% |
| Cost | 64 |
herbie shell --seed 2023146
(FPCore (i)
:name "Octave 3.8, jcobi/4, as called"
:precision binary64
:pre (> i 0.0)
(/ (/ (* (* i i) (* i i)) (* (* 2.0 i) (* 2.0 i))) (- (* (* 2.0 i) (* 2.0 i)) 1.0)))