
(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 7 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) (- (* (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 77.4%
associate-/l*77.4%
remove-double-neg77.4%
remove-double-neg77.4%
+-commutative77.4%
Simplified77.4%
cos-sum99.6%
Applied egg-rr99.6%
(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 77.4%
associate-/l*77.4%
remove-double-neg77.4%
remove-double-neg77.4%
+-commutative77.4%
Simplified77.4%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.00068) (not (<= b 0.00056))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00068) || !(b <= 0.00056)) {
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 <= (-0.00068d0)) .or. (.not. (b <= 0.00056d0))) 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 <= -0.00068) || !(b <= 0.00056)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.00068) or not (b <= 0.00056): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.00068) || !(b <= 0.00056)) 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 <= -0.00068) || ~((b <= 0.00056))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00068], N[Not[LessEqual[b, 0.00056]], $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 -0.00068 \lor \neg \left(b \leq 0.00056\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -6.8e-4 or 5.5999999999999995e-4 < b Initial program 55.8%
associate-/l*55.8%
remove-double-neg55.8%
remove-double-neg55.8%
+-commutative55.8%
Simplified55.8%
add-sqr-sqrt33.2%
sqrt-unprod37.1%
pow237.1%
Applied egg-rr37.1%
sqrt-pow155.8%
metadata-eval55.8%
pow155.8%
clear-num55.7%
Applied egg-rr55.7%
Taylor expanded in a around 0 56.3%
*-un-lft-identity56.3%
clear-num56.3%
quot-tan56.4%
Applied egg-rr56.4%
Simplified56.4%
if -6.8e-4 < b < 5.5999999999999995e-4Initial program 98.5%
associate-/l*98.6%
remove-double-neg98.6%
remove-double-neg98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in b around 0 98.6%
Final simplification77.7%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.00064) (not (<= b 4.8e-6))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00064) || !(b <= 4.8e-6)) {
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 <= (-0.00064d0)) .or. (.not. (b <= 4.8d-6))) 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 <= -0.00064) || !(b <= 4.8e-6)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.00064) or not (b <= 4.8e-6): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.00064) || !(b <= 4.8e-6)) 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 <= -0.00064) || ~((b <= 4.8e-6))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00064], N[Not[LessEqual[b, 4.8e-6]], $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 -0.00064 \lor \neg \left(b \leq 4.8 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -6.40000000000000052e-4 or 4.7999999999999998e-6 < b Initial program 55.8%
associate-/l*55.8%
remove-double-neg55.8%
remove-double-neg55.8%
+-commutative55.8%
Simplified55.8%
add-sqr-sqrt33.2%
sqrt-unprod37.1%
pow237.1%
Applied egg-rr37.1%
sqrt-pow155.8%
metadata-eval55.8%
pow155.8%
clear-num55.7%
Applied egg-rr55.7%
Taylor expanded in a around 0 56.3%
*-un-lft-identity56.3%
clear-num56.3%
quot-tan56.4%
Applied egg-rr56.4%
Simplified56.4%
if -6.40000000000000052e-4 < b < 4.7999999999999998e-6Initial program 98.5%
associate-/l*98.6%
remove-double-neg98.6%
remove-double-neg98.6%
+-commutative98.6%
Simplified98.6%
cos-sum99.9%
Applied egg-rr99.9%
Taylor expanded in r around 0 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 98.5%
associate-/l*98.6%
Simplified98.6%
Final simplification77.7%
(FPCore (r a b) :precision binary64 (if (<= b -0.00064) (* r (tan b)) (if (<= b 1.85e-5) (* r (/ b (cos a))) (/ r (/ 1.0 (tan b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -0.00064) {
tmp = r * tan(b);
} else if (b <= 1.85e-5) {
tmp = r * (b / cos(a));
} else {
tmp = r / (1.0 / 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 (b <= (-0.00064d0)) then
tmp = r * tan(b)
else if (b <= 1.85d-5) then
tmp = r * (b / cos(a))
else
tmp = r / (1.0d0 / tan(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -0.00064) {
tmp = r * Math.tan(b);
} else if (b <= 1.85e-5) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r / (1.0 / Math.tan(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -0.00064: tmp = r * math.tan(b) elif b <= 1.85e-5: tmp = r * (b / math.cos(a)) else: tmp = r / (1.0 / math.tan(b)) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -0.00064) tmp = Float64(r * tan(b)); elseif (b <= 1.85e-5) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r / Float64(1.0 / tan(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -0.00064) tmp = r * tan(b); elseif (b <= 1.85e-5) tmp = r * (b / cos(a)); else tmp = r / (1.0 / tan(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -0.00064], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.85e-5], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00064:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{-5}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{1}{\tan b}}\\
\end{array}
\end{array}
if b < -6.40000000000000052e-4Initial program 52.1%
associate-/l*52.0%
remove-double-neg52.0%
remove-double-neg52.0%
+-commutative52.0%
Simplified52.0%
add-sqr-sqrt31.4%
sqrt-unprod36.0%
pow236.0%
Applied egg-rr36.0%
sqrt-pow152.0%
metadata-eval52.0%
pow152.0%
clear-num51.9%
Applied egg-rr51.9%
Taylor expanded in a around 0 52.6%
*-un-lft-identity52.6%
clear-num52.7%
quot-tan52.8%
Applied egg-rr52.8%
Simplified52.8%
if -6.40000000000000052e-4 < b < 1.84999999999999991e-5Initial program 98.5%
associate-/l*98.6%
remove-double-neg98.6%
remove-double-neg98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in b around 0 98.6%
if 1.84999999999999991e-5 < b Initial program 59.3%
associate-/l*59.2%
remove-double-neg59.2%
remove-double-neg59.2%
+-commutative59.2%
Simplified59.2%
add-sqr-sqrt34.8%
sqrt-unprod38.2%
pow238.2%
Applied egg-rr38.2%
sqrt-pow159.2%
metadata-eval59.2%
pow159.2%
clear-num59.2%
Applied egg-rr59.2%
Taylor expanded in a around 0 59.7%
un-div-inv59.8%
clear-num59.7%
quot-tan59.8%
Applied egg-rr59.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 77.4%
associate-/l*77.4%
remove-double-neg77.4%
remove-double-neg77.4%
+-commutative77.4%
Simplified77.4%
add-sqr-sqrt44.0%
sqrt-unprod43.8%
pow243.8%
Applied egg-rr43.8%
sqrt-pow177.4%
metadata-eval77.4%
pow177.4%
clear-num77.2%
Applied egg-rr77.2%
Taylor expanded in a around 0 60.0%
*-un-lft-identity60.0%
clear-num60.1%
quot-tan60.2%
Applied egg-rr60.2%
Simplified60.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 77.4%
associate-/l*77.4%
remove-double-neg77.4%
remove-double-neg77.4%
+-commutative77.4%
Simplified77.4%
Taylor expanded in b around 0 51.6%
Taylor expanded in a around 0 34.0%
herbie shell --seed 2024103
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))