
(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}
(FPCore (x) :precision binary64 (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))
double code(double x) {
return 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))));
}
def code(x): return 1.0 - math.sqrt((0.5 + (0.5 / math.hypot(1.0, x))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x)))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
(FPCore (x)
:precision binary64
(-
1.0
(sqrt
(+
0.5
(/ (+ 0.5 (+ (/ 0.1875 (* x (* x (* x x)))) (/ -0.25 (* x x)))) x)))))
double code(double x) {
return 1.0 - sqrt((0.5 + ((0.5 + ((0.1875 / (x * (x * (x * x)))) + (-0.25 / (x * x)))) / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - sqrt((0.5d0 + ((0.5d0 + ((0.1875d0 / (x * (x * (x * x)))) + ((-0.25d0) / (x * x)))) / x)))
end function
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 + ((0.5 + ((0.1875 / (x * (x * (x * x)))) + (-0.25 / (x * x)))) / x)));
}
def code(x): return 1.0 - math.sqrt((0.5 + ((0.5 + ((0.1875 / (x * (x * (x * x)))) + (-0.25 / (x * x)))) / x)))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 + Float64(Float64(0.5 + Float64(Float64(0.1875 / Float64(x * Float64(x * Float64(x * x)))) + Float64(-0.25 / Float64(x * x)))) / x)))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 + ((0.5 + ((0.1875 / (x * (x * (x * x)))) + (-0.25 / (x * x)))) / x))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 + N[(N[(0.5 + N[(N[(0.1875 / N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.25 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 + \frac{0.5 + \left(\frac{0.1875}{x \cdot \left(x \cdot \left(x \cdot x\right)\right)} + \frac{-0.25}{x \cdot x}\right)}{x}}
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified96.7%
(FPCore (x) :precision binary64 (+ 1.0 (* (sqrt 0.5) (+ -1.0 (/ (+ -0.5 (/ 0.125 x)) x)))))
double code(double x) {
return 1.0 + (sqrt(0.5) * (-1.0 + ((-0.5 + (0.125 / x)) / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + (sqrt(0.5d0) * ((-1.0d0) + (((-0.5d0) + (0.125d0 / x)) / x)))
end function
public static double code(double x) {
return 1.0 + (Math.sqrt(0.5) * (-1.0 + ((-0.5 + (0.125 / x)) / x)));
}
def code(x): return 1.0 + (math.sqrt(0.5) * (-1.0 + ((-0.5 + (0.125 / x)) / x)))
function code(x) return Float64(1.0 + Float64(sqrt(0.5) * Float64(-1.0 + Float64(Float64(-0.5 + Float64(0.125 / x)) / x)))) end
function tmp = code(x) tmp = 1.0 + (sqrt(0.5) * (-1.0 + ((-0.5 + (0.125 / x)) / x))); end
code[x_] := N[(1.0 + N[(N[Sqrt[0.5], $MachinePrecision] * N[(-1.0 + N[(N[(-0.5 + N[(0.125 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \sqrt{0.5} \cdot \left(-1 + \frac{-0.5 + \frac{0.125}{x}}{x}\right)
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
sub-negN/A
+-commutativeN/A
pow1/2N/A
clear-numN/A
associate-/r/N/A
distribute-rgt1-inN/A
unpow-prod-downN/A
distribute-lft-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
Applied egg-rr98.3%
sub0-negN/A
neg-lowering-neg.f64N/A
sqrt-lowering-sqrt.f64N/A
remove-double-negN/A
distribute-frac-neg2N/A
unsub-negN/A
--lowering--.f64N/A
metadata-evalN/A
frac-2negN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Applied egg-rr98.3%
Taylor expanded in x around inf
associate--l+N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
--lowering--.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6496.8%
Simplified96.8%
Taylor expanded in x around inf
Simplified96.8%
(FPCore (x) :precision binary64 (- 1.0 (sqrt (+ 0.5 (/ 0.5 x)))))
double code(double x) {
return 1.0 - sqrt((0.5 + (0.5 / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - sqrt((0.5d0 + (0.5d0 / x)))
end function
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 + (0.5 / x)));
}
def code(x): return 1.0 - math.sqrt((0.5 + (0.5 / x)))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / x)))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 + (0.5 / x))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 + \frac{0.5}{x}}
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around inf
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6496.7%
Simplified96.7%
(FPCore (x) :precision binary64 (- 1.0 (sqrt 0.5)))
double code(double x) {
return 1.0 - sqrt(0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - sqrt(0.5d0)
end function
public static double code(double x) {
return 1.0 - Math.sqrt(0.5);
}
def code(x): return 1.0 - math.sqrt(0.5)
function code(x) return Float64(1.0 - sqrt(0.5)) end
function tmp = code(x) tmp = 1.0 - sqrt(0.5); end
code[x_] := N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5}
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around inf
--lowering--.f64N/A
sqrt-lowering-sqrt.f6496.3%
Simplified96.3%
(FPCore (x) :precision binary64 (- 1.0 (+ 1.0 (* x (* x -0.125)))))
double code(double x) {
return 1.0 - (1.0 + (x * (x * -0.125)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (1.0d0 + (x * (x * (-0.125d0))))
end function
public static double code(double x) {
return 1.0 - (1.0 + (x * (x * -0.125)));
}
def code(x): return 1.0 - (1.0 + (x * (x * -0.125)))
function code(x) return Float64(1.0 - Float64(1.0 + Float64(x * Float64(x * -0.125)))) end
function tmp = code(x) tmp = 1.0 - (1.0 + (x * (x * -0.125))); end
code[x_] := N[(1.0 - N[(1.0 + N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(1 + x \cdot \left(x \cdot -0.125\right)\right)
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f644.3%
Simplified4.3%
(FPCore (x) :precision binary64 (* (* x x) (* x (/ 0.125 x))))
double code(double x) {
return (x * x) * (x * (0.125 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (x * (0.125d0 / x))
end function
public static double code(double x) {
return (x * x) * (x * (0.125 / x));
}
def code(x): return (x * x) * (x * (0.125 / x))
function code(x) return Float64(Float64(x * x) * Float64(x * Float64(0.125 / x))) end
function tmp = code(x) tmp = (x * x) * (x * (0.125 / x)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(x * N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(x \cdot \frac{0.125}{x}\right)
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around 0
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.3%
Simplified1.3%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f644.3%
Simplified4.3%
*-commutativeN/A
pow2N/A
metadata-evalN/A
pow-prod-upN/A
inv-powN/A
cube-unmultN/A
associate-*l*N/A
div-invN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f644.3%
Applied egg-rr4.3%
Final simplification4.3%
(FPCore (x) :precision binary64 (* (* x x) 0.125))
double code(double x) {
return (x * x) * 0.125;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * 0.125d0
end function
public static double code(double x) {
return (x * x) * 0.125;
}
def code(x): return (x * x) * 0.125
function code(x) return Float64(Float64(x * x) * 0.125) end
function tmp = code(x) tmp = (x * x) * 0.125; end
code[x_] := N[(N[(x * x), $MachinePrecision] * 0.125), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot 0.125
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around 0
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f644.3%
Simplified4.3%
Final simplification4.3%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 98.3%
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
hypot-undefineN/A
hypot-lowering-hypot.f6498.3%
Simplified98.3%
Taylor expanded in x around 0
Simplified3.1%
metadata-eval3.1%
Applied egg-rr3.1%
herbie shell --seed 2024164
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))