
(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 8 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 (sin a) (- (sin b)) (* (cos a) (cos b))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(sin(a), -sin(b), (cos(a) * cos(b))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(sin(a), Float64(-sin(b)), Float64(cos(a) * cos(b))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin a, -\sin b, \cos a \cdot \cos b\right)}
\end{array}
Initial program 75.3%
+-commutative75.3%
Simplified75.3%
cos-sum99.5%
Applied egg-rr99.5%
Taylor expanded in b around inf 99.5%
sub-neg99.5%
*-commutative99.5%
distribute-rgt-neg-out99.5%
+-commutative99.5%
fma-def99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* (cos a) (cos b)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(a) * cos(b)) - (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(a) * cos(b)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(a) * Math.cos(b)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(a) * math.cos(b)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(a) * cos(b)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(a) * cos(b)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a}
\end{array}
Initial program 75.3%
+-commutative75.3%
Simplified75.3%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (<= b -5e+21) (* r (tan b)) (if (<= b 1.9) (* r (/ b (cos (+ b a)))) (/ (sin b) (/ (cos b) r)))))
double code(double r, double a, double b) {
double tmp;
if (b <= -5e+21) {
tmp = r * tan(b);
} else if (b <= 1.9) {
tmp = r * (b / cos((b + a)));
} else {
tmp = sin(b) / (cos(b) / r);
}
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 <= (-5d+21)) then
tmp = r * tan(b)
else if (b <= 1.9d0) then
tmp = r * (b / cos((b + a)))
else
tmp = sin(b) / (cos(b) / r)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -5e+21) {
tmp = r * Math.tan(b);
} else if (b <= 1.9) {
tmp = r * (b / Math.cos((b + a)));
} else {
tmp = Math.sin(b) / (Math.cos(b) / r);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -5e+21: tmp = r * math.tan(b) elif b <= 1.9: tmp = r * (b / math.cos((b + a))) else: tmp = math.sin(b) / (math.cos(b) / r) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -5e+21) tmp = Float64(r * tan(b)); elseif (b <= 1.9) tmp = Float64(r * Float64(b / cos(Float64(b + a)))); else tmp = Float64(sin(b) / Float64(cos(b) / r)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -5e+21) tmp = r * tan(b); elseif (b <= 1.9) tmp = r * (b / cos((b + a))); else tmp = sin(b) / (cos(b) / r); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -5e+21], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+21}:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{elif}\;b \leq 1.9:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin b}{\frac{\cos b}{r}}\\
\end{array}
\end{array}
if b < -5e21Initial program 59.9%
+-commutative59.9%
Simplified59.9%
associate-*r/59.9%
expm1-log1p-u42.2%
*-commutative42.2%
Applied egg-rr42.2%
Taylor expanded in a around 0 41.8%
expm1-log1p-u60.0%
div-inv60.0%
*-commutative60.0%
associate-*l*60.0%
Applied egg-rr60.0%
expm1-log1p-u47.6%
expm1-udef47.4%
un-div-inv47.4%
quot-tan47.4%
Applied egg-rr47.4%
expm1-def47.7%
expm1-log1p60.1%
Simplified60.1%
if -5e21 < b < 1.8999999999999999Initial program 96.6%
+-commutative96.6%
Simplified96.6%
Taylor expanded in b around 0 96.6%
if 1.8999999999999999 < b Initial program 49.5%
*-commutative49.5%
associate-/r/49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in a around 0 50.8%
Final simplification75.6%
(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 75.3%
Final simplification75.3%
(FPCore (r a b) :precision binary64 (if (or (<= b -5e+21) (not (<= b 1.9))) (* r (tan b)) (* r (/ b (cos (+ b a))))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -5e+21) || !(b <= 1.9)) {
tmp = r * tan(b);
} else {
tmp = r * (b / cos((b + 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 <= (-5d+21)) .or. (.not. (b <= 1.9d0))) then
tmp = r * tan(b)
else
tmp = r * (b / cos((b + a)))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -5e+21) || !(b <= 1.9)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos((b + a)));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -5e+21) or not (b <= 1.9): tmp = r * math.tan(b) else: tmp = r * (b / math.cos((b + a))) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -5e+21) || !(b <= 1.9)) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(b / cos(Float64(b + a)))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -5e+21) || ~((b <= 1.9))) tmp = r * tan(b); else tmp = r * (b / cos((b + a))); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -5e+21], N[Not[LessEqual[b, 1.9]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+21} \lor \neg \left(b \leq 1.9\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
if b < -5e21 or 1.8999999999999999 < b Initial program 54.9%
+-commutative54.9%
Simplified54.9%
associate-*r/54.9%
expm1-log1p-u39.5%
*-commutative39.5%
Applied egg-rr39.5%
Taylor expanded in a around 0 39.7%
expm1-log1p-u55.5%
div-inv55.5%
*-commutative55.5%
associate-*l*55.5%
Applied egg-rr55.5%
expm1-log1p-u44.0%
expm1-udef43.8%
un-div-inv43.9%
quot-tan43.9%
Applied egg-rr43.9%
expm1-def44.1%
expm1-log1p55.6%
Simplified55.6%
if -5e21 < b < 1.8999999999999999Initial program 96.6%
+-commutative96.6%
Simplified96.6%
Taylor expanded in b around 0 96.6%
Final simplification75.6%
(FPCore (r a b) :precision binary64 (if (or (<= b -5e+21) (not (<= b 1.9))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -5e+21) || !(b <= 1.9)) {
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 <= (-5d+21)) .or. (.not. (b <= 1.9d0))) 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 <= -5e+21) || !(b <= 1.9)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -5e+21) or not (b <= 1.9): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -5e+21) || !(b <= 1.9)) 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 <= -5e+21) || ~((b <= 1.9))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -5e+21], N[Not[LessEqual[b, 1.9]], $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 -5 \cdot 10^{+21} \lor \neg \left(b \leq 1.9\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -5e21 or 1.8999999999999999 < b Initial program 54.9%
+-commutative54.9%
Simplified54.9%
associate-*r/54.9%
expm1-log1p-u39.5%
*-commutative39.5%
Applied egg-rr39.5%
Taylor expanded in a around 0 39.7%
expm1-log1p-u55.5%
div-inv55.5%
*-commutative55.5%
associate-*l*55.5%
Applied egg-rr55.5%
expm1-log1p-u44.0%
expm1-udef43.8%
un-div-inv43.9%
quot-tan43.9%
Applied egg-rr43.9%
expm1-def44.1%
expm1-log1p55.6%
Simplified55.6%
if -5e21 < b < 1.8999999999999999Initial program 96.6%
+-commutative96.6%
Simplified96.6%
Taylor expanded in b around 0 96.5%
Final simplification75.6%
(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 75.3%
+-commutative75.3%
Simplified75.3%
associate-*r/75.2%
expm1-log1p-u59.1%
*-commutative59.1%
Applied egg-rr59.1%
Taylor expanded in a around 0 46.4%
expm1-log1p-u59.1%
div-inv59.1%
*-commutative59.1%
associate-*l*59.1%
Applied egg-rr59.1%
expm1-log1p-u53.3%
expm1-udef37.0%
un-div-inv37.0%
quot-tan37.0%
Applied egg-rr37.0%
expm1-def53.3%
expm1-log1p59.2%
Simplified59.2%
Final simplification59.2%
(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 75.3%
+-commutative75.3%
Simplified75.3%
Taylor expanded in b around 0 48.9%
Taylor expanded in a around 0 32.6%
Final simplification32.6%
herbie shell --seed 2023182
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))