
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}
(FPCore (x) :precision binary64 (* (/ (+ x -1.0) (+ x (fma 4.0 (sqrt x) 1.0))) 6.0))
double code(double x) {
return ((x + -1.0) / (x + fma(4.0, sqrt(x), 1.0))) * 6.0;
}
function code(x) return Float64(Float64(Float64(x + -1.0) / Float64(x + fma(4.0, sqrt(x), 1.0))) * 6.0) end
code[x_] := N[(N[(N[(x + -1.0), $MachinePrecision] / N[(x + N[(4.0 * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + -1}{x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)} \cdot 6
\end{array}
Initial program 99.8%
associate-/l*99.9%
*-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
associate-+l+99.9%
+-commutative99.9%
fma-define99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= x 0.038) (+ -6.0 (* (sqrt x) 24.0)) (* (+ x -1.0) (/ 6.0 (+ x (* 4.0 (sqrt x)))))))
double code(double x) {
double tmp;
if (x <= 0.038) {
tmp = -6.0 + (sqrt(x) * 24.0);
} else {
tmp = (x + -1.0) * (6.0 / (x + (4.0 * sqrt(x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.038d0) then
tmp = (-6.0d0) + (sqrt(x) * 24.0d0)
else
tmp = (x + (-1.0d0)) * (6.0d0 / (x + (4.0d0 * sqrt(x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.038) {
tmp = -6.0 + (Math.sqrt(x) * 24.0);
} else {
tmp = (x + -1.0) * (6.0 / (x + (4.0 * Math.sqrt(x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.038: tmp = -6.0 + (math.sqrt(x) * 24.0) else: tmp = (x + -1.0) * (6.0 / (x + (4.0 * math.sqrt(x)))) return tmp
function code(x) tmp = 0.0 if (x <= 0.038) tmp = Float64(-6.0 + Float64(sqrt(x) * 24.0)); else tmp = Float64(Float64(x + -1.0) * Float64(6.0 / Float64(x + Float64(4.0 * sqrt(x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.038) tmp = -6.0 + (sqrt(x) * 24.0); else tmp = (x + -1.0) * (6.0 / (x + (4.0 * sqrt(x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.038], N[(-6.0 + N[(N[Sqrt[x], $MachinePrecision] * 24.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + -1.0), $MachinePrecision] * N[(6.0 / N[(x + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.038:\\
\;\;\;\;-6 + \sqrt{x} \cdot 24\\
\mathbf{else}:\\
\;\;\;\;\left(x + -1\right) \cdot \frac{6}{x + 4 \cdot \sqrt{x}}\\
\end{array}
\end{array}
if x < 0.0379999999999999991Initial program 99.9%
flip-+99.9%
associate-/r/100.0%
Applied egg-rr100.0%
associate-*l/100.0%
fma-define100.0%
*-commutative100.0%
fma-define100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
if 0.0379999999999999991 < x Initial program 99.6%
*-commutative99.6%
associate-/l*99.8%
sub-neg99.8%
metadata-eval99.8%
associate-+l+99.8%
+-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 95.4%
*-commutative95.4%
Simplified95.4%
Final simplification97.8%
(FPCore (x) :precision binary64 (* (+ x -1.0) (/ 6.0 (+ (+ x 1.0) (* 4.0 (sqrt x))))))
double code(double x) {
return (x + -1.0) * (6.0 / ((x + 1.0) + (4.0 * sqrt(x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (-1.0d0)) * (6.0d0 / ((x + 1.0d0) + (4.0d0 * sqrt(x))))
end function
public static double code(double x) {
return (x + -1.0) * (6.0 / ((x + 1.0) + (4.0 * Math.sqrt(x))));
}
def code(x): return (x + -1.0) * (6.0 / ((x + 1.0) + (4.0 * math.sqrt(x))))
function code(x) return Float64(Float64(x + -1.0) * Float64(6.0 / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))))) end
function tmp = code(x) tmp = (x + -1.0) * (6.0 / ((x + 1.0) + (4.0 * sqrt(x)))); end
code[x_] := N[(N[(x + -1.0), $MachinePrecision] * N[(6.0 / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + -1\right) \cdot \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-/l*99.9%
sub-neg99.9%
metadata-eval99.9%
associate-+l+99.9%
+-commutative99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 99.9%
associate-+r+99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.07) (+ -6.0 (* (sqrt x) 24.0)) (/ 6.0 (+ 1.0 (/ 4.0 (sqrt x))))))
double code(double x) {
double tmp;
if (x <= 0.07) {
tmp = -6.0 + (sqrt(x) * 24.0);
} else {
tmp = 6.0 / (1.0 + (4.0 / sqrt(x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.07d0) then
tmp = (-6.0d0) + (sqrt(x) * 24.0d0)
else
tmp = 6.0d0 / (1.0d0 + (4.0d0 / sqrt(x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.07) {
tmp = -6.0 + (Math.sqrt(x) * 24.0);
} else {
tmp = 6.0 / (1.0 + (4.0 / Math.sqrt(x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.07: tmp = -6.0 + (math.sqrt(x) * 24.0) else: tmp = 6.0 / (1.0 + (4.0 / math.sqrt(x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.07) tmp = Float64(-6.0 + Float64(sqrt(x) * 24.0)); else tmp = Float64(6.0 / Float64(1.0 + Float64(4.0 / sqrt(x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.07) tmp = -6.0 + (sqrt(x) * 24.0); else tmp = 6.0 / (1.0 + (4.0 / sqrt(x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.07], N[(-6.0 + N[(N[Sqrt[x], $MachinePrecision] * 24.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(1.0 + N[(4.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.07:\\
\;\;\;\;-6 + \sqrt{x} \cdot 24\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{1 + \frac{4}{\sqrt{x}}}\\
\end{array}
\end{array}
if x < 0.070000000000000007Initial program 99.9%
flip-+99.9%
associate-/r/100.0%
Applied egg-rr100.0%
associate-*l/100.0%
fma-define100.0%
*-commutative100.0%
fma-define100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
if 0.070000000000000007 < x Initial program 99.6%
Taylor expanded in x around inf 95.3%
*-commutative95.3%
Simplified95.3%
Taylor expanded in x around inf 95.4%
*-commutative95.4%
Simplified95.4%
add-exp-log95.3%
log-div95.4%
log1p-define95.4%
*-commutative95.4%
sqrt-div95.4%
metadata-eval95.4%
un-div-inv95.4%
Applied egg-rr95.4%
exp-diff95.4%
rem-exp-log95.4%
log1p-undefine95.4%
rem-exp-log95.4%
Simplified95.4%
(FPCore (x) :precision binary64 (if (<= x 0.06) (+ -6.0 (* (sqrt x) 24.0)) (+ 6.0 (/ -24.0 (sqrt x)))))
double code(double x) {
double tmp;
if (x <= 0.06) {
tmp = -6.0 + (sqrt(x) * 24.0);
} else {
tmp = 6.0 + (-24.0 / sqrt(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.06d0) then
tmp = (-6.0d0) + (sqrt(x) * 24.0d0)
else
tmp = 6.0d0 + ((-24.0d0) / sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.06) {
tmp = -6.0 + (Math.sqrt(x) * 24.0);
} else {
tmp = 6.0 + (-24.0 / Math.sqrt(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.06: tmp = -6.0 + (math.sqrt(x) * 24.0) else: tmp = 6.0 + (-24.0 / math.sqrt(x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.06) tmp = Float64(-6.0 + Float64(sqrt(x) * 24.0)); else tmp = Float64(6.0 + Float64(-24.0 / sqrt(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.06) tmp = -6.0 + (sqrt(x) * 24.0); else tmp = 6.0 + (-24.0 / sqrt(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.06], N[(-6.0 + N[(N[Sqrt[x], $MachinePrecision] * 24.0), $MachinePrecision]), $MachinePrecision], N[(6.0 + N[(-24.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.06:\\
\;\;\;\;-6 + \sqrt{x} \cdot 24\\
\mathbf{else}:\\
\;\;\;\;6 + \frac{-24}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.059999999999999998Initial program 99.9%
flip-+99.9%
associate-/r/100.0%
Applied egg-rr100.0%
associate-*l/100.0%
fma-define100.0%
*-commutative100.0%
fma-define100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
if 0.059999999999999998 < x Initial program 99.6%
flip-+58.4%
associate-/r/58.4%
Applied egg-rr58.3%
associate-*l/57.0%
fma-define57.0%
*-commutative57.0%
fma-define57.0%
associate-+l+57.0%
*-commutative57.0%
+-commutative57.0%
Simplified57.0%
Taylor expanded in x around inf 95.0%
distribute-rgt-in95.0%
metadata-eval95.0%
*-commutative95.0%
associate-*l*95.0%
metadata-eval95.0%
Simplified95.0%
*-commutative95.0%
sqrt-div95.0%
metadata-eval95.0%
un-div-inv95.0%
Applied egg-rr95.0%
(FPCore (x) :precision binary64 (+ -6.0 (* (sqrt x) 24.0)))
double code(double x) {
return -6.0 + (sqrt(x) * 24.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-6.0d0) + (sqrt(x) * 24.0d0)
end function
public static double code(double x) {
return -6.0 + (Math.sqrt(x) * 24.0);
}
def code(x): return -6.0 + (math.sqrt(x) * 24.0)
function code(x) return Float64(-6.0 + Float64(sqrt(x) * 24.0)) end
function tmp = code(x) tmp = -6.0 + (sqrt(x) * 24.0); end
code[x_] := N[(-6.0 + N[(N[Sqrt[x], $MachinePrecision] * 24.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-6 + \sqrt{x} \cdot 24
\end{array}
Initial program 99.8%
flip-+80.1%
associate-/r/80.1%
Applied egg-rr80.1%
associate-*l/79.5%
fma-define79.5%
*-commutative79.5%
fma-define79.5%
associate-+l+79.5%
*-commutative79.5%
+-commutative79.5%
Simplified79.5%
Taylor expanded in x around 0 55.8%
distribute-rgt-in55.8%
metadata-eval55.8%
*-commutative55.8%
associate-*l*55.8%
metadata-eval55.8%
Simplified55.8%
(FPCore (x) :precision binary64 (sqrt (* x 2.25)))
double code(double x) {
return sqrt((x * 2.25));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x * 2.25d0))
end function
public static double code(double x) {
return Math.sqrt((x * 2.25));
}
def code(x): return math.sqrt((x * 2.25))
function code(x) return sqrt(Float64(x * 2.25)) end
function tmp = code(x) tmp = sqrt((x * 2.25)); end
code[x_] := N[Sqrt[N[(x * 2.25), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x \cdot 2.25}
\end{array}
Initial program 99.8%
Taylor expanded in x around inf 46.6%
*-commutative46.6%
Simplified46.6%
Taylor expanded in x around inf 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in x around 0 4.5%
add-sqr-sqrt4.5%
sqrt-unprod4.5%
*-commutative4.5%
*-commutative4.5%
swap-sqr4.5%
add-sqr-sqrt4.5%
metadata-eval4.5%
Applied egg-rr4.5%
(FPCore (x) :precision binary64 (/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0))))
double code(double x) {
return 6.0 / (((x + 1.0) + (4.0 * sqrt(x))) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 6.0d0 / (((x + 1.0d0) + (4.0d0 * sqrt(x))) / (x - 1.0d0))
end function
public static double code(double x) {
return 6.0 / (((x + 1.0) + (4.0 * Math.sqrt(x))) / (x - 1.0));
}
def code(x): return 6.0 / (((x + 1.0) + (4.0 * math.sqrt(x))) / (x - 1.0))
function code(x) return Float64(6.0 / Float64(Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))) / Float64(x - 1.0))) end
function tmp = code(x) tmp = 6.0 / (((x + 1.0) + (4.0 * sqrt(x))) / (x - 1.0)); end
code[x_] := N[(6.0 / N[(N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}
\end{array}
herbie shell --seed 2024111
(FPCore (x)
:name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
:precision binary64
:alt
(/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0)))
(/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))