
(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 7 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 (* eh (/ (tan t) 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 = eh * (tan(t) / 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 = eh * (Math.tan(t) / 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 = eh * (math.tan(t) / 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(eh * Float64(tan(t) / ew)) return abs(Float64(Float64(Float64(ew * 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 = eh * (tan(t) / 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[(eh * N[(N[Tan[t], $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + t$95$1 ^ 2], $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 := eh \cdot \frac{\tan t}{ew}\\
\left|\frac{ew \cdot \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%
cos-atan99.8%
un-div-inv99.8%
hypot-1-def99.8%
associate-/l*99.8%
add-sqr-sqrt54.6%
sqrt-unprod94.5%
sqr-neg94.5%
sqrt-unprod45.2%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (* eh (* (sin t) (sin (atan (/ (* eh (tan t)) ew))))))) (if (<= eh 1.18e+232) (fabs (* ew (+ (cos t) (/ t_1 ew)))) (fabs t_1))))
double code(double eh, double ew, double t) {
double t_1 = eh * (sin(t) * sin(atan(((eh * tan(t)) / ew))));
double tmp;
if (eh <= 1.18e+232) {
tmp = fabs((ew * (cos(t) + (t_1 / ew))));
} else {
tmp = fabs(t_1);
}
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) :: t_1
real(8) :: tmp
t_1 = eh * (sin(t) * sin(atan(((eh * tan(t)) / ew))))
if (eh <= 1.18d+232) then
tmp = abs((ew * (cos(t) + (t_1 / ew))))
else
tmp = abs(t_1)
end if
code = tmp
end function
public static double code(double eh, double ew, double t) {
double t_1 = eh * (Math.sin(t) * Math.sin(Math.atan(((eh * Math.tan(t)) / ew))));
double tmp;
if (eh <= 1.18e+232) {
tmp = Math.abs((ew * (Math.cos(t) + (t_1 / ew))));
} else {
tmp = Math.abs(t_1);
}
return tmp;
}
def code(eh, ew, t): t_1 = eh * (math.sin(t) * math.sin(math.atan(((eh * math.tan(t)) / ew)))) tmp = 0 if eh <= 1.18e+232: tmp = math.fabs((ew * (math.cos(t) + (t_1 / ew)))) else: tmp = math.fabs(t_1) return tmp
function code(eh, ew, t) t_1 = Float64(eh * Float64(sin(t) * sin(atan(Float64(Float64(eh * tan(t)) / ew))))) tmp = 0.0 if (eh <= 1.18e+232) tmp = abs(Float64(ew * Float64(cos(t) + Float64(t_1 / ew)))); else tmp = abs(t_1); end return tmp end
function tmp_2 = code(eh, ew, t) t_1 = eh * (sin(t) * sin(atan(((eh * tan(t)) / ew)))); tmp = 0.0; if (eh <= 1.18e+232) tmp = abs((ew * (cos(t) + (t_1 / ew)))); else tmp = abs(t_1); end tmp_2 = tmp; end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[N[(N[(eh * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eh, 1.18e+232], N[Abs[N[(ew * N[(N[Cos[t], $MachinePrecision] + N[(t$95$1 / ew), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[t$95$1], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(\frac{eh \cdot \tan t}{ew}\right)\right)\\
\mathbf{if}\;eh \leq 1.18 \cdot 10^{+232}:\\
\;\;\;\;\left|ew \cdot \left(\cos t + \frac{t\_1}{ew}\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|t\_1\right|\\
\end{array}
\end{array}
if eh < 1.18e232Initial program 99.8%
add-cbrt-cube39.4%
pow339.4%
Applied egg-rr39.4%
Taylor expanded in ew around inf 94.0%
if 1.18e232 < eh Initial program 99.8%
add-cbrt-cube16.6%
pow316.6%
Applied egg-rr16.6%
Taylor expanded in ew around 0 99.8%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (fabs (* ew (cos t)))))
(if (<= ew -2.45e-113)
t_1
(if (<= ew 3.4e-136)
(fabs (* eh (* (sin t) (sin (atan (/ (* eh (tan t)) ew))))))
t_1))))
double code(double eh, double ew, double t) {
double t_1 = fabs((ew * cos(t)));
double tmp;
if (ew <= -2.45e-113) {
tmp = t_1;
} else if (ew <= 3.4e-136) {
tmp = fabs((eh * (sin(t) * sin(atan(((eh * tan(t)) / ew))))));
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = abs((ew * cos(t)))
if (ew <= (-2.45d-113)) then
tmp = t_1
else if (ew <= 3.4d-136) then
tmp = abs((eh * (sin(t) * sin(atan(((eh * tan(t)) / ew))))))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.abs((ew * Math.cos(t)));
double tmp;
if (ew <= -2.45e-113) {
tmp = t_1;
} else if (ew <= 3.4e-136) {
tmp = Math.abs((eh * (Math.sin(t) * Math.sin(Math.atan(((eh * Math.tan(t)) / ew))))));
} else {
tmp = t_1;
}
return tmp;
}
def code(eh, ew, t): t_1 = math.fabs((ew * math.cos(t))) tmp = 0 if ew <= -2.45e-113: tmp = t_1 elif ew <= 3.4e-136: tmp = math.fabs((eh * (math.sin(t) * math.sin(math.atan(((eh * math.tan(t)) / ew)))))) else: tmp = t_1 return tmp
function code(eh, ew, t) t_1 = abs(Float64(ew * cos(t))) tmp = 0.0 if (ew <= -2.45e-113) tmp = t_1; elseif (ew <= 3.4e-136) tmp = abs(Float64(eh * Float64(sin(t) * sin(atan(Float64(Float64(eh * tan(t)) / ew)))))); else tmp = t_1; end return tmp end
function tmp_2 = code(eh, ew, t) t_1 = abs((ew * cos(t))); tmp = 0.0; if (ew <= -2.45e-113) tmp = t_1; elseif (ew <= 3.4e-136) tmp = abs((eh * (sin(t) * sin(atan(((eh * tan(t)) / ew)))))); else tmp = t_1; end tmp_2 = tmp; end
code[eh_, ew_, t_] := Block[{t$95$1 = N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[ew, -2.45e-113], t$95$1, If[LessEqual[ew, 3.4e-136], N[Abs[N[(eh * N[(N[Sin[t], $MachinePrecision] * N[Sin[N[ArcTan[N[(N[(eh * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left|ew \cdot \cos t\right|\\
\mathbf{if}\;ew \leq -2.45 \cdot 10^{-113}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;ew \leq 3.4 \cdot 10^{-136}:\\
\;\;\;\;\left|eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(\frac{eh \cdot \tan t}{ew}\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if ew < -2.4500000000000001e-113 or 3.4e-136 < ew Initial program 99.8%
add-cbrt-cube39.6%
pow339.7%
Applied egg-rr39.7%
Taylor expanded in ew around inf 82.6%
if -2.4500000000000001e-113 < ew < 3.4e-136Initial program 99.7%
add-cbrt-cube35.8%
pow335.8%
Applied egg-rr35.8%
Taylor expanded in ew around 0 76.5%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (fabs (* ew (cos t)))))
(if (<= t -0.0015)
t_1
(if (<= t 480.0)
(fabs (+ ew (* eh (* t (sin (atan (/ (* eh t) ew)))))))
t_1))))
double code(double eh, double ew, double t) {
double t_1 = fabs((ew * cos(t)));
double tmp;
if (t <= -0.0015) {
tmp = t_1;
} else if (t <= 480.0) {
tmp = fabs((ew + (eh * (t * sin(atan(((eh * t) / ew)))))));
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = abs((ew * cos(t)))
if (t <= (-0.0015d0)) then
tmp = t_1
else if (t <= 480.0d0) then
tmp = abs((ew + (eh * (t * sin(atan(((eh * t) / ew)))))))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.abs((ew * Math.cos(t)));
double tmp;
if (t <= -0.0015) {
tmp = t_1;
} else if (t <= 480.0) {
tmp = Math.abs((ew + (eh * (t * Math.sin(Math.atan(((eh * t) / ew)))))));
} else {
tmp = t_1;
}
return tmp;
}
def code(eh, ew, t): t_1 = math.fabs((ew * math.cos(t))) tmp = 0 if t <= -0.0015: tmp = t_1 elif t <= 480.0: tmp = math.fabs((ew + (eh * (t * math.sin(math.atan(((eh * t) / ew))))))) else: tmp = t_1 return tmp
function code(eh, ew, t) t_1 = abs(Float64(ew * cos(t))) tmp = 0.0 if (t <= -0.0015) tmp = t_1; elseif (t <= 480.0) tmp = abs(Float64(ew + Float64(eh * Float64(t * sin(atan(Float64(Float64(eh * t) / ew))))))); else tmp = t_1; end return tmp end
function tmp_2 = code(eh, ew, t) t_1 = abs((ew * cos(t))); tmp = 0.0; if (t <= -0.0015) tmp = t_1; elseif (t <= 480.0) tmp = abs((ew + (eh * (t * sin(atan(((eh * t) / ew))))))); else tmp = t_1; end tmp_2 = tmp; end
code[eh_, ew_, t_] := Block[{t$95$1 = N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t, -0.0015], t$95$1, If[LessEqual[t, 480.0], N[Abs[N[(ew + N[(eh * N[(t * N[Sin[N[ArcTan[N[(N[(eh * t), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left|ew \cdot \cos t\right|\\
\mathbf{if}\;t \leq -0.0015:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 480:\\
\;\;\;\;\left|ew + eh \cdot \left(t \cdot \sin \tan^{-1} \left(\frac{eh \cdot t}{ew}\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -0.0015 or 480 < t Initial program 99.6%
add-cbrt-cube37.7%
pow337.7%
Applied egg-rr37.7%
Taylor expanded in ew around inf 57.3%
if -0.0015 < t < 480Initial program 100.0%
add-cbrt-cube39.4%
pow339.4%
Applied egg-rr39.4%
Taylor expanded in t around 0 99.3%
Taylor expanded in t around 0 99.3%
(FPCore (eh ew t) :precision binary64 (fabs (* ew (cos t))))
double code(double eh, double ew, double t) {
return fabs((ew * cos(t)));
}
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 * cos(t)))
end function
public static double code(double eh, double ew, double t) {
return Math.abs((ew * Math.cos(t)));
}
def code(eh, ew, t): return math.fabs((ew * math.cos(t)))
function code(eh, ew, t) return abs(Float64(ew * cos(t))) end
function tmp = code(eh, ew, t) tmp = abs((ew * cos(t))); end
code[eh_, ew_, t_] := N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|ew \cdot \cos t\right|
\end{array}
Initial program 99.8%
add-cbrt-cube38.5%
pow338.5%
Applied egg-rr38.5%
Taylor expanded in ew around inf 66.2%
(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.5%
pow338.5%
Applied egg-rr38.5%
Taylor expanded in t around 0 43.9%
(FPCore (eh ew t) :precision binary64 ew)
double code(double eh, double ew, double t) {
return ew;
}
real(8) function code(eh, ew, t)
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
code = ew
end function
public static double code(double eh, double ew, double t) {
return ew;
}
def code(eh, ew, t): return ew
function code(eh, ew, t) return ew end
function tmp = code(eh, ew, t) tmp = ew; end
code[eh_, ew_, t_] := ew
\begin{array}{l}
\\
ew
\end{array}
Initial program 99.8%
add-cbrt-cube38.5%
pow338.5%
Applied egg-rr38.5%
Taylor expanded in t around 0 43.9%
add-sqr-sqrt22.1%
fabs-sqr22.1%
add-sqr-sqrt23.0%
*-un-lft-identity23.0%
Applied egg-rr23.0%
Taylor expanded in ew around 0 23.0%
herbie shell --seed 2024116 -o generate:simplify
(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)))))))