
(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 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(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 b) (- (sin a)) (* (cos a) (cos b))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(sin(b), -sin(a), (cos(a) * cos(b))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(sin(b), Float64(-sin(a)), Float64(cos(a) * cos(b))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)}
\end{array}
Initial program 78.7%
associate-*r/78.7%
+-commutative78.7%
Simplified78.7%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-define99.5%
Applied egg-rr99.5%
Taylor expanded in r around 0 99.5%
associate-/l*99.5%
mul-1-neg99.5%
*-commutative99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
fma-define99.6%
*-commutative99.6%
Simplified99.6%
(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 78.7%
associate-*r/78.7%
+-commutative78.7%
Simplified78.7%
cos-sum99.5%
Applied egg-rr99.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 78.7%
+-commutative78.7%
Simplified78.7%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.000165) (not (<= b 12000.0))) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.000165) || !(b <= 12000.0)) {
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 ((b <= (-0.000165d0)) .or. (.not. (b <= 12000.0d0))) 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 ((b <= -0.000165) || !(b <= 12000.0)) {
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 (b <= -0.000165) or not (b <= 12000.0): 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 ((b <= -0.000165) || !(b <= 12000.0)) tmp = Float64(r * Float64(sin(b) / cos(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 ((b <= -0.000165) || ~((b <= 12000.0))) tmp = r * (sin(b) / cos(b)); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.000165], N[Not[LessEqual[b, 12000.0]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.000165 \lor \neg \left(b \leq 12000\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
if b < -1.65e-4 or 12000 < b Initial program 58.0%
+-commutative58.0%
Simplified58.0%
Taylor expanded in a around 0 56.9%
if -1.65e-4 < b < 12000Initial program 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in b around 0 98.5%
Final simplification78.2%
(FPCore (r a b) :precision binary64 (if (<= b -3.8e-6) (* r (* (sin b) (/ 1.0 (cos b)))) (if (<= b 12000.0) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -3.8e-6) {
tmp = r * (sin(b) * (1.0 / cos(b)));
} else if (b <= 12000.0) {
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 (b <= (-3.8d-6)) then
tmp = r * (sin(b) * (1.0d0 / cos(b)))
else if (b <= 12000.0d0) 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 (b <= -3.8e-6) {
tmp = r * (Math.sin(b) * (1.0 / Math.cos(b)));
} else if (b <= 12000.0) {
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 b <= -3.8e-6: tmp = r * (math.sin(b) * (1.0 / math.cos(b))) elif b <= 12000.0: 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 (b <= -3.8e-6) tmp = Float64(r * Float64(sin(b) * Float64(1.0 / cos(b)))); elseif (b <= 12000.0) 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 (b <= -3.8e-6) tmp = r * (sin(b) * (1.0 / cos(b))); elseif (b <= 12000.0) tmp = r * (sin(b) / cos(a)); else tmp = r * (sin(b) / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -3.8e-6], N[(r * N[(N[Sin[b], $MachinePrecision] * N[(1.0 / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 12000.0], 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}\;b \leq -3.8 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \left(\sin b \cdot \frac{1}{\cos b}\right)\\
\mathbf{elif}\;b \leq 12000:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if b < -3.8e-6Initial program 57.0%
+-commutative57.0%
Simplified57.0%
Taylor expanded in a around 0 56.3%
*-commutative56.3%
Simplified56.3%
div-inv56.3%
*-commutative56.3%
associate-*l*56.4%
Applied egg-rr56.4%
if -3.8e-6 < b < 12000Initial program 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in b around 0 98.5%
if 12000 < b Initial program 58.9%
+-commutative58.9%
Simplified58.9%
Taylor expanded in a around 0 57.5%
(FPCore (r a b) :precision binary64 (if (<= b -3.6e-6) (/ (* r (sin b)) (cos b)) (if (<= b 12000.0) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -3.6e-6) {
tmp = (r * sin(b)) / cos(b);
} else if (b <= 12000.0) {
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 (b <= (-3.6d-6)) then
tmp = (r * sin(b)) / cos(b)
else if (b <= 12000.0d0) 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 (b <= -3.6e-6) {
tmp = (r * Math.sin(b)) / Math.cos(b);
} else if (b <= 12000.0) {
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 b <= -3.6e-6: tmp = (r * math.sin(b)) / math.cos(b) elif b <= 12000.0: 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 (b <= -3.6e-6) tmp = Float64(Float64(r * sin(b)) / cos(b)); elseif (b <= 12000.0) 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 (b <= -3.6e-6) tmp = (r * sin(b)) / cos(b); elseif (b <= 12000.0) tmp = r * (sin(b) / cos(a)); else tmp = r * (sin(b) / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -3.6e-6], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 12000.0], 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}\;b \leq -3.6 \cdot 10^{-6}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\
\mathbf{elif}\;b \leq 12000:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if b < -3.59999999999999984e-6Initial program 57.0%
+-commutative57.0%
Simplified57.0%
Taylor expanded in a around 0 56.3%
*-commutative56.3%
Simplified56.3%
if -3.59999999999999984e-6 < b < 12000Initial program 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in b around 0 98.5%
if 12000 < b Initial program 58.9%
+-commutative58.9%
Simplified58.9%
Taylor expanded in a around 0 57.5%
Final simplification78.2%
(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 78.7%
Final simplification78.7%
(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 78.7%
+-commutative78.7%
Simplified78.7%
Taylor expanded in b around 0 55.8%
(FPCore (r a b) :precision binary64 (if (<= b -1.3) (* r (sin b)) (if (<= b 4.4) (* r (/ b (cos a))) (/ r (- (sin a))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -1.3) {
tmp = r * sin(b);
} else if (b <= 4.4) {
tmp = r * (b / cos(a));
} else {
tmp = r / -sin(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.3d0)) then
tmp = r * sin(b)
else if (b <= 4.4d0) then
tmp = r * (b / cos(a))
else
tmp = r / -sin(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -1.3) {
tmp = r * Math.sin(b);
} else if (b <= 4.4) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r / -Math.sin(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -1.3: tmp = r * math.sin(b) elif b <= 4.4: tmp = r * (b / math.cos(a)) else: tmp = r / -math.sin(a) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -1.3) tmp = Float64(r * sin(b)); elseif (b <= 4.4) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r / Float64(-sin(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -1.3) tmp = r * sin(b); elseif (b <= 4.4) tmp = r * (b / cos(a)); else tmp = r / -sin(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -1.3], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.4], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / (-N[Sin[a], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.3:\\
\;\;\;\;r \cdot \sin b\\
\mathbf{elif}\;b \leq 4.4:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{-\sin a}\\
\end{array}
\end{array}
if b < -1.30000000000000004Initial program 57.0%
associate-*r/57.1%
+-commutative57.1%
Simplified57.1%
Taylor expanded in b around 0 11.6%
Taylor expanded in a around 0 13.2%
*-commutative13.2%
Simplified13.2%
if -1.30000000000000004 < b < 4.4000000000000004Initial program 99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in b around 0 99.1%
if 4.4000000000000004 < b Initial program 58.3%
+-commutative58.3%
Simplified58.3%
associate-*r/58.2%
clear-num58.2%
*-commutative58.2%
Applied egg-rr58.2%
Taylor expanded in b around 0 8.7%
fma-define8.7%
associate-/l*8.7%
Simplified8.7%
Taylor expanded in b around inf 10.5%
mul-1-neg10.5%
distribute-neg-frac210.5%
Simplified10.5%
Final simplification56.2%
(FPCore (r a b) :precision binary64 (if (<= b -1.6) (* r (sin b)) (if (<= b 4.5) (* b (/ r (cos a))) (/ r (- (sin a))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -1.6) {
tmp = r * sin(b);
} else if (b <= 4.5) {
tmp = b * (r / cos(a));
} else {
tmp = r / -sin(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.6d0)) then
tmp = r * sin(b)
else if (b <= 4.5d0) then
tmp = b * (r / cos(a))
else
tmp = r / -sin(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -1.6) {
tmp = r * Math.sin(b);
} else if (b <= 4.5) {
tmp = b * (r / Math.cos(a));
} else {
tmp = r / -Math.sin(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -1.6: tmp = r * math.sin(b) elif b <= 4.5: tmp = b * (r / math.cos(a)) else: tmp = r / -math.sin(a) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -1.6) tmp = Float64(r * sin(b)); elseif (b <= 4.5) tmp = Float64(b * Float64(r / cos(a))); else tmp = Float64(r / Float64(-sin(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -1.6) tmp = r * sin(b); elseif (b <= 4.5) tmp = b * (r / cos(a)); else tmp = r / -sin(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -1.6], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.5], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / (-N[Sin[a], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6:\\
\;\;\;\;r \cdot \sin b\\
\mathbf{elif}\;b \leq 4.5:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{-\sin a}\\
\end{array}
\end{array}
if b < -1.6000000000000001Initial program 57.0%
associate-*r/57.1%
+-commutative57.1%
Simplified57.1%
Taylor expanded in b around 0 11.6%
Taylor expanded in a around 0 13.2%
*-commutative13.2%
Simplified13.2%
if -1.6000000000000001 < b < 4.5Initial program 99.1%
associate-*r/99.1%
+-commutative99.1%
Simplified99.1%
cos-sum99.8%
*-un-lft-identity99.8%
prod-diff99.8%
Applied egg-rr99.8%
fma-undefine99.8%
distribute-lft-neg-in99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
*-rgt-identity99.8%
*-commutative99.8%
fma-undefine99.8%
*-rgt-identity99.8%
distribute-lft-neg-in99.8%
*-rgt-identity99.8%
fma-undefine99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 99.1%
associate-/l*99.1%
Simplified99.1%
if 4.5 < b Initial program 58.3%
+-commutative58.3%
Simplified58.3%
associate-*r/58.2%
clear-num58.2%
*-commutative58.2%
Applied egg-rr58.2%
Taylor expanded in b around 0 8.7%
fma-define8.7%
associate-/l*8.7%
Simplified8.7%
Taylor expanded in b around inf 10.5%
mul-1-neg10.5%
distribute-neg-frac210.5%
Simplified10.5%
Final simplification56.2%
(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 78.7%
associate-*r/78.7%
+-commutative78.7%
Simplified78.7%
Taylor expanded in b around 0 55.8%
Taylor expanded in a around 0 35.5%
*-commutative35.5%
Simplified35.5%
Final simplification35.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 78.7%
+-commutative78.7%
Simplified78.7%
Taylor expanded in b around 0 52.2%
Taylor expanded in a around 0 31.6%
herbie shell --seed 2024100
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))