
(FPCore (i) :precision binary64 (let* ((t_0 (* (* 2.0 i) (* 2.0 i)))) (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
t_0 = (2.0d0 * i) * (2.0d0 * i)
code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i): t_0 = (2.0 * i) * (2.0 * i) return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i) t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i)) return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0)) end
function tmp = code(i) t_0 = (2.0 * i) * (2.0 * i); tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0); end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (i) :precision binary64 (let* ((t_0 (* (* 2.0 i) (* 2.0 i)))) (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
t_0 = (2.0d0 * i) * (2.0d0 * i)
code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i): t_0 = (2.0 * i) * (2.0 * i) return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i) t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i)) return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0)) end
function tmp = code(i) t_0 = (2.0 * i) * (2.0 * i); tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0); end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{t\_0 - 1}
\end{array}
\end{array}
(FPCore (i)
:precision binary64
(let* ((t_0 (* (* i 2.0) (* i 2.0))))
(if (<= i 5e-9)
(* i (* 0.25 (- i)))
(if (<= i 5000000.0)
(/ (/ (* (* i i) (* i i)) t_0) (+ -1.0 t_0))
0.0625))))
double code(double i) {
double t_0 = (i * 2.0) * (i * 2.0);
double tmp;
if (i <= 5e-9) {
tmp = i * (0.25 * -i);
} else if (i <= 5000000.0) {
tmp = (((i * i) * (i * i)) / t_0) / (-1.0 + t_0);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
real(8) :: tmp
t_0 = (i * 2.0d0) * (i * 2.0d0)
if (i <= 5d-9) then
tmp = i * (0.25d0 * -i)
else if (i <= 5000000.0d0) then
tmp = (((i * i) * (i * i)) / t_0) / ((-1.0d0) + t_0)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double t_0 = (i * 2.0) * (i * 2.0);
double tmp;
if (i <= 5e-9) {
tmp = i * (0.25 * -i);
} else if (i <= 5000000.0) {
tmp = (((i * i) * (i * i)) / t_0) / (-1.0 + t_0);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): t_0 = (i * 2.0) * (i * 2.0) tmp = 0 if i <= 5e-9: tmp = i * (0.25 * -i) elif i <= 5000000.0: tmp = (((i * i) * (i * i)) / t_0) / (-1.0 + t_0) else: tmp = 0.0625 return tmp
function code(i) t_0 = Float64(Float64(i * 2.0) * Float64(i * 2.0)) tmp = 0.0 if (i <= 5e-9) tmp = Float64(i * Float64(0.25 * Float64(-i))); elseif (i <= 5000000.0) tmp = Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(-1.0 + t_0)); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) t_0 = (i * 2.0) * (i * 2.0); tmp = 0.0; if (i <= 5e-9) tmp = i * (0.25 * -i); elseif (i <= 5000000.0) tmp = (((i * i) * (i * i)) / t_0) / (-1.0 + t_0); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := Block[{t$95$0 = N[(N[(i * 2.0), $MachinePrecision] * N[(i * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[i, 5e-9], N[(i * N[(0.25 * (-i)), $MachinePrecision]), $MachinePrecision], If[LessEqual[i, 5000000.0], N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 0.0625]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(i \cdot 2\right) \cdot \left(i \cdot 2\right)\\
\mathbf{if}\;i \leq 5 \cdot 10^{-9}:\\
\;\;\;\;i \cdot \left(0.25 \cdot \left(-i\right)\right)\\
\mathbf{elif}\;i \leq 5000000:\\
\;\;\;\;\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0}}{-1 + t\_0}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5.0000000000000001e-9Initial program 32.3%
Simplified100.0%
associate-*r*100.0%
frac-2neg100.0%
metadata-eval100.0%
fma-neg100.0%
associate-*r*100.0%
*-commutative100.0%
metadata-eval100.0%
swap-sqr100.0%
associate-*r/100.0%
*-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-neg-in100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in i around 0 100.0%
if 5.0000000000000001e-9 < i < 5e6Initial program 99.4%
if 5e6 < i Initial program 21.4%
Simplified49.3%
Taylor expanded in i around inf 100.0%
Final simplification100.0%
(FPCore (i) :precision binary64 (if (<= i 5000000.0) (* 0.25 (* i (/ i (fma i (* i 4.0) -1.0)))) 0.0625))
double code(double i) {
double tmp;
if (i <= 5000000.0) {
tmp = 0.25 * (i * (i / fma(i, (i * 4.0), -1.0)));
} else {
tmp = 0.0625;
}
return tmp;
}
function code(i) tmp = 0.0 if (i <= 5000000.0) tmp = Float64(0.25 * Float64(i * Float64(i / fma(i, Float64(i * 4.0), -1.0)))); else tmp = 0.0625; end return tmp end
code[i_] := If[LessEqual[i, 5000000.0], N[(0.25 * N[(i * N[(i / N[(i * N[(i * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 5000000:\\
\;\;\;\;0.25 \cdot \left(i \cdot \frac{i}{\mathsf{fma}\left(i, i \cdot 4, -1\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5e6Initial program 35.6%
Simplified100.0%
if 5e6 < i Initial program 21.4%
Simplified49.3%
Taylor expanded in i around inf 100.0%
(FPCore (i)
:precision binary64
(let* ((t_0 (* 4.0 (* i i))))
(if (<= i 5e-9)
(* i (* 0.25 (- i)))
(if (<= i 5000000.0)
(/ (* (* i i) (* i i)) (* t_0 (+ -1.0 t_0)))
0.0625))))
double code(double i) {
double t_0 = 4.0 * (i * i);
double tmp;
if (i <= 5e-9) {
tmp = i * (0.25 * -i);
} else if (i <= 5000000.0) {
tmp = ((i * i) * (i * i)) / (t_0 * (-1.0 + t_0));
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
real(8) :: tmp
t_0 = 4.0d0 * (i * i)
if (i <= 5d-9) then
tmp = i * (0.25d0 * -i)
else if (i <= 5000000.0d0) then
tmp = ((i * i) * (i * i)) / (t_0 * ((-1.0d0) + t_0))
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double t_0 = 4.0 * (i * i);
double tmp;
if (i <= 5e-9) {
tmp = i * (0.25 * -i);
} else if (i <= 5000000.0) {
tmp = ((i * i) * (i * i)) / (t_0 * (-1.0 + t_0));
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): t_0 = 4.0 * (i * i) tmp = 0 if i <= 5e-9: tmp = i * (0.25 * -i) elif i <= 5000000.0: tmp = ((i * i) * (i * i)) / (t_0 * (-1.0 + t_0)) else: tmp = 0.0625 return tmp
function code(i) t_0 = Float64(4.0 * Float64(i * i)) tmp = 0.0 if (i <= 5e-9) tmp = Float64(i * Float64(0.25 * Float64(-i))); elseif (i <= 5000000.0) tmp = Float64(Float64(Float64(i * i) * Float64(i * i)) / Float64(t_0 * Float64(-1.0 + t_0))); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) t_0 = 4.0 * (i * i); tmp = 0.0; if (i <= 5e-9) tmp = i * (0.25 * -i); elseif (i <= 5000000.0) tmp = ((i * i) * (i * i)) / (t_0 * (-1.0 + t_0)); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := Block[{t$95$0 = N[(4.0 * N[(i * i), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[i, 5e-9], N[(i * N[(0.25 * (-i)), $MachinePrecision]), $MachinePrecision], If[LessEqual[i, 5000000.0], N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0625]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \left(i \cdot i\right)\\
\mathbf{if}\;i \leq 5 \cdot 10^{-9}:\\
\;\;\;\;i \cdot \left(0.25 \cdot \left(-i\right)\right)\\
\mathbf{elif}\;i \leq 5000000:\\
\;\;\;\;\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t\_0 \cdot \left(-1 + t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5.0000000000000001e-9Initial program 32.3%
Simplified100.0%
associate-*r*100.0%
frac-2neg100.0%
metadata-eval100.0%
fma-neg100.0%
associate-*r*100.0%
*-commutative100.0%
metadata-eval100.0%
swap-sqr100.0%
associate-*r/100.0%
*-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-neg-in100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in i around 0 100.0%
if 5.0000000000000001e-9 < i < 5e6Initial program 99.4%
associate-/l/99.2%
sub-neg99.2%
swap-sqr99.2%
metadata-eval99.2%
metadata-eval99.2%
swap-sqr99.2%
metadata-eval99.2%
Simplified99.2%
if 5e6 < i Initial program 21.4%
Simplified49.3%
Taylor expanded in i around inf 100.0%
Final simplification100.0%
(FPCore (i) :precision binary64 (if (<= i 0.5) (* i (* 0.25 (- i))) 0.0625))
double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = i * (0.25 * -i);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 0.5d0) then
tmp = i * (0.25d0 * -i)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = i * (0.25 * -i);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 0.5: tmp = i * (0.25 * -i) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 0.5) tmp = Float64(i * Float64(0.25 * Float64(-i))); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.5) tmp = i * (0.25 * -i); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 0.5], N[(i * N[(0.25 * (-i)), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 0.5:\\
\;\;\;\;i \cdot \left(0.25 \cdot \left(-i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 0.5Initial program 34.7%
Simplified100.0%
associate-*r*100.0%
frac-2neg100.0%
metadata-eval100.0%
fma-neg100.0%
associate-*r*100.0%
*-commutative100.0%
metadata-eval100.0%
swap-sqr100.0%
associate-*r/100.0%
*-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-neg-in100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in i around 0 97.7%
if 0.5 < i Initial program 22.7%
Simplified50.2%
Taylor expanded in i around inf 99.1%
Final simplification98.4%
(FPCore (i) :precision binary64 (if (<= i 0.5) (* 0.25 (* i (- i))) 0.0625))
double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = 0.25 * (i * -i);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 0.5d0) then
tmp = 0.25d0 * (i * -i)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = 0.25 * (i * -i);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 0.5: tmp = 0.25 * (i * -i) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 0.5) tmp = Float64(0.25 * Float64(i * Float64(-i))); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.5) tmp = 0.25 * (i * -i); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 0.5], N[(0.25 * N[(i * (-i)), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 0.5:\\
\;\;\;\;0.25 \cdot \left(i \cdot \left(-i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 0.5Initial program 34.7%
Simplified100.0%
Taylor expanded in i around 0 97.7%
neg-mul-197.7%
Simplified97.7%
if 0.5 < i Initial program 22.7%
Simplified50.2%
Taylor expanded in i around inf 99.1%
(FPCore (i) :precision binary64 0.0625)
double code(double i) {
return 0.0625;
}
real(8) function code(i)
real(8), intent (in) :: i
code = 0.0625d0
end function
public static double code(double i) {
return 0.0625;
}
def code(i): return 0.0625
function code(i) return 0.0625 end
function tmp = code(i) tmp = 0.0625; end
code[i_] := 0.0625
\begin{array}{l}
\\
0.0625
\end{array}
Initial program 29.1%
Simplified76.8%
Taylor expanded in i around inf 47.5%
herbie shell --seed 2024085
(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)))