Trigonometry A

Percentage Accurate: 99.8% → 99.8%
Time: 7.8s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[0 \leq e \land e \leq 1\]
\[\begin{array}{l} \\ \frac{e \cdot \sin v}{1 + e \cdot \cos v} \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e \cdot \sin v}{1 + e \cdot \cos v} \end{array} \]
(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}

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. log1p-expm1-u99.8%

      \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e \cdot \sin v\right)\right)}}{1 + e \cdot \cos v} \]
  4. Applied egg-rr99.8%

    \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e \cdot \sin v\right)\right)}}{1 + e \cdot \cos v} \]
  5. Add Preprocessing

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 3: 99.6% accurate, 1.0× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in e around inf 99.7%

    \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \left(\cos v + \frac{1}{e}\right)}} \]
  6. Taylor expanded in v around inf 99.6%

    \[\leadsto \color{blue}{\frac{\sin v}{\cos v + \frac{1}{e}}} \]
  7. Add Preprocessing

Alternative 4: 98.7% accurate, 2.0× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0 98.4%

    \[\leadsto \frac{e \cdot \sin v}{1 + \color{blue}{e}} \]
  4. Final simplification98.4%

    \[\leadsto \frac{e \cdot \sin v}{e + 1} \]
  5. Add Preprocessing

Alternative 5: 97.7% accurate, 2.0× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in e around 0 97.3%

    \[\leadsto \color{blue}{e \cdot \sin v} \]
  6. Add Preprocessing

Alternative 6: 51.8% accurate, 29.9× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in v around 0 56.9%

    \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{e \cdot \frac{v}{1 + e}} \]
    2. +-commutative56.9%

      \[\leadsto e \cdot \frac{v}{\color{blue}{e + 1}} \]
  7. Simplified56.9%

    \[\leadsto \color{blue}{e \cdot \frac{v}{e + 1}} \]
  8. Add Preprocessing

Alternative 7: 51.4% accurate, 29.9× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in v around 0 56.9%

    \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{e \cdot \frac{v}{1 + e}} \]
    2. +-commutative56.9%

      \[\leadsto e \cdot \frac{v}{\color{blue}{e + 1}} \]
  7. Simplified56.9%

    \[\leadsto \color{blue}{e \cdot \frac{v}{e + 1}} \]
  8. Taylor expanded in e around 0 56.5%

    \[\leadsto \color{blue}{e \cdot \left(v + -1 \cdot \left(e \cdot v\right)\right)} \]
  9. Step-by-step derivation
    1. neg-mul-156.5%

      \[\leadsto e \cdot \left(v + \color{blue}{\left(-e \cdot v\right)}\right) \]
    2. *-lft-identity56.5%

      \[\leadsto e \cdot \left(\color{blue}{1 \cdot v} + \left(-e \cdot v\right)\right) \]
    3. distribute-lft-neg-in56.5%

      \[\leadsto e \cdot \left(1 \cdot v + \color{blue}{\left(-e\right) \cdot v}\right) \]
    4. distribute-rgt-in56.5%

      \[\leadsto e \cdot \color{blue}{\left(v \cdot \left(1 + \left(-e\right)\right)\right)} \]
    5. sub-neg56.5%

      \[\leadsto e \cdot \left(v \cdot \color{blue}{\left(1 - e\right)}\right) \]
  10. Simplified56.5%

    \[\leadsto \color{blue}{e \cdot \left(v \cdot \left(1 - e\right)\right)} \]
  11. Add Preprocessing

Alternative 8: 50.8% accurate, 69.7× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in v around 0 56.9%

    \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{e \cdot \frac{v}{1 + e}} \]
    2. +-commutative56.9%

      \[\leadsto e \cdot \frac{v}{\color{blue}{e + 1}} \]
  7. Simplified56.9%

    \[\leadsto \color{blue}{e \cdot \frac{v}{e + 1}} \]
  8. Taylor expanded in e around 0 56.5%

    \[\leadsto \color{blue}{e \cdot \left(v + -1 \cdot \left(e \cdot v\right)\right)} \]
  9. Step-by-step derivation
    1. neg-mul-156.5%

      \[\leadsto e \cdot \left(v + \color{blue}{\left(-e \cdot v\right)}\right) \]
    2. distribute-rgt-neg-in56.5%

      \[\leadsto e \cdot \left(v + \color{blue}{e \cdot \left(-v\right)}\right) \]
  10. Simplified56.5%

    \[\leadsto \color{blue}{e \cdot \left(v + e \cdot \left(-v\right)\right)} \]
  11. Taylor expanded in e around 0 55.9%

    \[\leadsto \color{blue}{e \cdot v} \]
  12. Add Preprocessing

Alternative 9: 4.6% accurate, 209.0× speedup?

\[\begin{array}{l} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ v\_s \cdot v\_m \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 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}
Derivation
  1. Initial program 99.8%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Step-by-step derivation
    1. associate-/l*99.8%

      \[\leadsto \color{blue}{e \cdot \frac{\sin v}{1 + e \cdot \cos v}} \]
    2. remove-double-neg99.8%

      \[\leadsto e \cdot \color{blue}{\left(-\left(-\frac{\sin v}{1 + e \cdot \cos v}\right)\right)} \]
    3. cos-neg99.8%

      \[\leadsto e \cdot \left(-\left(-\frac{\sin v}{1 + e \cdot \color{blue}{\cos \left(-v\right)}}\right)\right) \]
    4. distribute-frac-neg99.8%

      \[\leadsto e \cdot \left(-\color{blue}{\frac{-\sin v}{1 + e \cdot \cos \left(-v\right)}}\right) \]
    5. sin-neg99.8%

      \[\leadsto e \cdot \left(-\frac{\color{blue}{\sin \left(-v\right)}}{1 + e \cdot \cos \left(-v\right)}\right) \]
    6. distribute-neg-frac99.8%

      \[\leadsto e \cdot \color{blue}{\frac{-\sin \left(-v\right)}{1 + e \cdot \cos \left(-v\right)}} \]
    7. sin-neg99.8%

      \[\leadsto e \cdot \frac{-\color{blue}{\left(-\sin v\right)}}{1 + e \cdot \cos \left(-v\right)} \]
    8. remove-double-neg99.8%

      \[\leadsto e \cdot \frac{\color{blue}{\sin v}}{1 + e \cdot \cos \left(-v\right)} \]
    9. +-commutative99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{e \cdot \cos \left(-v\right) + 1}} \]
    10. cos-neg99.8%

      \[\leadsto e \cdot \frac{\sin v}{e \cdot \color{blue}{\cos v} + 1} \]
    11. fma-define99.8%

      \[\leadsto e \cdot \frac{\sin v}{\color{blue}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in v around 0 56.9%

    \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{e \cdot \frac{v}{1 + e}} \]
    2. +-commutative56.9%

      \[\leadsto e \cdot \frac{v}{\color{blue}{e + 1}} \]
  7. Simplified56.9%

    \[\leadsto \color{blue}{e \cdot \frac{v}{e + 1}} \]
  8. Taylor expanded in e around inf 4.8%

    \[\leadsto \color{blue}{v} \]
  9. Add Preprocessing

Reproduce

?
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)))))