
(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 12 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}
(FPCore (e v) :precision binary64 (* (/ e (fma e (cos v) 1.0)) (sin v)))
double code(double e, double v) {
return (e / fma(e, cos(v), 1.0)) * sin(v);
}
function code(e, v) return Float64(Float64(e / fma(e, cos(v), 1.0)) * sin(v)) end
code[e_, v_] := N[(N[(e / N[(e * N[Cos[v], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[Sin[v], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e}{\mathsf{fma}\left(e, \cos v, 1\right)} \cdot \sin v
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (e v) :precision binary64 (/ (* e (sin v)) (+ e 1.0)))
double code(double e, double v) {
return (e * sin(v)) / (e + 1.0);
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = (e * sin(v)) / (e + 1.0d0)
end function
public static double code(double e, double v) {
return (e * Math.sin(v)) / (e + 1.0);
}
def code(e, v): return (e * math.sin(v)) / (e + 1.0)
function code(e, v) return Float64(Float64(e * sin(v)) / Float64(e + 1.0)) end
function tmp = code(e, v) tmp = (e * sin(v)) / (e + 1.0); end
code[e_, v_] := N[(N[(e * N[Sin[v], $MachinePrecision]), $MachinePrecision] / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e \cdot \sin v}{e + 1}
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-+.f6498.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (e v) :precision binary64 (* (sin v) (/ e (+ e 1.0))))
double code(double e, double v) {
return sin(v) * (e / (e + 1.0));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = sin(v) * (e / (e + 1.0d0))
end function
public static double code(double e, double v) {
return Math.sin(v) * (e / (e + 1.0));
}
def code(e, v): return math.sin(v) * (e / (e + 1.0))
function code(e, v) return Float64(sin(v) * Float64(e / Float64(e + 1.0))) end
function tmp = code(e, v) tmp = sin(v) * (e / (e + 1.0)); end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin v \cdot \frac{e}{e + 1}
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in v around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f6498.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (e v) :precision binary64 (* (sin v) (- e (* e e))))
double code(double e, double v) {
return sin(v) * (e - (e * e));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = sin(v) * (e - (e * e))
end function
public static double code(double e, double v) {
return Math.sin(v) * (e - (e * e));
}
def code(e, v): return math.sin(v) * (e - (e * e))
function code(e, v) return Float64(sin(v) * Float64(e - Float64(e * e))) end
function tmp = code(e, v) tmp = sin(v) * (e - (e * e)); end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * N[(e - N[(e * e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin v \cdot \left(e - e \cdot e\right)
\end{array}
Initial program 99.8%
Taylor expanded in e around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
unpow2N/A
associate-*r*N/A
distribute-lft-neg-inN/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites98.3%
Taylor expanded in v around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
unpow2N/A
lower-*.f6497.4
Applied rewrites97.4%
(FPCore (e v)
:precision binary64
(let* ((t_0 (/ e (+ e 1.0))))
(if (<= v 0.00038)
(* v (fma (* v v) (* t_0 (fma 0.5 t_0 -0.16666666666666666)) t_0))
(* e (sin v)))))
double code(double e, double v) {
double t_0 = e / (e + 1.0);
double tmp;
if (v <= 0.00038) {
tmp = v * fma((v * v), (t_0 * fma(0.5, t_0, -0.16666666666666666)), t_0);
} else {
tmp = e * sin(v);
}
return tmp;
}
function code(e, v) t_0 = Float64(e / Float64(e + 1.0)) tmp = 0.0 if (v <= 0.00038) tmp = Float64(v * fma(Float64(v * v), Float64(t_0 * fma(0.5, t_0, -0.16666666666666666)), t_0)); else tmp = Float64(e * sin(v)); end return tmp end
code[e_, v_] := Block[{t$95$0 = N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, 0.00038], N[(v * N[(N[(v * v), $MachinePrecision] * N[(t$95$0 * N[(0.5 * t$95$0 + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(e * N[Sin[v], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e}{e + 1}\\
\mathbf{if}\;v \leq 0.00038:\\
\;\;\;\;v \cdot \mathsf{fma}\left(v \cdot v, t\_0 \cdot \mathsf{fma}\left(0.5, t\_0, -0.16666666666666666\right), t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;e \cdot \sin v\\
\end{array}
\end{array}
if v < 3.8000000000000002e-4Initial program 99.8%
Taylor expanded in v around 0
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites63.5%
if 3.8000000000000002e-4 < v Initial program 99.8%
Taylor expanded in e around 0
lower-*.f64N/A
lower-sin.f6497.4
Applied rewrites97.4%
Final simplification72.9%
(FPCore (e v)
:precision binary64
(if (<= v 100.0)
(*
v
(fma
(* v v)
(*
(/ (* e (* v v)) (+ e 1.0))
(fma (* v v) -0.0001984126984126984 0.008333333333333333))
(* (/ e (+ e 1.0)) (fma v (* v -0.16666666666666666) 1.0))))
(* v (/ 1.0 (* (fma (* v v) 0.16666666666666666 1.0) (/ 1.0 e))))))
double code(double e, double v) {
double tmp;
if (v <= 100.0) {
tmp = v * fma((v * v), (((e * (v * v)) / (e + 1.0)) * fma((v * v), -0.0001984126984126984, 0.008333333333333333)), ((e / (e + 1.0)) * fma(v, (v * -0.16666666666666666), 1.0)));
} else {
tmp = v * (1.0 / (fma((v * v), 0.16666666666666666, 1.0) * (1.0 / e)));
}
return tmp;
}
function code(e, v) tmp = 0.0 if (v <= 100.0) tmp = Float64(v * fma(Float64(v * v), Float64(Float64(Float64(e * Float64(v * v)) / Float64(e + 1.0)) * fma(Float64(v * v), -0.0001984126984126984, 0.008333333333333333)), Float64(Float64(e / Float64(e + 1.0)) * fma(v, Float64(v * -0.16666666666666666), 1.0)))); else tmp = Float64(v * Float64(1.0 / Float64(fma(Float64(v * v), 0.16666666666666666, 1.0) * Float64(1.0 / e)))); end return tmp end
code[e_, v_] := If[LessEqual[v, 100.0], N[(v * N[(N[(v * v), $MachinePrecision] * N[(N[(N[(e * N[(v * v), $MachinePrecision]), $MachinePrecision] / N[(e + 1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision] * N[(v * N[(v * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(v * N[(1.0 / N[(N[(N[(v * v), $MachinePrecision] * 0.16666666666666666 + 1.0), $MachinePrecision] * N[(1.0 / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 100:\\
\;\;\;\;v \cdot \mathsf{fma}\left(v \cdot v, \frac{e \cdot \left(v \cdot v\right)}{e + 1} \cdot \mathsf{fma}\left(v \cdot v, -0.0001984126984126984, 0.008333333333333333\right), \frac{e}{e + 1} \cdot \mathsf{fma}\left(v, v \cdot -0.16666666666666666, 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;v \cdot \frac{1}{\mathsf{fma}\left(v \cdot v, 0.16666666666666666, 1\right) \cdot \frac{1}{e}}\\
\end{array}
\end{array}
if v < 100Initial program 99.8%
Taylor expanded in v around 0
lower-+.f6498.7
Applied rewrites98.7%
Taylor expanded in v around 0
Applied rewrites63.3%
if 100 < v Initial program 99.8%
Taylor expanded in e around 0
lower-*.f64N/A
lower-sin.f6497.3
Applied rewrites97.3%
Taylor expanded in v around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f642.5
Applied rewrites2.5%
lift-*.f64N/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-fma.f64N/A
lower-/.f642.5
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites2.5%
Taylor expanded in v around 0
associate-*r/N/A
*-rgt-identityN/A
associate-*r/N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f645.9
Applied rewrites5.9%
Final simplification47.8%
(FPCore (e v)
:precision binary64
(let* ((t_0 (/ e (+ e 1.0))))
(if (<= v 100.0)
(* v (fma (* v v) (* t_0 (fma 0.5 t_0 -0.16666666666666666)) t_0))
(* v (/ 1.0 (* (fma (* v v) 0.16666666666666666 1.0) (/ 1.0 e)))))))
double code(double e, double v) {
double t_0 = e / (e + 1.0);
double tmp;
if (v <= 100.0) {
tmp = v * fma((v * v), (t_0 * fma(0.5, t_0, -0.16666666666666666)), t_0);
} else {
tmp = v * (1.0 / (fma((v * v), 0.16666666666666666, 1.0) * (1.0 / e)));
}
return tmp;
}
function code(e, v) t_0 = Float64(e / Float64(e + 1.0)) tmp = 0.0 if (v <= 100.0) tmp = Float64(v * fma(Float64(v * v), Float64(t_0 * fma(0.5, t_0, -0.16666666666666666)), t_0)); else tmp = Float64(v * Float64(1.0 / Float64(fma(Float64(v * v), 0.16666666666666666, 1.0) * Float64(1.0 / e)))); end return tmp end
code[e_, v_] := Block[{t$95$0 = N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, 100.0], N[(v * N[(N[(v * v), $MachinePrecision] * N[(t$95$0 * N[(0.5 * t$95$0 + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(v * N[(1.0 / N[(N[(N[(v * v), $MachinePrecision] * 0.16666666666666666 + 1.0), $MachinePrecision] * N[(1.0 / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e}{e + 1}\\
\mathbf{if}\;v \leq 100:\\
\;\;\;\;v \cdot \mathsf{fma}\left(v \cdot v, t\_0 \cdot \mathsf{fma}\left(0.5, t\_0, -0.16666666666666666\right), t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;v \cdot \frac{1}{\mathsf{fma}\left(v \cdot v, 0.16666666666666666, 1\right) \cdot \frac{1}{e}}\\
\end{array}
\end{array}
if v < 100Initial program 99.8%
Taylor expanded in v around 0
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites63.1%
if 100 < v Initial program 99.8%
Taylor expanded in e around 0
lower-*.f64N/A
lower-sin.f6497.3
Applied rewrites97.3%
Taylor expanded in v around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f642.5
Applied rewrites2.5%
lift-*.f64N/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-fma.f64N/A
lower-/.f642.5
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites2.5%
Taylor expanded in v around 0
associate-*r/N/A
*-rgt-identityN/A
associate-*r/N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f645.9
Applied rewrites5.9%
Final simplification47.7%
(FPCore (e v) :precision binary64 (/ (* e v) (+ e 1.0)))
double code(double e, double v) {
return (e * v) / (e + 1.0);
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = (e * v) / (e + 1.0d0)
end function
public static double code(double e, double v) {
return (e * v) / (e + 1.0);
}
def code(e, v): return (e * v) / (e + 1.0)
function code(e, v) return Float64(Float64(e * v) / Float64(e + 1.0)) end
function tmp = code(e, v) tmp = (e * v) / (e + 1.0); end
code[e_, v_] := N[(N[(e * v), $MachinePrecision] / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e \cdot v}{e + 1}
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6447.0
Applied rewrites47.0%
Final simplification47.0%
(FPCore (e v) :precision binary64 (* e (fma e (- (* e v) v) v)))
double code(double e, double v) {
return e * fma(e, ((e * v) - v), v);
}
function code(e, v) return Float64(e * fma(e, Float64(Float64(e * v) - v), v)) end
code[e_, v_] := N[(e * N[(e * N[(N[(e * v), $MachinePrecision] - v), $MachinePrecision] + v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e \cdot \mathsf{fma}\left(e, e \cdot v - v, v\right)
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6447.0
Applied rewrites47.0%
Taylor expanded in e around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6446.3
Applied rewrites46.3%
(FPCore (e v) :precision binary64 (* e (* v (- 1.0 e))))
double code(double e, double v) {
return e * (v * (1.0 - e));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = e * (v * (1.0d0 - e))
end function
public static double code(double e, double v) {
return e * (v * (1.0 - e));
}
def code(e, v): return e * (v * (1.0 - e))
function code(e, v) return Float64(e * Float64(v * Float64(1.0 - e))) end
function tmp = code(e, v) tmp = e * (v * (1.0 - e)); end
code[e_, v_] := N[(e * N[(v * N[(1.0 - e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e \cdot \left(v \cdot \left(1 - e\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6447.0
Applied rewrites47.0%
Taylor expanded in e around 0
distribute-lft-inN/A
associate-*r*N/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
unpow2N/A
mul-1-negN/A
distribute-rgt-inN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
unpow2N/A
lower-*.f6446.0
Applied rewrites46.0%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f6446.0
Applied rewrites46.0%
Final simplification46.0%
(FPCore (e v) :precision binary64 (* v (- e (* e e))))
double code(double e, double v) {
return v * (e - (e * e));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = v * (e - (e * e))
end function
public static double code(double e, double v) {
return v * (e - (e * e));
}
def code(e, v): return v * (e - (e * e))
function code(e, v) return Float64(v * Float64(e - Float64(e * e))) end
function tmp = code(e, v) tmp = v * (e - (e * e)); end
code[e_, v_] := N[(v * N[(e - N[(e * e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
v \cdot \left(e - e \cdot e\right)
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6447.0
Applied rewrites47.0%
Taylor expanded in e around 0
distribute-lft-inN/A
associate-*r*N/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
unpow2N/A
mul-1-negN/A
distribute-rgt-inN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
unpow2N/A
lower-*.f6446.0
Applied rewrites46.0%
(FPCore (e v) :precision binary64 (* e v))
double code(double e, double v) {
return e * v;
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = e * v
end function
public static double code(double e, double v) {
return e * v;
}
def code(e, v): return e * v
function code(e, v) return Float64(e * v) end
function tmp = code(e, v) tmp = e * v; end
code[e_, v_] := N[(e * v), $MachinePrecision]
\begin{array}{l}
\\
e \cdot v
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6447.0
Applied rewrites47.0%
Taylor expanded in e around 0
lower-*.f6445.3
Applied rewrites45.3%
herbie shell --seed 2024216
(FPCore (e v)
:name "Trigonometry A"
:precision binary64
:pre (and (<= 0.0 e) (<= e 1.0))
(/ (* e (sin v)) (+ 1.0 (* e (cos v)))))