
(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 12 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 (sin b)) (fma (cos b) (cos a) (* (sin b) (- (sin a))))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(b), cos(a), (sin(b) * -sin(a)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(sin(b) * Float64(-sin(a))))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)}
\end{array}
Initial program 75.5%
+-commutative75.5%
Simplified75.5%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 75.5%
+-commutative75.5%
Simplified75.5%
cos-sum99.4%
Applied egg-rr99.4%
(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 75.5%
associate-/l*75.5%
remove-double-neg75.5%
remove-double-neg75.5%
+-commutative75.5%
Simplified75.5%
cos-sum99.4%
Applied egg-rr99.3%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00029) (not (<= a 1.46e-6))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00029) || !(a <= 1.46e-6)) {
tmp = r * (sin(b) / 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 ((a <= (-0.00029d0)) .or. (.not. (a <= 1.46d-6))) then
tmp = r * (sin(b) / 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 ((a <= -0.00029) || !(a <= 1.46e-6)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = r * (Math.sin(b) / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.00029) or not (a <= 1.46e-6): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = r * (math.sin(b) / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.00029) || !(a <= 1.46e-6)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(r * Float64(sin(b) / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -0.00029) || ~((a <= 1.46e-6))) tmp = r * (sin(b) / cos(a)); else tmp = r * (sin(b) / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00029], N[Not[LessEqual[a, 1.46e-6]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00029 \lor \neg \left(a \leq 1.46 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -2.9e-4 or 1.46e-6 < a Initial program 54.2%
associate-/l*54.2%
remove-double-neg54.2%
remove-double-neg54.2%
+-commutative54.2%
Simplified54.2%
Taylor expanded in b around 0 54.3%
if -2.9e-4 < a < 1.46e-6Initial program 99.2%
associate-/l*99.2%
remove-double-neg99.2%
remove-double-neg99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in a around 0 99.2%
Final simplification75.5%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* r (sin b))))
(if (<= a -0.0014)
(* r (/ (sin b) (cos a)))
(if (<= a 9.5e-5) (/ t_0 (cos b)) (/ t_0 (cos a))))))
double code(double r, double a, double b) {
double t_0 = r * sin(b);
double tmp;
if (a <= -0.0014) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 9.5e-5) {
tmp = t_0 / cos(b);
} else {
tmp = t_0 / 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 = r * sin(b)
if (a <= (-0.0014d0)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 9.5d-5) then
tmp = t_0 / cos(b)
else
tmp = t_0 / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = r * Math.sin(b);
double tmp;
if (a <= -0.0014) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 9.5e-5) {
tmp = t_0 / Math.cos(b);
} else {
tmp = t_0 / Math.cos(a);
}
return tmp;
}
def code(r, a, b): t_0 = r * math.sin(b) tmp = 0 if a <= -0.0014: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 9.5e-5: tmp = t_0 / math.cos(b) else: tmp = t_0 / math.cos(a) return tmp
function code(r, a, b) t_0 = Float64(r * sin(b)) tmp = 0.0 if (a <= -0.0014) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 9.5e-5) tmp = Float64(t_0 / cos(b)); else tmp = Float64(t_0 / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * sin(b); tmp = 0.0; if (a <= -0.0014) tmp = r * (sin(b) / cos(a)); elseif (a <= 9.5e-5) tmp = t_0 / cos(b); else tmp = t_0 / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.0014], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 9.5e-5], N[(t$95$0 / N[Cos[b], $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Cos[a], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \sin b\\
\mathbf{if}\;a \leq -0.0014:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 9.5 \cdot 10^{-5}:\\
\;\;\;\;\frac{t\_0}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\cos a}\\
\end{array}
\end{array}
if a < -0.00139999999999999999Initial program 58.3%
associate-/l*58.3%
remove-double-neg58.3%
remove-double-neg58.3%
+-commutative58.3%
Simplified58.3%
Taylor expanded in b around 0 58.2%
if -0.00139999999999999999 < a < 9.5000000000000005e-5Initial program 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in a around 0 99.2%
if 9.5000000000000005e-5 < a Initial program 50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in b around 0 50.8%
(FPCore (r a b) :precision binary64 (if (<= a -0.0135) (* r (/ (sin b) (cos a))) (if (<= a 0.00029) (* r (/ (sin b) (cos b))) (/ (* r (sin b)) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if (a <= -0.0135) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 0.00029) {
tmp = r * (sin(b) / cos(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 <= (-0.0135d0)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 0.00029d0) then
tmp = r * (sin(b) / cos(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 <= -0.0135) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 0.00029) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else {
tmp = (r * Math.sin(b)) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -0.0135: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 0.00029: tmp = r * (math.sin(b) / math.cos(b)) else: tmp = (r * math.sin(b)) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -0.0135) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 0.00029) tmp = Float64(r * Float64(sin(b) / cos(b))); else tmp = Float64(Float64(r * sin(b)) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -0.0135) tmp = r * (sin(b) / cos(a)); elseif (a <= 0.00029) tmp = r * (sin(b) / cos(b)); else tmp = (r * sin(b)) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -0.0135], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.00029], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0135:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 0.00029:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\end{array}
\end{array}
if a < -0.0134999999999999998Initial program 58.3%
associate-/l*58.3%
remove-double-neg58.3%
remove-double-neg58.3%
+-commutative58.3%
Simplified58.3%
Taylor expanded in b around 0 58.2%
if -0.0134999999999999998 < a < 2.9e-4Initial program 99.2%
associate-/l*99.2%
remove-double-neg99.2%
remove-double-neg99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in a around 0 99.2%
if 2.9e-4 < a Initial program 50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in b around 0 50.8%
(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 75.5%
Final simplification75.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 75.5%
associate-/l*75.5%
remove-double-neg75.5%
remove-double-neg75.5%
+-commutative75.5%
Simplified75.5%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos a))))
double code(double r, double a, double b) {
return r * (sin(b) / cos(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))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos(a));
}
def code(r, a, b): return r * (math.sin(b) / math.cos(a))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(a))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos(a)); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos a}
\end{array}
Initial program 75.5%
associate-/l*75.5%
remove-double-neg75.5%
remove-double-neg75.5%
+-commutative75.5%
Simplified75.5%
Taylor expanded in b around 0 52.7%
(FPCore (r a b) :precision binary64 (/ (* r b) (cos a)))
double code(double r, double a, double b) {
return (r * b) / cos(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 * b) / cos(a)
end function
public static double code(double r, double a, double b) {
return (r * b) / Math.cos(a);
}
def code(r, a, b): return (r * b) / math.cos(a)
function code(r, a, b) return Float64(Float64(r * b) / cos(a)) end
function tmp = code(r, a, b) tmp = (r * b) / cos(a); end
code[r_, a_, b_] := N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot b}{\cos a}
\end{array}
Initial program 75.5%
associate-/l*75.5%
remove-double-neg75.5%
remove-double-neg75.5%
+-commutative75.5%
Simplified75.5%
Taylor expanded in b around 0 49.3%
Final simplification49.3%
(FPCore (r a b) :precision binary64 (* b (/ r (cos a))))
double code(double r, double a, double b) {
return b * (r / cos(a));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = b * (r / cos(a))
end function
public static double code(double r, double a, double b) {
return b * (r / Math.cos(a));
}
def code(r, a, b): return b * (r / math.cos(a))
function code(r, a, b) return Float64(b * Float64(r / cos(a))) end
function tmp = code(r, a, b) tmp = b * (r / cos(a)); end
code[r_, a_, b_] := N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot \frac{r}{\cos a}
\end{array}
Initial program 75.5%
+-commutative75.5%
Simplified75.5%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
Taylor expanded in b around 0 49.3%
associate-*r/49.2%
Simplified49.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.5%
associate-/l*75.5%
remove-double-neg75.5%
remove-double-neg75.5%
+-commutative75.5%
Simplified75.5%
Taylor expanded in b around 0 49.2%
Taylor expanded in a around 0 31.2%
*-commutative31.2%
Simplified31.2%
herbie shell --seed 2024110
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))