
(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 (- (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(Float64(r * sin(b)) / fma(Float64(-sin(a)), sin(b), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[((-N[Sin[a], $MachinePrecision]) * N[Sin[b], $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(-\sin a, \sin b, \cos a \cdot \cos b\right)}
\end{array}
Initial program 74.9%
associate-*r/74.9%
/-rgt-identity74.9%
metadata-eval74.9%
associate-/l/74.9%
associate-*l/74.9%
associate-/l/74.9%
metadata-eval74.9%
metadata-eval74.9%
metadata-eval74.9%
/-rgt-identity74.9%
+-commutative74.9%
Simplified74.9%
cos-sum99.4%
*-un-lft-identity99.4%
prod-diff99.4%
Applied egg-rr99.4%
fma-udef99.4%
distribute-lft-neg-in99.4%
cancel-sign-sub-inv99.4%
*-commutative99.4%
*-rgt-identity99.4%
*-commutative99.4%
fma-udef99.4%
*-rgt-identity99.4%
distribute-lft-neg-in99.4%
*-rgt-identity99.4%
fma-udef99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in r around 0 99.5%
fma-def99.5%
*-commutative99.5%
Applied egg-rr99.5%
fma-udef99.5%
neg-mul-199.5%
*-commutative99.5%
distribute-lft-neg-in99.5%
fma-udef99.5%
Simplified99.5%
Final simplification99.5%
(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 74.9%
+-commutative74.9%
Simplified74.9%
cos-sum99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a}
\end{array}
Initial program 74.9%
associate-*r/74.9%
/-rgt-identity74.9%
metadata-eval74.9%
associate-/l/74.9%
associate-*l/74.9%
associate-/l/74.9%
metadata-eval74.9%
metadata-eval74.9%
metadata-eval74.9%
/-rgt-identity74.9%
+-commutative74.9%
Simplified74.9%
cos-sum99.4%
*-un-lft-identity99.4%
prod-diff99.4%
Applied egg-rr99.4%
fma-udef99.4%
distribute-lft-neg-in99.4%
cancel-sign-sub-inv99.4%
*-commutative99.4%
*-rgt-identity99.4%
*-commutative99.4%
fma-udef99.4%
*-rgt-identity99.4%
distribute-lft-neg-in99.4%
*-rgt-identity99.4%
fma-udef99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in r around 0 99.5%
+-commutative99.5%
mul-1-neg99.5%
sub-neg99.5%
*-commutative99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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 74.9%
Final simplification74.9%
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos (+ b a)))))
double code(double r, double a, double b) {
return sin(b) * (r / 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 = sin(b) * (r / cos((b + a)))
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * (r / Math.cos((b + a)));
}
def code(r, a, b): return math.sin(b) * (r / math.cos((b + a)))
function code(r, a, b) return Float64(sin(b) * Float64(r / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = sin(b) * (r / cos((b + a))); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot \frac{r}{\cos \left(b + a\right)}
\end{array}
Initial program 74.9%
associate-*r/74.9%
/-rgt-identity74.9%
metadata-eval74.9%
associate-/l/74.9%
associate-*l/74.9%
associate-/l/74.9%
metadata-eval74.9%
metadata-eval74.9%
metadata-eval74.9%
/-rgt-identity74.9%
+-commutative74.9%
Simplified74.9%
Final simplification74.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -4.5e-6) (not (<= b 1.2e-12))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -4.5e-6) || !(b <= 1.2e-12)) {
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 <= (-4.5d-6)) .or. (.not. (b <= 1.2d-12))) 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 <= -4.5e-6) || !(b <= 1.2e-12)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -4.5e-6) or not (b <= 1.2e-12): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -4.5e-6) || !(b <= 1.2e-12)) 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 <= -4.5e-6) || ~((b <= 1.2e-12))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -4.5e-6], N[Not[LessEqual[b, 1.2e-12]], $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 -4.5 \cdot 10^{-6} \lor \neg \left(b \leq 1.2 \cdot 10^{-12}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -4.50000000000000011e-6 or 1.19999999999999994e-12 < b Initial program 50.0%
+-commutative50.0%
Simplified50.0%
log1p-expm1-u49.0%
Applied egg-rr49.0%
Taylor expanded in a around 0 48.4%
expm1-def49.1%
log1p-expm1-u50.2%
add-log-exp49.4%
*-un-lft-identity49.4%
log-prod49.4%
metadata-eval49.4%
add-log-exp50.2%
quot-tan50.3%
Applied egg-rr50.3%
+-lft-identity50.3%
Simplified50.3%
if -4.50000000000000011e-6 < b < 1.19999999999999994e-12Initial program 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 99.8%
Final simplification75.1%
(FPCore (r a b) :precision binary64 (* r (log1p b)))
double code(double r, double a, double b) {
return r * log1p(b);
}
public static double code(double r, double a, double b) {
return r * Math.log1p(b);
}
def code(r, a, b): return r * math.log1p(b)
function code(r, a, b) return Float64(r * log1p(b)) end
code[r_, a_, b_] := N[(r * N[Log[1 + b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \mathsf{log1p}\left(b\right)
\end{array}
Initial program 74.9%
+-commutative74.9%
Simplified74.9%
log1p-expm1-u74.4%
Applied egg-rr74.4%
Taylor expanded in a around 0 36.8%
Taylor expanded in b around 0 35.0%
Final simplification35.0%
(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 74.9%
+-commutative74.9%
Simplified74.9%
log1p-expm1-u74.4%
Applied egg-rr74.4%
Taylor expanded in a around 0 36.8%
expm1-def56.9%
log1p-expm1-u57.4%
add-log-exp37.3%
*-un-lft-identity37.3%
log-prod37.3%
metadata-eval37.3%
add-log-exp57.4%
quot-tan57.5%
Applied egg-rr57.5%
+-lft-identity57.5%
Simplified57.5%
Final simplification57.5%
(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 74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in b around 0 52.4%
Taylor expanded in a around 0 34.8%
Final simplification34.8%
herbie shell --seed 2023333
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))