
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (atan (/ (* (- eh) (tan t)) ew)))) (fabs (- (* (* ew (cos t)) (cos t_1)) (* (* eh (sin t)) (sin t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan(((-eh * tan(t)) / ew));
return fabs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))));
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
t_1 = atan(((-eh * tan(t)) / ew))
code = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.atan(((-eh * Math.tan(t)) / ew));
return Math.abs((((ew * Math.cos(t)) * Math.cos(t_1)) - ((eh * Math.sin(t)) * Math.sin(t_1))));
}
def code(eh, ew, t): t_1 = math.atan(((-eh * math.tan(t)) / ew)) return math.fabs((((ew * math.cos(t)) * math.cos(t_1)) - ((eh * math.sin(t)) * math.sin(t_1))))
function code(eh, ew, t) t_1 = atan(Float64(Float64(Float64(-eh) * tan(t)) / ew)) return abs(Float64(Float64(Float64(ew * cos(t)) * cos(t_1)) - Float64(Float64(eh * sin(t)) * sin(t_1)))) end
function tmp = code(eh, ew, t) t_1 = atan(((-eh * tan(t)) / ew)); tmp = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1)))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\\
\left|\left(ew \cdot \cos t\right) \cdot \cos t\_1 - \left(eh \cdot \sin t\right) \cdot \sin t\_1\right|
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (atan (/ (* (- eh) (tan t)) ew)))) (fabs (- (* (* ew (cos t)) (cos t_1)) (* (* eh (sin t)) (sin t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan(((-eh * tan(t)) / ew));
return fabs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))));
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
t_1 = atan(((-eh * tan(t)) / ew))
code = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.atan(((-eh * Math.tan(t)) / ew));
return Math.abs((((ew * Math.cos(t)) * Math.cos(t_1)) - ((eh * Math.sin(t)) * Math.sin(t_1))));
}
def code(eh, ew, t): t_1 = math.atan(((-eh * math.tan(t)) / ew)) return math.fabs((((ew * math.cos(t)) * math.cos(t_1)) - ((eh * math.sin(t)) * math.sin(t_1))))
function code(eh, ew, t) t_1 = atan(Float64(Float64(Float64(-eh) * tan(t)) / ew)) return abs(Float64(Float64(Float64(ew * cos(t)) * cos(t_1)) - Float64(Float64(eh * sin(t)) * sin(t_1)))) end
function tmp = code(eh, ew, t) t_1 = atan(((-eh * tan(t)) / ew)); tmp = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1)))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\\
\left|\left(ew \cdot \cos t\right) \cdot \cos t\_1 - \left(eh \cdot \sin t\right) \cdot \sin t\_1\right|
\end{array}
\end{array}
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (* (tan t) (/ eh ew))))
(fabs
(+
(* ew (/ (cos t) (hypot 1.0 t_1)))
(* eh (* (sin t) (sin (atan t_1))))))))
double code(double eh, double ew, double t) {
double t_1 = tan(t) * (eh / ew);
return fabs(((ew * (cos(t) / hypot(1.0, t_1))) + (eh * (sin(t) * sin(atan(t_1))))));
}
public static double code(double eh, double ew, double t) {
double t_1 = Math.tan(t) * (eh / ew);
return Math.abs(((ew * (Math.cos(t) / Math.hypot(1.0, t_1))) + (eh * (Math.sin(t) * Math.sin(Math.atan(t_1))))));
}
def code(eh, ew, t): t_1 = math.tan(t) * (eh / ew) return math.fabs(((ew * (math.cos(t) / math.hypot(1.0, t_1))) + (eh * (math.sin(t) * math.sin(math.atan(t_1))))))
function code(eh, ew, t) t_1 = Float64(tan(t) * Float64(eh / ew)) return abs(Float64(Float64(ew * Float64(cos(t) / hypot(1.0, t_1))) + Float64(eh * Float64(sin(t) * sin(atan(t_1)))))) end
function tmp = code(eh, ew, t) t_1 = tan(t) * (eh / ew); tmp = abs(((ew * (cos(t) / hypot(1.0, t_1))) + (eh * (sin(t) * sin(atan(t_1)))))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[Tan[t], $MachinePrecision] * N[(eh / ew), $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(ew * N[(N[Cos[t], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan t \cdot \frac{eh}{ew}\\
\left|ew \cdot \frac{\cos t}{\mathsf{hypot}\left(1, t\_1\right)} + eh \cdot \left(\sin t \cdot \sin \tan^{-1} t\_1\right)\right|
\end{array}
\end{array}
Initial program 99.8%
sub-neg99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-commutative99.8%
associate-*r/99.8%
associate-*r/99.8%
*-commutative99.8%
associate-*r/99.8%
*-commutative99.8%
associate-*r/99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (eh ew t) :precision binary64 (fabs (+ (* eh (* (sin t) (sin (atan (* (tan t) (/ eh ew)))))) (* (cos t) ew))))
double code(double eh, double ew, double t) {
return fabs(((eh * (sin(t) * sin(atan((tan(t) * (eh / ew)))))) + (cos(t) * ew)));
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
code = abs(((eh * (sin(t) * sin(atan((tan(t) * (eh / ew)))))) + (cos(t) * ew)))
end function
public static double code(double eh, double ew, double t) {
return Math.abs(((eh * (Math.sin(t) * Math.sin(Math.atan((Math.tan(t) * (eh / ew)))))) + (Math.cos(t) * ew)));
}
def code(eh, ew, t): return math.fabs(((eh * (math.sin(t) * math.sin(math.atan((math.tan(t) * (eh / ew)))))) + (math.cos(t) * ew)))
function code(eh, ew, t) return abs(Float64(Float64(eh * Float64(sin(t) * sin(atan(Float64(tan(t) * Float64(eh / ew)))))) + Float64(cos(t) * ew))) end
function tmp = code(eh, ew, t) tmp = abs(((eh * (sin(t) * sin(atan((tan(t) * (eh / ew)))))) + (cos(t) * ew))); end
code[eh_, ew_, t_] := N[Abs[N[(N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[N[(N[Tan[t], $MachinePrecision] * N[(eh / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(\tan t \cdot \frac{eh}{ew}\right)\right) + \cos t \cdot ew\right|
\end{array}
Initial program 99.8%
sub-neg99.8%
Applied egg-rr99.8%
Taylor expanded in ew around inf 98.3%
Final simplification98.3%
(FPCore (eh ew t)
:precision binary64
(if (<= t -9.5e+68)
(fabs (* (cos t) ew))
(if (or (<= t -3.75e-6) (not (<= t 4.4e-18)))
(fabs (* eh (* (sin t) (sin (atan (/ (* t eh) ew))))))
(fabs (+ ew (* eh (* t (sin (atan (/ (* (tan t) eh) ew))))))))))
double code(double eh, double ew, double t) {
double tmp;
if (t <= -9.5e+68) {
tmp = fabs((cos(t) * ew));
} else if ((t <= -3.75e-6) || !(t <= 4.4e-18)) {
tmp = fabs((eh * (sin(t) * sin(atan(((t * eh) / ew))))));
} else {
tmp = fabs((ew + (eh * (t * sin(atan(((tan(t) * eh) / ew)))))));
}
return tmp;
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-9.5d+68)) then
tmp = abs((cos(t) * ew))
else if ((t <= (-3.75d-6)) .or. (.not. (t <= 4.4d-18))) then
tmp = abs((eh * (sin(t) * sin(atan(((t * eh) / ew))))))
else
tmp = abs((ew + (eh * (t * sin(atan(((tan(t) * eh) / ew)))))))
end if
code = tmp
end function
public static double code(double eh, double ew, double t) {
double tmp;
if (t <= -9.5e+68) {
tmp = Math.abs((Math.cos(t) * ew));
} else if ((t <= -3.75e-6) || !(t <= 4.4e-18)) {
tmp = Math.abs((eh * (Math.sin(t) * Math.sin(Math.atan(((t * eh) / ew))))));
} else {
tmp = Math.abs((ew + (eh * (t * Math.sin(Math.atan(((Math.tan(t) * eh) / ew)))))));
}
return tmp;
}
def code(eh, ew, t): tmp = 0 if t <= -9.5e+68: tmp = math.fabs((math.cos(t) * ew)) elif (t <= -3.75e-6) or not (t <= 4.4e-18): tmp = math.fabs((eh * (math.sin(t) * math.sin(math.atan(((t * eh) / ew)))))) else: tmp = math.fabs((ew + (eh * (t * math.sin(math.atan(((math.tan(t) * eh) / ew))))))) return tmp
function code(eh, ew, t) tmp = 0.0 if (t <= -9.5e+68) tmp = abs(Float64(cos(t) * ew)); elseif ((t <= -3.75e-6) || !(t <= 4.4e-18)) tmp = abs(Float64(eh * Float64(sin(t) * sin(atan(Float64(Float64(t * eh) / ew)))))); else tmp = abs(Float64(ew + Float64(eh * Float64(t * sin(atan(Float64(Float64(tan(t) * eh) / ew))))))); end return tmp end
function tmp_2 = code(eh, ew, t) tmp = 0.0; if (t <= -9.5e+68) tmp = abs((cos(t) * ew)); elseif ((t <= -3.75e-6) || ~((t <= 4.4e-18))) tmp = abs((eh * (sin(t) * sin(atan(((t * eh) / ew)))))); else tmp = abs((ew + (eh * (t * sin(atan(((tan(t) * eh) / ew))))))); end tmp_2 = tmp; end
code[eh_, ew_, t_] := If[LessEqual[t, -9.5e+68], N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[t, -3.75e-6], N[Not[LessEqual[t, 4.4e-18]], $MachinePrecision]], N[Abs[N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[N[(N[(t * eh), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(ew + N[(eh * N[(t * N[Sin[N[ArcTan[N[(N[(N[Tan[t], $MachinePrecision] * eh), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -9.5 \cdot 10^{+68}:\\
\;\;\;\;\left|\cos t \cdot ew\right|\\
\mathbf{elif}\;t \leq -3.75 \cdot 10^{-6} \lor \neg \left(t \leq 4.4 \cdot 10^{-18}\right):\\
\;\;\;\;\left|eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(\frac{t \cdot eh}{ew}\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|ew + eh \cdot \left(t \cdot \sin \tan^{-1} \left(\frac{\tan t \cdot eh}{ew}\right)\right)\right|\\
\end{array}
\end{array}
if t < -9.50000000000000069e68Initial program 99.6%
add-cbrt-cube29.7%
pow329.8%
Applied egg-rr29.8%
Taylor expanded in ew around inf 20.7%
pow-prod-down20.8%
rem-cbrt-cube67.6%
*-commutative67.6%
Applied egg-rr67.6%
if -9.50000000000000069e68 < t < -3.7500000000000001e-6 or 4.3999999999999997e-18 < t Initial program 99.6%
add-cbrt-cube39.5%
pow339.5%
Applied egg-rr39.5%
Taylor expanded in ew around 0 64.0%
Taylor expanded in t around 0 64.2%
if -3.7500000000000001e-6 < t < 4.3999999999999997e-18Initial program 100.0%
add-cbrt-cube39.8%
pow339.9%
Applied egg-rr39.9%
Taylor expanded in t around 0 99.1%
Final simplification83.2%
(FPCore (eh ew t) :precision binary64 (if (or (<= ew -3.6e-53) (not (<= ew 3.1e-103))) (fabs (* (cos t) ew)) (fabs (* eh (* (sin t) (sin (atan (/ (* t eh) ew))))))))
double code(double eh, double ew, double t) {
double tmp;
if ((ew <= -3.6e-53) || !(ew <= 3.1e-103)) {
tmp = fabs((cos(t) * ew));
} else {
tmp = fabs((eh * (sin(t) * sin(atan(((t * eh) / ew))))));
}
return tmp;
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: tmp
if ((ew <= (-3.6d-53)) .or. (.not. (ew <= 3.1d-103))) then
tmp = abs((cos(t) * ew))
else
tmp = abs((eh * (sin(t) * sin(atan(((t * eh) / ew))))))
end if
code = tmp
end function
public static double code(double eh, double ew, double t) {
double tmp;
if ((ew <= -3.6e-53) || !(ew <= 3.1e-103)) {
tmp = Math.abs((Math.cos(t) * ew));
} else {
tmp = Math.abs((eh * (Math.sin(t) * Math.sin(Math.atan(((t * eh) / ew))))));
}
return tmp;
}
def code(eh, ew, t): tmp = 0 if (ew <= -3.6e-53) or not (ew <= 3.1e-103): tmp = math.fabs((math.cos(t) * ew)) else: tmp = math.fabs((eh * (math.sin(t) * math.sin(math.atan(((t * eh) / ew)))))) return tmp
function code(eh, ew, t) tmp = 0.0 if ((ew <= -3.6e-53) || !(ew <= 3.1e-103)) tmp = abs(Float64(cos(t) * ew)); else tmp = abs(Float64(eh * Float64(sin(t) * sin(atan(Float64(Float64(t * eh) / ew)))))); end return tmp end
function tmp_2 = code(eh, ew, t) tmp = 0.0; if ((ew <= -3.6e-53) || ~((ew <= 3.1e-103))) tmp = abs((cos(t) * ew)); else tmp = abs((eh * (sin(t) * sin(atan(((t * eh) / ew)))))); end tmp_2 = tmp; end
code[eh_, ew_, t_] := If[Or[LessEqual[ew, -3.6e-53], N[Not[LessEqual[ew, 3.1e-103]], $MachinePrecision]], N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision], N[Abs[N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[N[(N[(t * eh), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ew \leq -3.6 \cdot 10^{-53} \lor \neg \left(ew \leq 3.1 \cdot 10^{-103}\right):\\
\;\;\;\;\left|\cos t \cdot ew\right|\\
\mathbf{else}:\\
\;\;\;\;\left|eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(\frac{t \cdot eh}{ew}\right)\right)\right|\\
\end{array}
\end{array}
if ew < -3.5999999999999999e-53 or 3.1000000000000001e-103 < ew Initial program 99.8%
add-cbrt-cube38.3%
pow338.3%
Applied egg-rr38.3%
Taylor expanded in ew around inf 31.8%
pow-prod-down31.8%
rem-cbrt-cube80.6%
*-commutative80.6%
Applied egg-rr80.6%
if -3.5999999999999999e-53 < ew < 3.1000000000000001e-103Initial program 99.8%
add-cbrt-cube37.6%
pow337.6%
Applied egg-rr37.6%
Taylor expanded in ew around 0 73.4%
Taylor expanded in t around 0 73.5%
Final simplification77.7%
(FPCore (eh ew t) :precision binary64 (fabs (* (cos t) ew)))
double code(double eh, double ew, double t) {
return fabs((cos(t) * ew));
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
code = abs((cos(t) * ew))
end function
public static double code(double eh, double ew, double t) {
return Math.abs((Math.cos(t) * ew));
}
def code(eh, ew, t): return math.fabs((math.cos(t) * ew))
function code(eh, ew, t) return abs(Float64(cos(t) * ew)) end
function tmp = code(eh, ew, t) tmp = abs((cos(t) * ew)); end
code[eh_, ew_, t_] := N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\cos t \cdot ew\right|
\end{array}
Initial program 99.8%
add-cbrt-cube38.0%
pow338.0%
Applied egg-rr38.0%
Taylor expanded in ew around inf 22.1%
pow-prod-down22.1%
rem-cbrt-cube60.8%
*-commutative60.8%
Applied egg-rr60.8%
(FPCore (eh ew t) :precision binary64 (fabs ew))
double code(double eh, double ew, double t) {
return fabs(ew);
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
code = abs(ew)
end function
public static double code(double eh, double ew, double t) {
return Math.abs(ew);
}
def code(eh, ew, t): return math.fabs(ew)
function code(eh, ew, t) return abs(ew) end
function tmp = code(eh, ew, t) tmp = abs(ew); end
code[eh_, ew_, t_] := N[Abs[ew], $MachinePrecision]
\begin{array}{l}
\\
\left|ew\right|
\end{array}
Initial program 99.8%
add-cbrt-cube38.0%
pow338.0%
Applied egg-rr38.0%
Taylor expanded in t around 0 17.5%
Taylor expanded in ew around 0 43.7%
herbie shell --seed 2024141
(FPCore (eh ew t)
:name "Example 2 from Robby"
:precision binary64
(fabs (- (* (* ew (cos t)) (cos (atan (/ (* (- eh) (tan t)) ew)))) (* (* eh (sin t)) (sin (atan (/ (* (- eh) (tan t)) ew)))))))