
(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 11 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 (/ (sin v) (fma e (cos v) 1.0))))
double code(double e, double v) {
return e * (sin(v) / fma(e, cos(v), 1.0));
}
function code(e, v) return Float64(e * Float64(sin(v) / fma(e, cos(v), 1.0))) end
code[e_, v_] := N[(e * N[(N[Sin[v], $MachinePrecision] / N[(e * N[Cos[v], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e \cdot \frac{\sin v}{\mathsf{fma}\left(e, \cos v, 1\right)}
\end{array}
Initial program 99.8%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
Final simplification99.8%
(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%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6498.5
Applied egg-rr98.5%
associate-/r*N/A
clear-numN/A
/-lowering-/.f64N/A
sin-lowering-sin.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6499.7
Applied egg-rr99.7%
Taylor expanded in v around 0
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6499.0
Simplified99.0%
clear-numN/A
associate-/r/N/A
clear-numN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sin-lowering-sin.f6499.2
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (e v) :precision binary64 (* (- 1.0 e) (* (sin v) e)))
double code(double e, double v) {
return (1.0 - e) * (sin(v) * e);
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = (1.0d0 - e) * (sin(v) * e)
end function
public static double code(double e, double v) {
return (1.0 - e) * (Math.sin(v) * e);
}
def code(e, v): return (1.0 - e) * (math.sin(v) * e)
function code(e, v) return Float64(Float64(1.0 - e) * Float64(sin(v) * e)) end
function tmp = code(e, v) tmp = (1.0 - e) * (sin(v) * e); end
code[e_, v_] := N[(N[(1.0 - e), $MachinePrecision] * N[(N[Sin[v], $MachinePrecision] * e), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - e\right) \cdot \left(\sin v \cdot e\right)
\end{array}
Initial program 99.8%
Taylor expanded in e around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
Simplified98.6%
Taylor expanded in v around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6498.2
Simplified98.2%
Final simplification98.2%
(FPCore (e v) :precision binary64 (if (<= v 2e-27) (* e (/ v (+ e 1.0))) (* (sin v) e)))
double code(double e, double v) {
double tmp;
if (v <= 2e-27) {
tmp = e * (v / (e + 1.0));
} else {
tmp = sin(v) * e;
}
return tmp;
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
real(8) :: tmp
if (v <= 2d-27) then
tmp = e * (v / (e + 1.0d0))
else
tmp = sin(v) * e
end if
code = tmp
end function
public static double code(double e, double v) {
double tmp;
if (v <= 2e-27) {
tmp = e * (v / (e + 1.0));
} else {
tmp = Math.sin(v) * e;
}
return tmp;
}
def code(e, v): tmp = 0 if v <= 2e-27: tmp = e * (v / (e + 1.0)) else: tmp = math.sin(v) * e return tmp
function code(e, v) tmp = 0.0 if (v <= 2e-27) tmp = Float64(e * Float64(v / Float64(e + 1.0))); else tmp = Float64(sin(v) * e); end return tmp end
function tmp_2 = code(e, v) tmp = 0.0; if (v <= 2e-27) tmp = e * (v / (e + 1.0)); else tmp = sin(v) * e; end tmp_2 = tmp; end
code[e_, v_] := If[LessEqual[v, 2e-27], N[(e * N[(v / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[v], $MachinePrecision] * e), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 2 \cdot 10^{-27}:\\
\;\;\;\;e \cdot \frac{v}{e + 1}\\
\mathbf{else}:\\
\;\;\;\;\sin v \cdot e\\
\end{array}
\end{array}
if v < 2.0000000000000001e-27Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6467.9
Simplified67.9%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6467.9
Applied egg-rr67.9%
if 2.0000000000000001e-27 < v Initial program 99.7%
Taylor expanded in e around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6498.2
Simplified98.2%
Final simplification76.5%
(FPCore (e v)
:precision binary64
(*
v
(/
1.0
(fma
v
(* v (- -0.5 (/ (fma e -0.16666666666666666 -0.16666666666666666) e)))
(+ 1.0 (/ 1.0 e))))))
double code(double e, double v) {
return v * (1.0 / fma(v, (v * (-0.5 - (fma(e, -0.16666666666666666, -0.16666666666666666) / e))), (1.0 + (1.0 / e))));
}
function code(e, v) return Float64(v * Float64(1.0 / fma(v, Float64(v * Float64(-0.5 - Float64(fma(e, -0.16666666666666666, -0.16666666666666666) / e))), Float64(1.0 + Float64(1.0 / e))))) end
code[e_, v_] := N[(v * N[(1.0 / N[(v * N[(v * N[(-0.5 - N[(N[(e * -0.16666666666666666 + -0.16666666666666666), $MachinePrecision] / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(1.0 / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
v \cdot \frac{1}{\mathsf{fma}\left(v, v \cdot \left(-0.5 - \frac{\mathsf{fma}\left(e, -0.16666666666666666, -0.16666666666666666\right)}{e}\right), 1 + \frac{1}{e}\right)}
\end{array}
Initial program 99.8%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6498.5
Applied egg-rr98.5%
Taylor expanded in v around 0
/-lowering-/.f64N/A
Simplified50.2%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f6451.4
Applied egg-rr51.4%
Final simplification51.4%
(FPCore (e v)
:precision binary64
(/
e
(/
(fma
(* v v)
(fma e -0.5 (fma e 0.16666666666666666 0.16666666666666666))
(+ e 1.0))
v)))
double code(double e, double v) {
return e / (fma((v * v), fma(e, -0.5, fma(e, 0.16666666666666666, 0.16666666666666666)), (e + 1.0)) / v);
}
function code(e, v) return Float64(e / Float64(fma(Float64(v * v), fma(e, -0.5, fma(e, 0.16666666666666666, 0.16666666666666666)), Float64(e + 1.0)) / v)) end
code[e_, v_] := N[(e / N[(N[(N[(v * v), $MachinePrecision] * N[(e * -0.5 + N[(e * 0.16666666666666666 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + N[(e + 1.0), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e}{\frac{\mathsf{fma}\left(v \cdot v, \mathsf{fma}\left(e, -0.5, \mathsf{fma}\left(e, 0.16666666666666666, 0.16666666666666666\right)\right), e + 1\right)}{v}}
\end{array}
Initial program 99.8%
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
sin-lowering-sin.f6499.6
Applied egg-rr99.6%
Taylor expanded in v around 0
/-lowering-/.f64N/A
associate-+r+N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6451.4
Simplified51.4%
(FPCore (e v) :precision binary64 (/ e (/ (fma (* v v) (* e -0.3333333333333333) (+ e 1.0)) v)))
double code(double e, double v) {
return e / (fma((v * v), (e * -0.3333333333333333), (e + 1.0)) / v);
}
function code(e, v) return Float64(e / Float64(fma(Float64(v * v), Float64(e * -0.3333333333333333), Float64(e + 1.0)) / v)) end
code[e_, v_] := N[(e / N[(N[(N[(v * v), $MachinePrecision] * N[(e * -0.3333333333333333), $MachinePrecision] + N[(e + 1.0), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e}{\frac{\mathsf{fma}\left(v \cdot v, e \cdot -0.3333333333333333, e + 1\right)}{v}}
\end{array}
Initial program 99.8%
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
sin-lowering-sin.f6499.6
Applied egg-rr99.6%
Taylor expanded in v around 0
/-lowering-/.f64N/A
associate-+r+N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6451.4
Simplified51.4%
Taylor expanded in e around inf
*-commutativeN/A
*-lowering-*.f6451.2
Simplified51.2%
(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(e * Float64(v / Float64(e + 1.0))) end
function tmp = code(e, v) tmp = e * (v / (e + 1.0)); end
code[e_, v_] := N[(e * N[(v / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e \cdot \frac{v}{e + 1}
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6450.5
Simplified50.5%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6450.5
Applied egg-rr50.5%
Final simplification50.5%
(FPCore (e v) :precision binary64 (* e (- v (* v e))))
double code(double e, double v) {
return e * (v - (v * e));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = e * (v - (v * e))
end function
public static double code(double e, double v) {
return e * (v - (v * e));
}
def code(e, v): return e * (v - (v * e))
function code(e, v) return Float64(e * Float64(v - Float64(v * e))) end
function tmp = code(e, v) tmp = e * (v - (v * e)); end
code[e_, v_] := N[(e * N[(v - N[(v * e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e \cdot \left(v - v \cdot e\right)
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6450.5
Simplified50.5%
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6450.4
Applied egg-rr50.4%
Taylor expanded in e around 0
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6449.5
Simplified49.5%
Final simplification49.5%
(FPCore (e v) :precision binary64 (* v e))
double code(double e, double v) {
return v * e;
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = v * e
end function
public static double code(double e, double v) {
return v * e;
}
def code(e, v): return v * e
function code(e, v) return Float64(v * e) end
function tmp = code(e, v) tmp = v * e; end
code[e_, v_] := N[(v * e), $MachinePrecision]
\begin{array}{l}
\\
v \cdot e
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6450.5
Simplified50.5%
Taylor expanded in e around 0
*-commutativeN/A
*-lowering-*.f6448.8
Simplified48.8%
(FPCore (e v) :precision binary64 v)
double code(double e, double v) {
return v;
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = v
end function
public static double code(double e, double v) {
return v;
}
def code(e, v): return v
function code(e, v) return v end
function tmp = code(e, v) tmp = v; end
code[e_, v_] := v
\begin{array}{l}
\\
v
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6450.5
Simplified50.5%
Taylor expanded in e around inf
Simplified4.8%
herbie shell --seed 2024198
(FPCore (e v)
:name "Trigonometry A"
:precision binary64
:pre (and (<= 0.0 e) (<= e 1.0))
(/ (* e (sin v)) (+ 1.0 (* e (cos v)))))