
(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 10 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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 80.1%
associate-*r/80.2%
+-commutative80.2%
Simplified80.2%
cos-sum99.6%
Applied egg-rr99.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 80.1%
+-commutative80.1%
Simplified80.1%
cos-sum99.6%
Applied egg-rr99.5%
(FPCore (r a b) :precision binary64 (if (<= b -2e-6) (* r (tan b)) (if (<= b 6.8e-9) (* b (/ r (cos a))) (/ (* r (sin b)) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if (b <= -2e-6) {
tmp = r * tan(b);
} else if (b <= 6.8e-9) {
tmp = b * (r / cos(a));
} else {
tmp = (r * sin(b)) / cos(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 <= (-2d-6)) then
tmp = r * tan(b)
else if (b <= 6.8d-9) then
tmp = b * (r / cos(a))
else
tmp = (r * sin(b)) / cos(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -2e-6) {
tmp = r * Math.tan(b);
} else if (b <= 6.8e-9) {
tmp = b * (r / Math.cos(a));
} else {
tmp = (r * Math.sin(b)) / Math.cos(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -2e-6: tmp = r * math.tan(b) elif b <= 6.8e-9: tmp = b * (r / math.cos(a)) else: tmp = (r * math.sin(b)) / math.cos(b) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -2e-6) tmp = Float64(r * tan(b)); elseif (b <= 6.8e-9) tmp = Float64(b * Float64(r / cos(a))); else tmp = Float64(Float64(r * sin(b)) / cos(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -2e-6) tmp = r * tan(b); elseif (b <= 6.8e-9) tmp = b * (r / cos(a)); else tmp = (r * sin(b)) / cos(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -2e-6], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.8e-9], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-9}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\
\end{array}
\end{array}
if b < -1.99999999999999991e-6Initial program 53.6%
+-commutative53.6%
Simplified53.6%
Taylor expanded in a around 0 54.5%
associate-/l*54.4%
*-commutative54.4%
quot-tan54.7%
Applied egg-rr54.7%
if -1.99999999999999991e-6 < b < 6.7999999999999997e-9Initial program 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 99.3%
associate-/l*99.3%
Simplified99.3%
if 6.7999999999999997e-9 < b Initial program 65.2%
+-commutative65.2%
Simplified65.2%
Taylor expanded in a around 0 65.8%
Final simplification80.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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(b - a\right)}
\end{array}
Initial program 80.1%
+-commutative80.1%
Simplified80.1%
cos-sum99.5%
sub-neg99.5%
Applied egg-rr99.5%
+-commutative99.5%
distribute-rgt-neg-in99.5%
fma-define99.6%
*-commutative99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-undefine99.5%
Applied egg-rr99.5%
expm1-define99.6%
Simplified99.6%
associate-*r/99.6%
expm1-log1p-u99.6%
fma-undefine99.6%
*-commutative99.6%
+-commutative99.6%
add-sqr-sqrt52.9%
sqrt-unprod88.6%
sqr-neg88.6%
sqrt-unprod35.7%
add-sqr-sqrt80.2%
cos-diff80.4%
Applied egg-rr80.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(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 80.1%
+-commutative80.1%
Simplified80.1%
cos-sum99.5%
sub-neg99.5%
Applied egg-rr99.5%
+-commutative99.5%
distribute-rgt-neg-in99.5%
fma-define99.6%
*-commutative99.6%
Simplified99.6%
fma-undefine99.5%
+-commutative99.5%
*-commutative99.5%
add-sqr-sqrt52.9%
sqrt-unprod88.6%
sqr-neg88.6%
sqrt-unprod35.7%
add-sqr-sqrt80.2%
cos-diff80.3%
Applied egg-rr80.3%
(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 80.1%
Final simplification80.1%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.1e-6) (not (<= b 6.8e-9))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.1e-6) || !(b <= 6.8e-9)) {
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) :: tmp
if ((b <= (-1.1d-6)) .or. (.not. (b <= 6.8d-9))) 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 tmp;
if ((b <= -1.1e-6) || !(b <= 6.8e-9)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.1e-6) or not (b <= 6.8e-9): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.1e-6) || !(b <= 6.8e-9)) tmp = Float64(r * tan(b)); else tmp = Float64(b * Float64(r / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -1.1e-6) || ~((b <= 6.8e-9))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.1e-6], N[Not[LessEqual[b, 6.8e-9]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-6} \lor \neg \left(b \leq 6.8 \cdot 10^{-9}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -1.1000000000000001e-6 or 6.7999999999999997e-9 < b Initial program 59.4%
+-commutative59.4%
Simplified59.4%
Taylor expanded in a around 0 60.2%
associate-/l*60.1%
*-commutative60.1%
quot-tan60.3%
Applied egg-rr60.3%
if -1.1000000000000001e-6 < b < 6.7999999999999997e-9Initial program 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 99.3%
associate-/l*99.3%
Simplified99.3%
Final simplification80.5%
(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 80.1%
+-commutative80.1%
Simplified80.1%
Taylor expanded in a around 0 63.7%
associate-/l*63.6%
*-commutative63.6%
quot-tan63.7%
Applied egg-rr63.7%
Final simplification63.7%
(FPCore (r a b) :precision binary64 (* r (sin b)))
double code(double r, double a, double b) {
return r * sin(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)
end function
public static double code(double r, double a, double b) {
return r * Math.sin(b);
}
def code(r, a, b): return r * math.sin(b)
function code(r, a, b) return Float64(r * sin(b)) end
function tmp = code(r, a, b) tmp = r * sin(b); end
code[r_, a_, b_] := N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \sin b
\end{array}
Initial program 80.1%
+-commutative80.1%
Simplified80.1%
add-log-exp40.9%
Applied egg-rr40.9%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 41.6%
(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 80.1%
+-commutative80.1%
Simplified80.1%
Taylor expanded in b around 0 53.7%
associate-/l*53.7%
Simplified53.7%
Taylor expanded in a around 0 37.0%
*-commutative37.0%
Simplified37.0%
herbie shell --seed 2024163
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))