
(FPCore (e v) :precision binary64 (/ (* e (sin v)) (+ 1.0 (* e (cos v)))))
double code(double e, double v) {
return (e * sin(v)) / (1.0 + (e * cos(v)));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = (e * sin(v)) / (1.0d0 + (e * cos(v)))
end function
public static double code(double e, double v) {
return (e * Math.sin(v)) / (1.0 + (e * Math.cos(v)));
}
def code(e, v): return (e * math.sin(v)) / (1.0 + (e * math.cos(v)))
function code(e, v) return Float64(Float64(e * sin(v)) / Float64(1.0 + Float64(e * cos(v)))) end
function tmp = code(e, v) tmp = (e * sin(v)) / (1.0 + (e * cos(v))); end
code[e_, v_] := N[(N[(e * N[Sin[v], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(e * N[Cos[v], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e \cdot \sin v}{1 + e \cdot \cos v}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (e v) :precision binary64 (/ (* e (sin v)) (+ 1.0 (* e (cos v)))))
double code(double e, double v) {
return (e * sin(v)) / (1.0 + (e * cos(v)));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = (e * sin(v)) / (1.0d0 + (e * cos(v)))
end function
public static double code(double e, double v) {
return (e * Math.sin(v)) / (1.0 + (e * Math.cos(v)));
}
def code(e, v): return (e * math.sin(v)) / (1.0 + (e * math.cos(v)))
function code(e, v) return Float64(Float64(e * sin(v)) / Float64(1.0 + Float64(e * cos(v)))) end
function tmp = code(e, v) tmp = (e * sin(v)) / (1.0 + (e * cos(v))); end
code[e_, v_] := N[(N[(e * N[Sin[v], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(e * N[Cos[v], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e \cdot \sin v}{1 + e \cdot \cos v}
\end{array}
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (/ (log1p (expm1 (* e (sin v_m)))) (+ 1.0 (* e (cos v_m))))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (log1p(expm1((e * sin(v_m)))) / (1.0 + (e * cos(v_m))));
}
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (Math.log1p(Math.expm1((e * Math.sin(v_m)))) / (1.0 + (e * Math.cos(v_m))));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (math.log1p(math.expm1((e * math.sin(v_m)))) / (1.0 + (e * math.cos(v_m))))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(log1p(expm1(Float64(e * sin(v_m)))) / Float64(1.0 + Float64(e * cos(v_m))))) end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(N[Log[1 + N[(Exp[N[(e * N[Sin[v$95$m], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(e * N[Cos[v$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \frac{\mathsf{log1p}\left(\mathsf{expm1}\left(e \cdot \sin v\_m\right)\right)}{1 + e \cdot \cos v\_m}
\end{array}
Initial program 99.8%
log1p-expm1-u99.8%
Applied egg-rr99.8%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (/ (* e (sin v_m)) (+ 1.0 (* e (cos v_m))))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * ((e * sin(v_m)) / (1.0 + (e * cos(v_m))));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * ((e * sin(v_m)) / (1.0d0 + (e * cos(v_m))))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * ((e * Math.sin(v_m)) / (1.0 + (e * Math.cos(v_m))));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * ((e * math.sin(v_m)) / (1.0 + (e * math.cos(v_m))))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(Float64(e * sin(v_m)) / Float64(1.0 + Float64(e * cos(v_m))))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * ((e * sin(v_m)) / (1.0 + (e * cos(v_m)))); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(N[(e * N[Sin[v$95$m], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(e * N[Cos[v$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \frac{e \cdot \sin v\_m}{1 + e \cdot \cos v\_m}
\end{array}
Initial program 99.8%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (/ (sin v_m) (+ (cos v_m) (/ 1.0 e)))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (sin(v_m) / (cos(v_m) + (1.0 / e)));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * (sin(v_m) / (cos(v_m) + (1.0d0 / e)))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (Math.sin(v_m) / (Math.cos(v_m) + (1.0 / e)));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (math.sin(v_m) / (math.cos(v_m) + (1.0 / e)))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(sin(v_m) / Float64(cos(v_m) + Float64(1.0 / e)))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * (sin(v_m) / (cos(v_m) + (1.0 / e))); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(N[Sin[v$95$m], $MachinePrecision] / N[(N[Cos[v$95$m], $MachinePrecision] + N[(1.0 / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \frac{\sin v\_m}{\cos v\_m + \frac{1}{e}}
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in e around inf 99.7%
Taylor expanded in v around inf 99.6%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (/ (* e (sin v_m)) (+ e 1.0))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * ((e * sin(v_m)) / (e + 1.0));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * ((e * sin(v_m)) / (e + 1.0d0))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * ((e * Math.sin(v_m)) / (e + 1.0));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * ((e * math.sin(v_m)) / (e + 1.0))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(Float64(e * sin(v_m)) / Float64(e + 1.0))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * ((e * sin(v_m)) / (e + 1.0)); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(N[(e * N[Sin[v$95$m], $MachinePrecision]), $MachinePrecision] / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \frac{e \cdot \sin v\_m}{e + 1}
\end{array}
Initial program 99.8%
Taylor expanded in v around 0 98.4%
Final simplification98.4%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (* e (sin v_m))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (e * sin(v_m));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * (e * sin(v_m))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (e * Math.sin(v_m));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (e * math.sin(v_m))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(e * sin(v_m))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * (e * sin(v_m)); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(e * N[Sin[v$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \left(e \cdot \sin v\_m\right)
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in e around 0 97.3%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (* e (/ v_m (+ e 1.0)))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (e * (v_m / (e + 1.0)));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * (e * (v_m / (e + 1.0d0)))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (e * (v_m / (e + 1.0)));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (e * (v_m / (e + 1.0)))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(e * Float64(v_m / Float64(e + 1.0)))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * (e * (v_m / (e + 1.0))); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(e * N[(v$95$m / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \left(e \cdot \frac{v\_m}{e + 1}\right)
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in v around 0 56.9%
associate-/l*56.9%
+-commutative56.9%
Simplified56.9%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (* e (* v_m (- 1.0 e)))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (e * (v_m * (1.0 - e)));
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * (e * (v_m * (1.0d0 - e)))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (e * (v_m * (1.0 - e)));
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (e * (v_m * (1.0 - e)))
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(e * Float64(v_m * Float64(1.0 - e)))) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * (e * (v_m * (1.0 - e))); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(e * N[(v$95$m * N[(1.0 - e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \left(e \cdot \left(v\_m \cdot \left(1 - e\right)\right)\right)
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in v around 0 56.9%
associate-/l*56.9%
+-commutative56.9%
Simplified56.9%
Taylor expanded in e around 0 56.5%
neg-mul-156.5%
*-lft-identity56.5%
distribute-lft-neg-in56.5%
distribute-rgt-in56.5%
sub-neg56.5%
Simplified56.5%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s (* e v_m)))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * (e * v_m);
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * (e * v_m)
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * (e * v_m);
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * (e * v_m)
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * Float64(e * v_m)) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * (e * v_m); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * N[(e * v$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \left(e \cdot v\_m\right)
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in v around 0 56.9%
associate-/l*56.9%
+-commutative56.9%
Simplified56.9%
Taylor expanded in e around 0 56.5%
neg-mul-156.5%
distribute-rgt-neg-in56.5%
Simplified56.5%
Taylor expanded in e around 0 55.9%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s e v_m) :precision binary64 (* v_s v_m))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double e, double v_m) {
return v_s * v_m;
}
v\_m = abs(v)
v\_s = copysign(1.0d0, v)
real(8) function code(v_s, e, v_m)
real(8), intent (in) :: v_s
real(8), intent (in) :: e
real(8), intent (in) :: v_m
code = v_s * v_m
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double e, double v_m) {
return v_s * v_m;
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, e, v_m): return v_s * v_m
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, e, v_m) return Float64(v_s * v_m) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, e, v_m) tmp = v_s * v_m; end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, e_, v$95$m_] := N[(v$95$s * v$95$m), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot v\_m
\end{array}
Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
cos-neg99.8%
distribute-frac-neg99.8%
sin-neg99.8%
distribute-neg-frac99.8%
sin-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
cos-neg99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in v around 0 56.9%
associate-/l*56.9%
+-commutative56.9%
Simplified56.9%
Taylor expanded in e around inf 4.8%
herbie shell --seed 2024131
(FPCore (e v)
:name "Trigonometry A"
:precision binary64
:pre (and (<= 0.0 e) (<= e 1.0))
(/ (* e (sin v)) (+ 1.0 (* e (cos v)))))