
(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) (- (* (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 78.8%
+-commutative78.8%
Simplified78.8%
cos-sum99.6%
Applied egg-rr99.6%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ (sin b) (cos (+ b a)))))
(if (<= t_0 -0.002)
(* r (tan b))
(if (<= t_0 1e-17) (* r (/ b (cos a))) (* r (fabs (tan b)))))))
double code(double r, double a, double b) {
double t_0 = sin(b) / cos((b + a));
double tmp;
if (t_0 <= -0.002) {
tmp = r * tan(b);
} else if (t_0 <= 1e-17) {
tmp = r * (b / cos(a));
} else {
tmp = r * fabs(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) :: t_0
real(8) :: tmp
t_0 = sin(b) / cos((b + a))
if (t_0 <= (-0.002d0)) then
tmp = r * tan(b)
else if (t_0 <= 1d-17) then
tmp = r * (b / cos(a))
else
tmp = r * abs(tan(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = Math.sin(b) / Math.cos((b + a));
double tmp;
if (t_0 <= -0.002) {
tmp = r * Math.tan(b);
} else if (t_0 <= 1e-17) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r * Math.abs(Math.tan(b));
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) / math.cos((b + a)) tmp = 0 if t_0 <= -0.002: tmp = r * math.tan(b) elif t_0 <= 1e-17: tmp = r * (b / math.cos(a)) else: tmp = r * math.fabs(math.tan(b)) return tmp
function code(r, a, b) t_0 = Float64(sin(b) / cos(Float64(b + a))) tmp = 0.0 if (t_0 <= -0.002) tmp = Float64(r * tan(b)); elseif (t_0 <= 1e-17) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r * abs(tan(b))); end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) / cos((b + a)); tmp = 0.0; if (t_0 <= -0.002) tmp = r * tan(b); elseif (t_0 <= 1e-17) tmp = r * (b / cos(a)); else tmp = r * abs(tan(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.002], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-17], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Abs[N[Tan[b], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
\mathbf{if}\;t\_0 \leq -0.002:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{elif}\;t\_0 \leq 10^{-17}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \left|\tan b\right|\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -2e-3Initial program 63.3%
+-commutative63.3%
Simplified63.3%
add-log-exp62.7%
Applied egg-rr62.7%
Taylor expanded in a around 0 62.8%
rem-log-exp63.4%
clear-num63.2%
un-div-inv63.3%
clear-num63.3%
quot-tan63.4%
Applied egg-rr63.4%
associate-/r/63.5%
/-rgt-identity63.5%
Simplified63.5%
if -2e-3 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 1.00000000000000007e-17Initial program 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 99.7%
*-commutative99.7%
associate-/l*99.8%
Simplified99.8%
if 1.00000000000000007e-17 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 53.2%
+-commutative53.2%
Simplified53.2%
add-log-exp51.3%
Applied egg-rr51.3%
Taylor expanded in a around 0 50.8%
rem-log-exp52.7%
add-sqr-sqrt52.0%
sqrt-unprod53.2%
pow253.2%
quot-tan53.2%
Applied egg-rr53.2%
unpow253.2%
rem-sqrt-square53.2%
Simplified53.2%
Final simplification78.9%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ (sin b) (cos (+ b a)))))
(if (or (<= t_0 -0.002) (not (<= t_0 1e-17)))
(* r (tan b))
(* r (/ b (cos a))))))
double code(double r, double a, double b) {
double t_0 = sin(b) / cos((b + a));
double tmp;
if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) {
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) :: t_0
real(8) :: tmp
t_0 = sin(b) / cos((b + a))
if ((t_0 <= (-0.002d0)) .or. (.not. (t_0 <= 1d-17))) 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 t_0 = Math.sin(b) / Math.cos((b + a));
double tmp;
if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) / math.cos((b + a)) tmp = 0 if (t_0 <= -0.002) or not (t_0 <= 1e-17): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) t_0 = Float64(sin(b) / cos(Float64(b + a))) tmp = 0.0 if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) / cos((b + a)); tmp = 0.0; if ((t_0 <= -0.002) || ~((t_0 <= 1e-17))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.002], N[Not[LessEqual[t$95$0, 1e-17]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
\mathbf{if}\;t\_0 \leq -0.002 \lor \neg \left(t\_0 \leq 10^{-17}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -2e-3 or 1.00000000000000007e-17 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 58.5%
+-commutative58.5%
Simplified58.5%
add-log-exp57.3%
Applied egg-rr57.3%
Taylor expanded in a around 0 57.1%
rem-log-exp58.3%
clear-num58.2%
un-div-inv58.2%
clear-num58.2%
quot-tan58.2%
Applied egg-rr58.2%
associate-/r/58.4%
/-rgt-identity58.4%
Simplified58.4%
if -2e-3 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 1.00000000000000007e-17Initial program 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 99.7%
*-commutative99.7%
associate-/l*99.8%
Simplified99.8%
Final simplification78.8%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ (sin b) (cos (+ b a)))))
(if (or (<= t_0 -0.002) (not (<= t_0 1e-17)))
(* r (tan b))
(* b (/ r (cos a))))))
double code(double r, double a, double b) {
double t_0 = sin(b) / cos((b + a));
double tmp;
if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) {
tmp = r * tan(b);
} else {
tmp = b * (r / 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) :: t_0
real(8) :: tmp
t_0 = sin(b) / cos((b + a))
if ((t_0 <= (-0.002d0)) .or. (.not. (t_0 <= 1d-17))) then
tmp = r * tan(b)
else
tmp = b * (r / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = Math.sin(b) / Math.cos((b + a));
double tmp;
if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) / math.cos((b + a)) tmp = 0 if (t_0 <= -0.002) or not (t_0 <= 1e-17): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) t_0 = Float64(sin(b) / cos(Float64(b + a))) tmp = 0.0 if ((t_0 <= -0.002) || !(t_0 <= 1e-17)) tmp = Float64(r * tan(b)); else tmp = Float64(b * Float64(r / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) / cos((b + a)); tmp = 0.0; if ((t_0 <= -0.002) || ~((t_0 <= 1e-17))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.002], N[Not[LessEqual[t$95$0, 1e-17]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
\mathbf{if}\;t\_0 \leq -0.002 \lor \neg \left(t\_0 \leq 10^{-17}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -2e-3 or 1.00000000000000007e-17 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 58.5%
+-commutative58.5%
Simplified58.5%
add-log-exp57.3%
Applied egg-rr57.3%
Taylor expanded in a around 0 57.1%
rem-log-exp58.3%
clear-num58.2%
un-div-inv58.2%
clear-num58.2%
quot-tan58.2%
Applied egg-rr58.2%
associate-/r/58.4%
/-rgt-identity58.4%
Simplified58.4%
if -2e-3 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 1.00000000000000007e-17Initial program 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 99.7%
associate-/l*99.7%
Simplified99.7%
Final simplification78.7%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (+ (* (cos b) (cos a)) (* (sin a) 0.0)))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) + (sin(a) * 0.0)));
}
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(a) * 0.0d0)))
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(a) * 0.0)));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) + (math.sin(a) * 0.0)))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) + Float64(sin(a) * 0.0)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(b) * cos(a)) + (sin(a) * 0.0))); 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[a], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a + \sin a \cdot 0}
\end{array}
Initial program 78.8%
+-commutative78.8%
Simplified78.8%
cos-sum99.6%
Applied egg-rr99.6%
expm1-log1p-u99.6%
expm1-undefine99.6%
Applied egg-rr99.6%
expm1-define99.6%
Simplified99.6%
expm1-undefine99.6%
log1p-undefine99.5%
rem-exp-log99.6%
+-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in b around 0 80.1%
Final simplification80.1%
(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 78.8%
Final simplification78.8%
(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 78.8%
+-commutative78.8%
Simplified78.8%
add-log-exp41.0%
Applied egg-rr41.0%
Taylor expanded in a around 0 40.9%
rem-log-exp58.9%
clear-num58.8%
un-div-inv58.7%
clear-num58.7%
quot-tan58.7%
Applied egg-rr58.7%
associate-/r/58.9%
/-rgt-identity58.9%
Simplified58.9%
(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 78.8%
+-commutative78.8%
Simplified78.8%
Taylor expanded in b around 0 52.0%
associate-/l*52.0%
Simplified52.0%
Taylor expanded in a around 0 32.2%
Final simplification32.2%
herbie shell --seed 2024191
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))