
(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) (fma (cos v) (* e (- e)) e)))
double code(double e, double v) {
return sin(v) * fma(cos(v), (e * -e), e);
}
function code(e, v) return Float64(sin(v) * fma(cos(v), Float64(e * Float64(-e)), e)) end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * N[(N[Cos[v], $MachinePrecision] * N[(e * (-e)), $MachinePrecision] + e), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin v \cdot \mathsf{fma}\left(\cos v, e \cdot \left(-e\right), 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
*-lowering-*.f64N/A
sin-lowering-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
Simplified99.0%
(FPCore (e v) :precision binary64 (* (sin v) e))
double code(double e, double v) {
return sin(v) * e;
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = sin(v) * e
end function
public static double code(double e, double v) {
return Math.sin(v) * e;
}
def code(e, v): return math.sin(v) * e
function code(e, v) return Float64(sin(v) * e) end
function tmp = code(e, v) tmp = sin(v) * e; end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * e), $MachinePrecision]
\begin{array}{l}
\\
\sin v \cdot e
\end{array}
Initial program 99.8%
Taylor expanded in e around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6498.2
Simplified98.2%
Final simplification98.2%
(FPCore (e v)
:precision binary64
(/
1.0
(/
(fma
(* v v)
(fma
(* v v)
(+
0.041666666666666664
(- (* -0.019444444444444445 (/ (- -1.0 e) e)) 0.08333333333333333))
(- -0.5 (/ (fma e -0.16666666666666666 -0.16666666666666666) e)))
(+ 1.0 (/ 1.0 e)))
v)))
double code(double e, double v) {
return 1.0 / (fma((v * v), fma((v * v), (0.041666666666666664 + ((-0.019444444444444445 * ((-1.0 - e) / e)) - 0.08333333333333333)), (-0.5 - (fma(e, -0.16666666666666666, -0.16666666666666666) / e))), (1.0 + (1.0 / e))) / v);
}
function code(e, v) return Float64(1.0 / Float64(fma(Float64(v * v), fma(Float64(v * v), Float64(0.041666666666666664 + Float64(Float64(-0.019444444444444445 * Float64(Float64(-1.0 - e) / e)) - 0.08333333333333333)), Float64(-0.5 - Float64(fma(e, -0.16666666666666666, -0.16666666666666666) / e))), Float64(1.0 + Float64(1.0 / e))) / v)) end
code[e_, v_] := N[(1.0 / N[(N[(N[(v * v), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] * N[(0.041666666666666664 + N[(N[(-0.019444444444444445 * N[(N[(-1.0 - e), $MachinePrecision] / e), $MachinePrecision]), $MachinePrecision] - 0.08333333333333333), $MachinePrecision]), $MachinePrecision] + 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] / v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\mathsf{fma}\left(v \cdot v, \mathsf{fma}\left(v \cdot v, 0.041666666666666664 + \left(-0.019444444444444445 \cdot \frac{-1 - e}{e} - 0.08333333333333333\right), -0.5 - \frac{\mathsf{fma}\left(e, -0.16666666666666666, -0.16666666666666666\right)}{e}\right), 1 + \frac{1}{e}\right)}{v}}
\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.f6499.0
Applied egg-rr99.0%
Taylor expanded in v around 0
/-lowering-/.f64N/A
Simplified59.3%
Final simplification59.3%
(FPCore (e v)
:precision binary64
(if (<= v 8.2e-10)
(* v (/ e (+ e 1.0)))
(/
1.0
(/
(fma
(/ (* v v) e)
(fma (* v v) 0.019444444444444445 0.16666666666666666)
(/ 1.0 e))
v))))
double code(double e, double v) {
double tmp;
if (v <= 8.2e-10) {
tmp = v * (e / (e + 1.0));
} else {
tmp = 1.0 / (fma(((v * v) / e), fma((v * v), 0.019444444444444445, 0.16666666666666666), (1.0 / e)) / v);
}
return tmp;
}
function code(e, v) tmp = 0.0 if (v <= 8.2e-10) tmp = Float64(v * Float64(e / Float64(e + 1.0))); else tmp = Float64(1.0 / Float64(fma(Float64(Float64(v * v) / e), fma(Float64(v * v), 0.019444444444444445, 0.16666666666666666), Float64(1.0 / e)) / v)); end return tmp end
code[e_, v_] := If[LessEqual[v, 8.2e-10], N[(v * N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(N[(v * v), $MachinePrecision] / e), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] * 0.019444444444444445 + 0.16666666666666666), $MachinePrecision] + N[(1.0 / e), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 8.2 \cdot 10^{-10}:\\
\;\;\;\;v \cdot \frac{e}{e + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(\frac{v \cdot v}{e}, \mathsf{fma}\left(v \cdot v, 0.019444444444444445, 0.16666666666666666\right), \frac{1}{e}\right)}{v}}\\
\end{array}
\end{array}
if v < 8.1999999999999996e-10Initial program 99.9%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6471.2
Simplified71.2%
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6471.2
Applied egg-rr71.2%
if 8.1999999999999996e-10 < v Initial program 99.7%
Taylor expanded in e around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6497.3
Simplified97.3%
/-rgt-identityN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6497.2
Applied egg-rr97.2%
Taylor expanded in v around 0
/-lowering-/.f64N/A
Simplified16.8%
Final simplification59.3%
(FPCore (e v)
:precision binary64
(/
1.0
(/
(+
1.0
(fma
(* v v)
(- -0.5 (/ (fma e -0.16666666666666666 -0.16666666666666666) e))
(/ 1.0 e)))
v)))
double code(double e, double v) {
return 1.0 / ((1.0 + fma((v * v), (-0.5 - (fma(e, -0.16666666666666666, -0.16666666666666666) / e)), (1.0 / e))) / v);
}
function code(e, v) return Float64(1.0 / Float64(Float64(1.0 + fma(Float64(v * v), Float64(-0.5 - Float64(fma(e, -0.16666666666666666, -0.16666666666666666) / e)), Float64(1.0 / e))) / v)) end
code[e_, v_] := N[(1.0 / N[(N[(1.0 + N[(N[(v * v), $MachinePrecision] * N[(-0.5 - N[(N[(e * -0.16666666666666666 + -0.16666666666666666), $MachinePrecision] / e), $MachinePrecision]), $MachinePrecision] + N[(1.0 / e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1 + \mathsf{fma}\left(v \cdot v, -0.5 - \frac{\mathsf{fma}\left(e, -0.16666666666666666, -0.16666666666666666\right)}{e}, \frac{1}{e}\right)}{v}}
\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.f6499.0
Applied egg-rr99.0%
Taylor expanded in v around 0
/-lowering-/.f64N/A
Simplified59.0%
(FPCore (e v) :precision binary64 (if (<= v 8.2e-10) (* v (/ e (+ e 1.0))) (/ 1.0 (/ (* (/ 1.0 e) (fma (* v v) 0.16666666666666666 1.0)) v))))
double code(double e, double v) {
double tmp;
if (v <= 8.2e-10) {
tmp = v * (e / (e + 1.0));
} else {
tmp = 1.0 / (((1.0 / e) * fma((v * v), 0.16666666666666666, 1.0)) / v);
}
return tmp;
}
function code(e, v) tmp = 0.0 if (v <= 8.2e-10) tmp = Float64(v * Float64(e / Float64(e + 1.0))); else tmp = Float64(1.0 / Float64(Float64(Float64(1.0 / e) * fma(Float64(v * v), 0.16666666666666666, 1.0)) / v)); end return tmp end
code[e_, v_] := If[LessEqual[v, 8.2e-10], N[(v * N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(1.0 / e), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] * 0.16666666666666666 + 1.0), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 8.2 \cdot 10^{-10}:\\
\;\;\;\;v \cdot \frac{e}{e + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{e} \cdot \mathsf{fma}\left(v \cdot v, 0.16666666666666666, 1\right)}{v}}\\
\end{array}
\end{array}
if v < 8.1999999999999996e-10Initial program 99.9%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6471.2
Simplified71.2%
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6471.2
Applied egg-rr71.2%
if 8.1999999999999996e-10 < v Initial program 99.7%
Taylor expanded in e around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6497.3
Simplified97.3%
/-rgt-identityN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6497.2
Applied egg-rr97.2%
Taylor expanded in v around 0
associate-*r/N/A
associate-*l/N/A
metadata-evalN/A
associate-*r/N/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
distribute-lft1-inN/A
*-lowering-*.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6416.5
Simplified16.5%
Final simplification59.2%
(FPCore (e v) :precision binary64 (* v (/ e (+ e 1.0))))
double code(double e, double v) {
return v * (e / (e + 1.0));
}
real(8) function code(e, v)
real(8), intent (in) :: e
real(8), intent (in) :: v
code = v * (e / (e + 1.0d0))
end function
public static double code(double e, double v) {
return v * (e / (e + 1.0));
}
def code(e, v): return v * (e / (e + 1.0))
function code(e, v) return Float64(v * Float64(e / Float64(e + 1.0))) end
function tmp = code(e, v) tmp = v * (e / (e + 1.0)); end
code[e_, v_] := N[(v * N[(e / N[(e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
v \cdot \frac{e}{e + 1}
\end{array}
Initial program 99.8%
Taylor expanded in v around 0
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f6458.1
Simplified58.1%
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f6458.2
Applied egg-rr58.2%
Final simplification58.2%
(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-+.f6458.1
Simplified58.1%
Taylor expanded in e around 0
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6457.8
Simplified57.8%
Final simplification57.8%
(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 e around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6498.2
Simplified98.2%
Taylor expanded in v around 0
Simplified57.3%
Final simplification57.3%
(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-+.f6458.1
Simplified58.1%
Taylor expanded in e around inf
Simplified5.0%
herbie shell --seed 2024199
(FPCore (e v)
:name "Trigonometry A"
:precision binary64
:pre (and (<= 0.0 e) (<= e 1.0))
(/ (* e (sin v)) (+ 1.0 (* e (cos v)))))