
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
double code(double x) {
return (1.0 - cos(x)) / sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / sin(x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / Math.sin(x);
}
def code(x): return (1.0 - math.cos(x)) / math.sin(x)
function code(x) return Float64(Float64(1.0 - cos(x)) / sin(x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / sin(x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{\sin x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
double code(double x) {
return (1.0 - cos(x)) / sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / sin(x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / Math.sin(x);
}
def code(x): return (1.0 - math.cos(x)) / math.sin(x)
function code(x) return Float64(Float64(1.0 - cos(x)) / sin(x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / sin(x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{\sin x}
\end{array}
(FPCore (x) :precision binary64 (tan (/ x 2.0)))
double code(double x) {
return tan((x / 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x / 2.0d0))
end function
public static double code(double x) {
return Math.tan((x / 2.0));
}
def code(x): return math.tan((x / 2.0))
function code(x) return tan(Float64(x / 2.0)) end
function tmp = code(x) tmp = tan((x / 2.0)); end
code[x_] := N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan \left(\frac{x}{2}\right)
\end{array}
Initial program 55.0%
hang-p0-tanN/A
tan-lowering-tan.f64N/A
/-lowering-/.f64100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (/ x (- 2.0 (* (* x x) 0.16666666666666666))))
double code(double x) {
return x / (2.0 - ((x * x) * 0.16666666666666666));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (2.0d0 - ((x * x) * 0.16666666666666666d0))
end function
public static double code(double x) {
return x / (2.0 - ((x * x) * 0.16666666666666666));
}
def code(x): return x / (2.0 - ((x * x) * 0.16666666666666666))
function code(x) return Float64(x / Float64(2.0 - Float64(Float64(x * x) * 0.16666666666666666))) end
function tmp = code(x) tmp = x / (2.0 - ((x * x) * 0.16666666666666666)); end
code[x_] := N[(x / N[(2.0 - N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2 - \left(x \cdot x\right) \cdot 0.16666666666666666}
\end{array}
Initial program 55.0%
hang-p0-tanN/A
tan-lowering-tan.f64N/A
/-lowering-/.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6448.8%
Simplified48.8%
flip3-+N/A
clear-numN/A
un-div-invN/A
frac-2negN/A
/-lowering-/.f64N/A
neg-sub0N/A
--lowering--.f64N/A
neg-sub0N/A
--lowering--.f64N/A
Applied egg-rr48.9%
Taylor expanded in x around 0
sub-negN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
metadata-eval49.4%
Simplified49.4%
sub0-negN/A
distribute-frac-negN/A
distribute-frac-neg2N/A
/-lowering-/.f64N/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6449.4%
Applied egg-rr49.4%
(FPCore (x) :precision binary64 (* x (+ 0.5 (* x (* x 0.041666666666666664)))))
double code(double x) {
return x * (0.5 + (x * (x * 0.041666666666666664)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (0.5d0 + (x * (x * 0.041666666666666664d0)))
end function
public static double code(double x) {
return x * (0.5 + (x * (x * 0.041666666666666664)));
}
def code(x): return x * (0.5 + (x * (x * 0.041666666666666664)))
function code(x) return Float64(x * Float64(0.5 + Float64(x * Float64(x * 0.041666666666666664)))) end
function tmp = code(x) tmp = x * (0.5 + (x * (x * 0.041666666666666664))); end
code[x_] := N[(x * N[(0.5 + N[(x * N[(x * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)
\end{array}
Initial program 55.0%
hang-p0-tanN/A
tan-lowering-tan.f64N/A
/-lowering-/.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6448.8%
Simplified48.8%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return x * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.5d0
end function
public static double code(double x) {
return x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 55.0%
hang-p0-tanN/A
tan-lowering-tan.f64N/A
/-lowering-/.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f6448.7%
Simplified48.7%
Final simplification48.7%
(FPCore (x) :precision binary64 (tan (/ x 2.0)))
double code(double x) {
return tan((x / 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x / 2.0d0))
end function
public static double code(double x) {
return Math.tan((x / 2.0));
}
def code(x): return math.tan((x / 2.0))
function code(x) return tan(Float64(x / 2.0)) end
function tmp = code(x) tmp = tan((x / 2.0)); end
code[x_] := N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan \left(\frac{x}{2}\right)
\end{array}
herbie shell --seed 2024191
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:alt
(! :herbie-platform default (tan (/ x 2)))
(/ (- 1.0 (cos x)) (sin x)))