
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (fma (cos b) (cos a) (* (sin a) (- (sin b)))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(cos(b), cos(a), (sin(a) * -sin(b))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(cos(b), cos(a), Float64(sin(a) * Float64(-sin(b)))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin a \cdot \left(-\sin b\right)\right)}
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
fma-neg99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (* (cos b) (cos a)))))
double code(double r, double a, double b) {
return r * (sin(b) / (cos(b) * cos(a)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / (cos(b) * cos(a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / (Math.cos(b) * Math.cos(a)));
}
def code(r, a, b): return r * (math.sin(b) / (math.cos(b) * math.cos(a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(cos(b) * cos(a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / (cos(b) * cos(a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a}
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
Applied egg-rr99.5%
sin-mult78.3%
div-sub78.3%
cos-diff78.0%
add-sqr-sqrt38.9%
sqrt-unprod77.2%
sqr-neg77.2%
sqrt-unprod48.5%
add-sqr-sqrt77.0%
sub-neg77.0%
cos-sum78.2%
Applied egg-rr78.2%
+-inverses78.2%
Simplified78.2%
Final simplification78.2%
(FPCore (r a b) :precision binary64 (if (<= b -5.4e-6) (* r (/ (sin b) (cos b))) (if (<= b 54.0) (* r (/ b (cos a))) (* r (tan b)))))
double code(double r, double a, double b) {
double tmp;
if (b <= -5.4e-6) {
tmp = r * (sin(b) / cos(b));
} else if (b <= 54.0) {
tmp = r * (b / cos(a));
} else {
tmp = r * tan(b);
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-5.4d-6)) then
tmp = r * (sin(b) / cos(b))
else if (b <= 54.0d0) then
tmp = r * (b / cos(a))
else
tmp = r * tan(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -5.4e-6) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else if (b <= 54.0) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r * Math.tan(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -5.4e-6: tmp = r * (math.sin(b) / math.cos(b)) elif b <= 54.0: tmp = r * (b / math.cos(a)) else: tmp = r * math.tan(b) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -5.4e-6) tmp = Float64(r * Float64(sin(b) / cos(b))); elseif (b <= 54.0) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r * tan(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -5.4e-6) tmp = r * (sin(b) / cos(b)); elseif (b <= 54.0) tmp = r * (b / cos(a)); else tmp = r * tan(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -5.4e-6], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 54.0], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.4 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{elif}\;b \leq 54:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \tan b\\
\end{array}
\end{array}
if b < -5.39999999999999997e-6Initial program 59.8%
+-commutative59.8%
Simplified59.8%
Taylor expanded in a around 0 59.7%
if -5.39999999999999997e-6 < b < 54Initial program 98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in b around 0 99.0%
if 54 < b Initial program 48.7%
+-commutative48.7%
Simplified48.7%
expm1-log1p-u48.7%
Applied egg-rr48.7%
Taylor expanded in a around 0 49.3%
log1p-define49.5%
Simplified49.5%
expm1-log1p-u49.4%
quot-tan49.5%
Applied egg-rr49.5%
Final simplification77.4%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ b a)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((b + a)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((b + a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((b + a)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((b + a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((b + a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(b + a\right)}
\end{array}
Initial program 77.2%
Final simplification77.2%
(FPCore (r a b) :precision binary64 (if (or (<= b -6.4e-6) (not (<= b 54.0))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -6.4e-6) || !(b <= 54.0)) {
tmp = r * tan(b);
} else {
tmp = r * (b / cos(a));
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-6.4d-6)) .or. (.not. (b <= 54.0d0))) then
tmp = r * tan(b)
else
tmp = r * (b / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -6.4e-6) || !(b <= 54.0)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -6.4e-6) or not (b <= 54.0): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -6.4e-6) || !(b <= 54.0)) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -6.4e-6) || ~((b <= 54.0))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -6.4e-6], N[Not[LessEqual[b, 54.0]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.4 \cdot 10^{-6} \lor \neg \left(b \leq 54\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -6.3999999999999997e-6 or 54 < b Initial program 54.1%
+-commutative54.1%
Simplified54.1%
expm1-log1p-u54.0%
Applied egg-rr54.0%
Taylor expanded in a around 0 54.2%
log1p-define54.4%
Simplified54.4%
expm1-log1p-u54.4%
quot-tan54.4%
Applied egg-rr54.4%
if -6.3999999999999997e-6 < b < 54Initial program 98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in b around 0 99.0%
Final simplification77.4%
(FPCore (r a b) :precision binary64 (* r (tan b)))
double code(double r, double a, double b) {
return r * tan(b);
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * tan(b)
end function
public static double code(double r, double a, double b) {
return r * Math.tan(b);
}
def code(r, a, b): return r * math.tan(b)
function code(r, a, b) return Float64(r * tan(b)) end
function tmp = code(r, a, b) tmp = r * tan(b); end
code[r_, a_, b_] := N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \tan b
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
expm1-log1p-u77.1%
Applied egg-rr77.1%
Taylor expanded in a around 0 58.4%
log1p-define58.5%
Simplified58.5%
expm1-log1p-u58.5%
quot-tan58.6%
Applied egg-rr58.6%
Final simplification58.6%
(FPCore (r a b) :precision binary64 (/ r (+ (* b -0.3333333333333333) (/ 1.0 b))))
double code(double r, double a, double b) {
return r / ((b * -0.3333333333333333) + (1.0 / b));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r / ((b * (-0.3333333333333333d0)) + (1.0d0 / b))
end function
public static double code(double r, double a, double b) {
return r / ((b * -0.3333333333333333) + (1.0 / b));
}
def code(r, a, b): return r / ((b * -0.3333333333333333) + (1.0 / b))
function code(r, a, b) return Float64(r / Float64(Float64(b * -0.3333333333333333) + Float64(1.0 / b))) end
function tmp = code(r, a, b) tmp = r / ((b * -0.3333333333333333) + (1.0 / b)); end
code[r_, a_, b_] := N[(r / N[(N[(b * -0.3333333333333333), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{b \cdot -0.3333333333333333 + \frac{1}{b}}
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
fma-neg99.6%
Applied egg-rr99.6%
Taylor expanded in r around 0 99.5%
associate-/l*99.4%
Simplified99.4%
Taylor expanded in b around 0 54.1%
Taylor expanded in a around 0 35.1%
Final simplification35.1%
(FPCore (r a b) :precision binary64 (* r b))
double code(double r, double a, double b) {
return r * b;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * b
end function
public static double code(double r, double a, double b) {
return r * b;
}
def code(r, a, b): return r * b
function code(r, a, b) return Float64(r * b) end
function tmp = code(r, a, b) tmp = r * b; end
code[r_, a_, b_] := N[(r * b), $MachinePrecision]
\begin{array}{l}
\\
r \cdot b
\end{array}
Initial program 77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in b around 0 53.6%
Taylor expanded in a around 0 34.7%
Final simplification34.7%
herbie shell --seed 2024034
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))