
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (/ r (- (/ (cos a) (tan b)) (sin a))))
double code(double r, double a, double b) {
return r / ((cos(a) / tan(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 / ((cos(a) / tan(b)) - sin(a))
end function
public static double code(double r, double a, double b) {
return r / ((Math.cos(a) / Math.tan(b)) - Math.sin(a));
}
def code(r, a, b): return r / ((math.cos(a) / math.tan(b)) - math.sin(a))
function code(r, a, b) return Float64(r / Float64(Float64(cos(a) / tan(b)) - sin(a))) end
function tmp = code(r, a, b) tmp = r / ((cos(a) / tan(b)) - sin(a)); end
code[r_, a_, b_] := N[(r / N[(N[(N[Cos[a], $MachinePrecision] / N[Tan[b], $MachinePrecision]), $MachinePrecision] - N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\frac{\cos a}{\tan b} - \sin a}
\end{array}
Initial program 81.3%
associate-/l*81.4%
+-commutative81.4%
Simplified81.4%
cos-sum99.5%
div-sub99.5%
Applied egg-rr99.5%
associate-/l*99.5%
associate-/l*99.5%
Simplified99.5%
expm1-log1p-u77.8%
expm1-udef36.2%
Applied egg-rr36.2%
expm1-def77.8%
expm1-log1p99.5%
fma-udef99.5%
unsub-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -1.32e-5) (not (<= a 1.25e-23))) (* r (/ (sin b) (cos a))) (* r (tan b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -1.32e-5) || !(a <= 1.25e-23)) {
tmp = r * (sin(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 ((a <= (-1.32d-5)) .or. (.not. (a <= 1.25d-23))) then
tmp = r * (sin(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 ((a <= -1.32e-5) || !(a <= 1.25e-23)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = r * Math.tan(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -1.32e-5) or not (a <= 1.25e-23): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = r * math.tan(b) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -1.32e-5) || !(a <= 1.25e-23)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(r * tan(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -1.32e-5) || ~((a <= 1.25e-23))) tmp = r * (sin(b) / cos(a)); else tmp = r * tan(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -1.32e-5], N[Not[LessEqual[a, 1.25e-23]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.32 \cdot 10^{-5} \lor \neg \left(a \leq 1.25 \cdot 10^{-23}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \tan b\\
\end{array}
\end{array}
if a < -1.32000000000000007e-5 or 1.2500000000000001e-23 < a Initial program 58.7%
associate-/l*58.8%
remove-double-neg58.8%
sin-neg58.8%
neg-mul-158.8%
associate-/r*58.8%
associate-/l*58.7%
*-commutative58.7%
associate-*l/58.8%
associate-/l*58.8%
sin-neg58.8%
distribute-lft-neg-in58.8%
distribute-rgt-neg-in58.8%
associate-/l*58.8%
metadata-eval58.8%
/-rgt-identity58.8%
+-commutative58.8%
Simplified58.8%
Taylor expanded in b around 0 58.2%
if -1.32000000000000007e-5 < a < 1.2500000000000001e-23Initial program 99.3%
+-commutative99.3%
Simplified99.3%
log1p-expm1-u56.8%
log1p-udef16.8%
*-commutative16.8%
Applied egg-rr16.8%
add-exp-log15.0%
log1p-def30.9%
log1p-expm1-u51.4%
Applied egg-rr51.4%
Taylor expanded in a around 0 51.4%
rem-exp-log99.3%
associate-*l/99.3%
quot-tan99.3%
Applied egg-rr99.3%
Final simplification81.2%
(FPCore (r a b) :precision binary64 (if (<= a -5.3e-5) (/ r (/ (cos a) (sin b))) (if (<= a 1.25e-23) (* r (tan b)) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
double tmp;
if (a <= -5.3e-5) {
tmp = r / (cos(a) / sin(b));
} else if (a <= 1.25e-23) {
tmp = r * tan(b);
} else {
tmp = r * (sin(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 (a <= (-5.3d-5)) then
tmp = r / (cos(a) / sin(b))
else if (a <= 1.25d-23) then
tmp = r * tan(b)
else
tmp = r * (sin(b) / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (a <= -5.3e-5) {
tmp = r / (Math.cos(a) / Math.sin(b));
} else if (a <= 1.25e-23) {
tmp = r * Math.tan(b);
} else {
tmp = r * (Math.sin(b) / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -5.3e-5: tmp = r / (math.cos(a) / math.sin(b)) elif a <= 1.25e-23: tmp = r * math.tan(b) else: tmp = r * (math.sin(b) / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -5.3e-5) tmp = Float64(r / Float64(cos(a) / sin(b))); elseif (a <= 1.25e-23) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(sin(b) / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -5.3e-5) tmp = r / (cos(a) / sin(b)); elseif (a <= 1.25e-23) tmp = r * tan(b); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -5.3e-5], N[(r / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.25e-23], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.3 \cdot 10^{-5}:\\
\;\;\;\;\frac{r}{\frac{\cos a}{\sin b}}\\
\mathbf{elif}\;a \leq 1.25 \cdot 10^{-23}:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
if a < -5.3000000000000001e-5Initial program 57.2%
associate-/l*57.5%
+-commutative57.5%
Simplified57.5%
Taylor expanded in b around 0 57.2%
if -5.3000000000000001e-5 < a < 1.2500000000000001e-23Initial program 99.3%
+-commutative99.3%
Simplified99.3%
log1p-expm1-u56.8%
log1p-udef16.8%
*-commutative16.8%
Applied egg-rr16.8%
add-exp-log15.0%
log1p-def30.9%
log1p-expm1-u51.4%
Applied egg-rr51.4%
Taylor expanded in a around 0 51.4%
rem-exp-log99.3%
associate-*l/99.3%
quot-tan99.3%
Applied egg-rr99.3%
if 1.2500000000000001e-23 < a Initial program 59.7%
associate-/l*59.7%
remove-double-neg59.7%
sin-neg59.7%
neg-mul-159.7%
associate-/r*59.7%
associate-/l*59.7%
*-commutative59.7%
associate-*l/59.8%
associate-/l*59.8%
sin-neg59.8%
distribute-lft-neg-in59.8%
distribute-rgt-neg-in59.8%
associate-/l*59.8%
metadata-eval59.8%
/-rgt-identity59.8%
+-commutative59.8%
Simplified59.8%
Taylor expanded in b around 0 58.9%
Final simplification81.2%
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos (+ a b)))))
double code(double r, double a, double b) {
return sin(b) * (r / 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 = sin(b) * (r / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * (r / Math.cos((a + b)));
}
def code(r, a, b): return math.sin(b) * (r / math.cos((a + b)))
function code(r, a, b) return Float64(sin(b) * Float64(r / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = sin(b) * (r / cos((a + b))); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot \frac{r}{\cos \left(a + b\right)}
\end{array}
Initial program 81.3%
associate-/l*81.4%
+-commutative81.4%
Simplified81.4%
associate-/r/81.1%
Applied egg-rr81.1%
Final simplification81.1%
(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}
Initial program 81.3%
associate-/l*81.4%
remove-double-neg81.4%
sin-neg81.4%
neg-mul-181.4%
associate-/r*81.4%
associate-/l*81.3%
*-commutative81.3%
associate-*l/81.4%
associate-/l*81.4%
sin-neg81.4%
distribute-lft-neg-in81.4%
distribute-rgt-neg-in81.4%
associate-/l*81.4%
metadata-eval81.4%
/-rgt-identity81.4%
+-commutative81.4%
Simplified81.4%
Final simplification81.4%
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a - b\right)}
\end{array}
Initial program 81.3%
+-commutative81.3%
Simplified81.3%
cos-sum99.5%
sub-neg99.5%
Applied egg-rr99.5%
+-commutative99.5%
distribute-lft-neg-in99.5%
*-commutative99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
fma-udef99.5%
+-commutative99.5%
add-sqr-sqrt50.4%
sqrt-unprod91.2%
sqr-neg91.2%
sqrt-unprod40.8%
add-sqr-sqrt81.2%
cos-diff81.5%
Applied egg-rr81.5%
Final simplification81.5%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.5e-6) (not (<= b 1.5e-7))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.5e-6) || !(b <= 1.5e-7)) {
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 <= (-2.5d-6)) .or. (.not. (b <= 1.5d-7))) 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 <= -2.5e-6) || !(b <= 1.5e-7)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.5e-6) or not (b <= 1.5e-7): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.5e-6) || !(b <= 1.5e-7)) 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 <= -2.5e-6) || ~((b <= 1.5e-7))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.5e-6], N[Not[LessEqual[b, 1.5e-7]], $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 -2.5 \cdot 10^{-6} \lor \neg \left(b \leq 1.5 \cdot 10^{-7}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -2.5000000000000002e-6 or 1.4999999999999999e-7 < b Initial program 63.5%
+-commutative63.5%
Simplified63.5%
log1p-expm1-u29.1%
log1p-udef5.6%
*-commutative5.6%
Applied egg-rr5.6%
add-exp-log4.5%
log1p-def12.8%
log1p-expm1-u30.7%
Applied egg-rr30.7%
Taylor expanded in a around 0 30.1%
rem-exp-log62.5%
associate-*l/62.5%
quot-tan62.5%
Applied egg-rr62.5%
if -2.5000000000000002e-6 < b < 1.4999999999999999e-7Initial program 99.5%
associate-/l*99.5%
remove-double-neg99.5%
sin-neg99.5%
neg-mul-199.5%
associate-/r*99.5%
associate-/l*99.5%
*-commutative99.5%
associate-*l/99.6%
associate-/l*99.6%
sin-neg99.6%
distribute-lft-neg-in99.6%
distribute-rgt-neg-in99.6%
associate-/l*99.6%
metadata-eval99.6%
/-rgt-identity99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 99.6%
Final simplification80.9%
(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 81.3%
+-commutative81.3%
Simplified81.3%
log1p-expm1-u49.8%
log1p-udef16.1%
*-commutative16.1%
Applied egg-rr16.1%
add-exp-log14.8%
log1p-def27.6%
log1p-expm1-u43.2%
Applied egg-rr43.2%
Taylor expanded in a around 0 36.3%
rem-exp-log65.7%
associate-*l/65.7%
quot-tan65.7%
Applied egg-rr65.7%
Final simplification65.7%
(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 81.3%
associate-/l*81.4%
remove-double-neg81.4%
sin-neg81.4%
neg-mul-181.4%
associate-/r*81.4%
associate-/l*81.3%
*-commutative81.3%
associate-*l/81.4%
associate-/l*81.4%
sin-neg81.4%
distribute-lft-neg-in81.4%
distribute-rgt-neg-in81.4%
associate-/l*81.4%
metadata-eval81.4%
/-rgt-identity81.4%
+-commutative81.4%
Simplified81.4%
Taylor expanded in b around 0 52.1%
Taylor expanded in a around 0 37.0%
Final simplification37.0%
herbie shell --seed 2024026
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))