
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (/ 0.5 x_m) 0.5))
(t_1 (sqrt t_0))
(t_2 (+ t_1 1.0))
(t_3 (fma (sqrt 2.0) (sqrt 0.5) 1.0))
(t_4 (* (pow t_3 2.0) (sqrt 2.0)))
(t_5 (/ (sqrt 0.5) t_4))
(t_6 (/ 0.1875 t_3)))
(if (<= x_m 1.2)
(*
(fma
(-
(fma
(-
(/ 0.15625 t_3)
(fma
(/ 0.25 (sqrt 2.0))
(/ (* (fma t_5 -0.0625 t_6) (sqrt 0.5)) t_3)
(/ (* 0.125 (* 0.34375 (sqrt 0.5))) t_4)))
(* x_m x_m)
(* 0.0625 t_5))
t_6)
(* x_m x_m)
(/ 0.25 t_3))
(* x_m x_m))
(/ (- t_2 (fma t_1 t_0 t_0)) (* t_2 t_2)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double t_1 = sqrt(t_0);
double t_2 = t_1 + 1.0;
double t_3 = fma(sqrt(2.0), sqrt(0.5), 1.0);
double t_4 = pow(t_3, 2.0) * sqrt(2.0);
double t_5 = sqrt(0.5) / t_4;
double t_6 = 0.1875 / t_3;
double tmp;
if (x_m <= 1.2) {
tmp = fma((fma(((0.15625 / t_3) - fma((0.25 / sqrt(2.0)), ((fma(t_5, -0.0625, t_6) * sqrt(0.5)) / t_3), ((0.125 * (0.34375 * sqrt(0.5))) / t_4))), (x_m * x_m), (0.0625 * t_5)) - t_6), (x_m * x_m), (0.25 / t_3)) * (x_m * x_m);
} else {
tmp = (t_2 - fma(t_1, t_0, t_0)) / (t_2 * t_2);
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(Float64(0.5 / x_m) + 0.5) t_1 = sqrt(t_0) t_2 = Float64(t_1 + 1.0) t_3 = fma(sqrt(2.0), sqrt(0.5), 1.0) t_4 = Float64((t_3 ^ 2.0) * sqrt(2.0)) t_5 = Float64(sqrt(0.5) / t_4) t_6 = Float64(0.1875 / t_3) tmp = 0.0 if (x_m <= 1.2) tmp = Float64(fma(Float64(fma(Float64(Float64(0.15625 / t_3) - fma(Float64(0.25 / sqrt(2.0)), Float64(Float64(fma(t_5, -0.0625, t_6) * sqrt(0.5)) / t_3), Float64(Float64(0.125 * Float64(0.34375 * sqrt(0.5))) / t_4))), Float64(x_m * x_m), Float64(0.0625 * t_5)) - t_6), Float64(x_m * x_m), Float64(0.25 / t_3)) * Float64(x_m * x_m)); else tmp = Float64(Float64(t_2 - fma(t_1, t_0, t_0)) / Float64(t_2 * t_2)); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + 1.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[t$95$3, 2.0], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[0.5], $MachinePrecision] / t$95$4), $MachinePrecision]}, Block[{t$95$6 = N[(0.1875 / t$95$3), $MachinePrecision]}, If[LessEqual[x$95$m, 1.2], N[(N[(N[(N[(N[(N[(0.15625 / t$95$3), $MachinePrecision] - N[(N[(0.25 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(t$95$5 * -0.0625 + t$95$6), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision] + N[(N[(0.125 * N[(0.34375 * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + N[(0.0625 * t$95$5), $MachinePrecision]), $MachinePrecision] - t$95$6), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + N[(0.25 / t$95$3), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 - N[(t$95$1 * t$95$0 + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := \frac{0.5}{x\_m} + 0.5\\
t_1 := \sqrt{t\_0}\\
t_2 := t\_1 + 1\\
t_3 := \mathsf{fma}\left(\sqrt{2}, \sqrt{0.5}, 1\right)\\
t_4 := {t\_3}^{2} \cdot \sqrt{2}\\
t_5 := \frac{\sqrt{0.5}}{t\_4}\\
t_6 := \frac{0.1875}{t\_3}\\
\mathbf{if}\;x\_m \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{0.15625}{t\_3} - \mathsf{fma}\left(\frac{0.25}{\sqrt{2}}, \frac{\mathsf{fma}\left(t\_5, -0.0625, t\_6\right) \cdot \sqrt{0.5}}{t\_3}, \frac{0.125 \cdot \left(0.34375 \cdot \sqrt{0.5}\right)}{t\_4}\right), x\_m \cdot x\_m, 0.0625 \cdot t\_5\right) - t\_6, x\_m \cdot x\_m, \frac{0.25}{t\_3}\right) \cdot \left(x\_m \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_2 - \mathsf{fma}\left(t\_1, t\_0, t\_0\right)}{t\_2 \cdot t\_2}\\
\end{array}
\end{array}
if x < 1.19999999999999996Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
Applied rewrites71.0%
if 1.19999999999999996 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
Applied rewrites100.0%
Applied rewrites100.0%
lift-*.f64N/A
*-lft-identity100.0
Applied rewrites100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (/ 0.5 x_m) 0.5))
(t_1 (sqrt t_0))
(t_2 (+ t_1 1.0))
(t_3 (fma (sqrt 2.0) (sqrt 0.5) 1.0)))
(if (<= x_m 1.12)
(*
(fma
(* (- x_m) x_m)
(fma (/ (sqrt 0.5) (* (pow t_3 2.0) (sqrt 2.0))) -0.0625 (/ 0.1875 t_3))
(/ 0.25 t_3))
(* x_m x_m))
(/ (- t_2 (fma t_1 t_0 t_0)) (* t_2 t_2)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double t_1 = sqrt(t_0);
double t_2 = t_1 + 1.0;
double t_3 = fma(sqrt(2.0), sqrt(0.5), 1.0);
double tmp;
if (x_m <= 1.12) {
tmp = fma((-x_m * x_m), fma((sqrt(0.5) / (pow(t_3, 2.0) * sqrt(2.0))), -0.0625, (0.1875 / t_3)), (0.25 / t_3)) * (x_m * x_m);
} else {
tmp = (t_2 - fma(t_1, t_0, t_0)) / (t_2 * t_2);
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(Float64(0.5 / x_m) + 0.5) t_1 = sqrt(t_0) t_2 = Float64(t_1 + 1.0) t_3 = fma(sqrt(2.0), sqrt(0.5), 1.0) tmp = 0.0 if (x_m <= 1.12) tmp = Float64(fma(Float64(Float64(-x_m) * x_m), fma(Float64(sqrt(0.5) / Float64((t_3 ^ 2.0) * sqrt(2.0))), -0.0625, Float64(0.1875 / t_3)), Float64(0.25 / t_3)) * Float64(x_m * x_m)); else tmp = Float64(Float64(t_2 - fma(t_1, t_0, t_0)) / Float64(t_2 * t_2)); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + 1.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x$95$m, 1.12], N[(N[(N[((-x$95$m) * x$95$m), $MachinePrecision] * N[(N[(N[Sqrt[0.5], $MachinePrecision] / N[(N[Power[t$95$3, 2.0], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.0625 + N[(0.1875 / t$95$3), $MachinePrecision]), $MachinePrecision] + N[(0.25 / t$95$3), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 - N[(t$95$1 * t$95$0 + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := \frac{0.5}{x\_m} + 0.5\\
t_1 := \sqrt{t\_0}\\
t_2 := t\_1 + 1\\
t_3 := \mathsf{fma}\left(\sqrt{2}, \sqrt{0.5}, 1\right)\\
\mathbf{if}\;x\_m \leq 1.12:\\
\;\;\;\;\mathsf{fma}\left(\left(-x\_m\right) \cdot x\_m, \mathsf{fma}\left(\frac{\sqrt{0.5}}{{t\_3}^{2} \cdot \sqrt{2}}, -0.0625, \frac{0.1875}{t\_3}\right), \frac{0.25}{t\_3}\right) \cdot \left(x\_m \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_2 - \mathsf{fma}\left(t\_1, t\_0, t\_0\right)}{t\_2 \cdot t\_2}\\
\end{array}
\end{array}
if x < 1.1200000000000001Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites70.1%
if 1.1200000000000001 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
Applied rewrites100.0%
Applied rewrites100.0%
lift-*.f64N/A
*-lft-identity100.0
Applied rewrites100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (/ 0.5 x_m) 0.5)) (t_1 (sqrt t_0)) (t_2 (+ t_1 1.0)))
(if (<= x_m 1.25)
(* (* x_m x_m) 0.125)
(/ (- t_2 (fma t_1 t_0 t_0)) (* t_2 t_2)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double t_1 = sqrt(t_0);
double t_2 = t_1 + 1.0;
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = (t_2 - fma(t_1, t_0, t_0)) / (t_2 * t_2);
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(Float64(0.5 / x_m) + 0.5) t_1 = sqrt(t_0) t_2 = Float64(t_1 + 1.0) tmp = 0.0 if (x_m <= 1.25) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(Float64(t_2 - fma(t_1, t_0, t_0)) / Float64(t_2 * t_2)); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + 1.0), $MachinePrecision]}, If[LessEqual[x$95$m, 1.25], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(N[(t$95$2 - N[(t$95$1 * t$95$0 + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := \frac{0.5}{x\_m} + 0.5\\
t_1 := \sqrt{t\_0}\\
t_2 := t\_1 + 1\\
\mathbf{if}\;x\_m \leq 1.25:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_2 - \mathsf{fma}\left(t\_1, t\_0, t\_0\right)}{t\_2 \cdot t\_2}\\
\end{array}
\end{array}
if x < 1.25Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.25 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
Applied rewrites100.0%
Applied rewrites100.0%
lift-*.f64N/A
*-lft-identity100.0
Applied rewrites100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (/ 0.5 x_m) 0.5)) (t_1 (+ (sqrt t_0) 1.0)))
(if (<= x_m 1.25)
(* (* x_m x_m) 0.125)
(/ (* t_1 (- 1.0 t_0)) (* t_1 t_1)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double t_1 = sqrt(t_0) + 1.0;
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = (t_1 * (1.0 - t_0)) / (t_1 * t_1);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (0.5d0 / x_m) + 0.5d0
t_1 = sqrt(t_0) + 1.0d0
if (x_m <= 1.25d0) then
tmp = (x_m * x_m) * 0.125d0
else
tmp = (t_1 * (1.0d0 - t_0)) / (t_1 * t_1)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double t_1 = Math.sqrt(t_0) + 1.0;
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = (t_1 * (1.0 - t_0)) / (t_1 * t_1);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): t_0 = (0.5 / x_m) + 0.5 t_1 = math.sqrt(t_0) + 1.0 tmp = 0 if x_m <= 1.25: tmp = (x_m * x_m) * 0.125 else: tmp = (t_1 * (1.0 - t_0)) / (t_1 * t_1) return tmp
x_m = abs(x) function code(x_m) t_0 = Float64(Float64(0.5 / x_m) + 0.5) t_1 = Float64(sqrt(t_0) + 1.0) tmp = 0.0 if (x_m <= 1.25) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(Float64(t_1 * Float64(1.0 - t_0)) / Float64(t_1 * t_1)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) t_0 = (0.5 / x_m) + 0.5; t_1 = sqrt(t_0) + 1.0; tmp = 0.0; if (x_m <= 1.25) tmp = (x_m * x_m) * 0.125; else tmp = (t_1 * (1.0 - t_0)) / (t_1 * t_1); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[t$95$0], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x$95$m, 1.25], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(N[(t$95$1 * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := \frac{0.5}{x\_m} + 0.5\\
t_1 := \sqrt{t\_0} + 1\\
\mathbf{if}\;x\_m \leq 1.25:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot \left(1 - t\_0\right)}{t\_1 \cdot t\_1}\\
\end{array}
\end{array}
if x < 1.25Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.25 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
Applied rewrites100.0%
Applied rewrites100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (/ 0.5 x_m) 0.5)))
(if (<= x_m 1.25)
(* (* x_m x_m) 0.125)
(/ (- 1.0 t_0) (+ (sqrt t_0) 1.0)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = (1.0 - t_0) / (sqrt(t_0) + 1.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = (0.5d0 / x_m) + 0.5d0
if (x_m <= 1.25d0) then
tmp = (x_m * x_m) * 0.125d0
else
tmp = (1.0d0 - t_0) / (sqrt(t_0) + 1.0d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double t_0 = (0.5 / x_m) + 0.5;
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = (1.0 - t_0) / (Math.sqrt(t_0) + 1.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): t_0 = (0.5 / x_m) + 0.5 tmp = 0 if x_m <= 1.25: tmp = (x_m * x_m) * 0.125 else: tmp = (1.0 - t_0) / (math.sqrt(t_0) + 1.0) return tmp
x_m = abs(x) function code(x_m) t_0 = Float64(Float64(0.5 / x_m) + 0.5) tmp = 0.0 if (x_m <= 1.25) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(Float64(1.0 - t_0) / Float64(sqrt(t_0) + 1.0)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) t_0 = (0.5 / x_m) + 0.5; tmp = 0.0; if (x_m <= 1.25) tmp = (x_m * x_m) * 0.125; else tmp = (1.0 - t_0) / (sqrt(t_0) + 1.0); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]}, If[LessEqual[x$95$m, 1.25], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[(N[Sqrt[t$95$0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := \frac{0.5}{x\_m} + 0.5\\
\mathbf{if}\;x\_m \leq 1.25:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sqrt{t\_0} + 1}\\
\end{array}
\end{array}
if x < 1.25Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.25 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites99.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.25) (* (* x_m x_m) 0.125) (- 1.0 (sqrt (+ (/ 0.5 x_m) 0.5)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 1.0 - sqrt(((0.5 / x_m) + 0.5));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.25d0) then
tmp = (x_m * x_m) * 0.125d0
else
tmp = 1.0d0 - sqrt(((0.5d0 / x_m) + 0.5d0))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.25) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 1.0 - Math.sqrt(((0.5 / x_m) + 0.5));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.25: tmp = (x_m * x_m) * 0.125 else: tmp = 1.0 - math.sqrt(((0.5 / x_m) + 0.5)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.25) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(1.0 - sqrt(Float64(Float64(0.5 / x_m) + 0.5))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.25) tmp = (x_m * x_m) * 0.125; else tmp = 1.0 - sqrt(((0.5 / x_m) + 0.5)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.25], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(1.0 - N[Sqrt[N[(N[(0.5 / x$95$m), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.25:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{\frac{0.5}{x\_m} + 0.5}\\
\end{array}
\end{array}
if x < 1.25Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.25 < x Initial program 98.5%
Taylor expanded in x around inf
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.55) (* (* x_m x_m) 0.125) (/ 0.5 (+ (sqrt 0.5) 1.0))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 0.5 / (sqrt(0.5) + 1.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.55d0) then
tmp = (x_m * x_m) * 0.125d0
else
tmp = 0.5d0 / (sqrt(0.5d0) + 1.0d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 0.5 / (Math.sqrt(0.5) + 1.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.55: tmp = (x_m * x_m) * 0.125 else: tmp = 0.5 / (math.sqrt(0.5) + 1.0) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.55) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(0.5 / Float64(sqrt(0.5) + 1.0)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.55) tmp = (x_m * x_m) * 0.125; else tmp = 0.5 / (sqrt(0.5) + 1.0); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.55], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(0.5 / N[(N[Sqrt[0.5], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.55:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{0.5} + 1}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.55000000000000004 < x Initial program 98.5%
Taylor expanded in x around inf
Applied rewrites96.6%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites98.0%
Taylor expanded in x around inf
Applied rewrites98.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.55) (* (* x_m x_m) 0.125) (- 1.0 (sqrt 0.5))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 1.0 - sqrt(0.5);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.55d0) then
tmp = (x_m * x_m) * 0.125d0
else
tmp = 1.0d0 - sqrt(0.5d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = (x_m * x_m) * 0.125;
} else {
tmp = 1.0 - Math.sqrt(0.5);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.55: tmp = (x_m * x_m) * 0.125 else: tmp = 1.0 - math.sqrt(0.5) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.55) tmp = Float64(Float64(x_m * x_m) * 0.125); else tmp = Float64(1.0 - sqrt(0.5)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.55) tmp = (x_m * x_m) * 0.125; else tmp = 1.0 - sqrt(0.5); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.55], N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision], N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.55:\\
\;\;\;\;\left(x\_m \cdot x\_m\right) \cdot 0.125\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 63.5%
Taylor expanded in x around inf
Applied rewrites32.3%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites32.7%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6470.9
Applied rewrites70.9%
Applied rewrites70.9%
if 1.55000000000000004 < x Initial program 98.5%
Taylor expanded in x around inf
Applied rewrites96.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (* x_m x_m) 0.125))
x_m = fabs(x);
double code(double x_m) {
return (x_m * x_m) * 0.125;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m * x_m) * 0.125d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (x_m * x_m) * 0.125;
}
x_m = math.fabs(x) def code(x_m): return (x_m * x_m) * 0.125
x_m = abs(x) function code(x_m) return Float64(Float64(x_m * x_m) * 0.125) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m * x_m) * 0.125; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.125), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\left(x\_m \cdot x\_m\right) \cdot 0.125
\end{array}
Initial program 72.1%
Taylor expanded in x around inf
Applied rewrites48.1%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites48.8%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
rem-square-sqrtN/A
unpow2N/A
lower-sqrt.f64N/A
unpow2N/A
rem-square-sqrtN/A
lower-sqrt.f6454.6
Applied rewrites54.6%
Applied rewrites54.6%
herbie shell --seed 2024337
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))