| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 576 |
\[\frac{0.25}{4 + \frac{-1}{i \cdot i}}
\]
(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(i * Float64(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[(i * N[(i * -0.25), $MachinePrecision]), $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:\\
\;\;\;\;i \cdot \left(i \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625 + \frac{0.015625}{i \cdot i}\\
\end{array}
Results
if i < 0.5Initial program 44.7
Simplified39.9
[Start]44.7 | \[ \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}
\] |
|---|---|
associate-/r* [=>]14.7 | \[ \frac{\color{blue}{\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{2 \cdot i}}{2 \cdot i}}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
associate-/l/ [=>]14.7 | \[ \color{blue}{\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{2 \cdot i}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}}
\] |
*-commutative [=>]14.7 | \[ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\color{blue}{i \cdot 2}}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}
\] |
times-frac [=>]9.8 | \[ \frac{\color{blue}{\frac{i \cdot i}{i} \cdot \frac{i \cdot i}{2}}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}
\] |
times-frac [=>]0.1 | \[ \color{blue}{\frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \frac{\frac{i \cdot i}{2}}{2 \cdot i}}
\] |
associate-/r* [<=]0.1 | \[ \frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \color{blue}{\frac{i \cdot i}{2 \cdot \left(2 \cdot i\right)}}
\] |
*-commutative [<=]0.1 | \[ \frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \frac{i \cdot i}{\color{blue}{\left(2 \cdot i\right) \cdot 2}}
\] |
Taylor expanded in i around 0 0.7
Simplified0.7
[Start]0.7 | \[ -0.25 \cdot {i}^{2}
\] |
|---|---|
*-commutative [=>]0.7 | \[ \color{blue}{{i}^{2} \cdot -0.25}
\] |
unpow2 [=>]0.7 | \[ \color{blue}{\left(i \cdot i\right)} \cdot -0.25
\] |
associate-*l* [=>]0.7 | \[ \color{blue}{i \cdot \left(i \cdot -0.25\right)}
\] |
if 0.5 < i Initial program 48.0
Simplified43.0
[Start]48.0 | \[ \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}
\] |
|---|---|
associate-/r* [=>]48.0 | \[ \frac{\color{blue}{\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{2 \cdot i}}{2 \cdot i}}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1}
\] |
associate-/l/ [=>]48.0 | \[ \color{blue}{\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{2 \cdot i}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}}
\] |
*-commutative [=>]48.0 | \[ \frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{\color{blue}{i \cdot 2}}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}
\] |
times-frac [=>]42.9 | \[ \frac{\color{blue}{\frac{i \cdot i}{i} \cdot \frac{i \cdot i}{2}}}{\left(\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1\right) \cdot \left(2 \cdot i\right)}
\] |
times-frac [=>]32.3 | \[ \color{blue}{\frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \frac{\frac{i \cdot i}{2}}{2 \cdot i}}
\] |
associate-/r* [<=]32.3 | \[ \frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \color{blue}{\frac{i \cdot i}{2 \cdot \left(2 \cdot i\right)}}
\] |
*-commutative [<=]32.3 | \[ \frac{\frac{i \cdot i}{i}}{\left(2 \cdot i\right) \cdot \left(2 \cdot i\right) - 1} \cdot \frac{i \cdot i}{\color{blue}{\left(2 \cdot i\right) \cdot 2}}
\] |
Taylor expanded in i around inf 0.3
Simplified0.3
[Start]0.3 | \[ 0.0625 + 0.015625 \cdot \frac{1}{{i}^{2}}
\] |
|---|---|
associate-*r/ [=>]0.3 | \[ 0.0625 + \color{blue}{\frac{0.015625 \cdot 1}{{i}^{2}}}
\] |
metadata-eval [=>]0.3 | \[ 0.0625 + \frac{\color{blue}{0.015625}}{{i}^{2}}
\] |
unpow2 [=>]0.3 | \[ 0.0625 + \frac{0.015625}{\color{blue}{i \cdot i}}
\] |
Final simplification0.5
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Error | 0.7 |
| Cost | 452 |
| Alternative 3 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023046
(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)))