
(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))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(eh, ew, t)
use fmin_fmax_functions
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))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(eh, ew, t)
use fmin_fmax_functions
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 (atan (* -1.0 (/ (* eh (tan t)) ew)))))
(fabs
(-
(* (* -1.0 (* eh (sin t))) (sin t_1))
(* (* -1.0 (* ew (cos t))) (cos t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan((-1.0 * ((eh * tan(t)) / ew)));
return fabs((((-1.0 * (eh * sin(t))) * sin(t_1)) - ((-1.0 * (ew * cos(t))) * cos(t_1))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(eh, ew, t)
use fmin_fmax_functions
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
t_1 = atan(((-1.0d0) * ((eh * tan(t)) / ew)))
code = abs(((((-1.0d0) * (eh * sin(t))) * sin(t_1)) - (((-1.0d0) * (ew * cos(t))) * cos(t_1))))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.atan((-1.0 * ((eh * Math.tan(t)) / ew)));
return Math.abs((((-1.0 * (eh * Math.sin(t))) * Math.sin(t_1)) - ((-1.0 * (ew * Math.cos(t))) * Math.cos(t_1))));
}
def code(eh, ew, t): t_1 = math.atan((-1.0 * ((eh * math.tan(t)) / ew))) return math.fabs((((-1.0 * (eh * math.sin(t))) * math.sin(t_1)) - ((-1.0 * (ew * math.cos(t))) * math.cos(t_1))))
function code(eh, ew, t) t_1 = atan(Float64(-1.0 * Float64(Float64(eh * tan(t)) / ew))) return abs(Float64(Float64(Float64(-1.0 * Float64(eh * sin(t))) * sin(t_1)) - Float64(Float64(-1.0 * Float64(ew * cos(t))) * cos(t_1)))) end
function tmp = code(eh, ew, t) t_1 = atan((-1.0 * ((eh * tan(t)) / ew))); tmp = abs((((-1.0 * (eh * sin(t))) * sin(t_1)) - ((-1.0 * (ew * cos(t))) * cos(t_1)))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(-1.0 * N[(N[(eh * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(-1.0 * N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(-1 \cdot \frac{eh \cdot \tan t}{ew}\right)\\
\left|\left(-1 \cdot \left(eh \cdot \sin t\right)\right) \cdot \sin t\_1 - \left(-1 \cdot \left(ew \cdot \cos t\right)\right) \cdot \cos t\_1\right|
\end{array}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (* (sin t) eh))
(t_2 (* (/ -1.0 (cos t)) (/ t_1 ew)))
(t_3 (tanh (asinh t_2)))
(t_4 (cos (atan t_2))))
(if (or (<= ew -4e+24) (not (<= ew 5e-30)))
(fabs (* (fma (/ (* t_1 t_3) ew) -1.0 (* t_4 (cos t))) ew))
(fabs (* (- (/ (* (* (cos t) ew) t_4) eh) (* t_3 (sin t))) eh)))))
double code(double eh, double ew, double t) {
double t_1 = sin(t) * eh;
double t_2 = (-1.0 / cos(t)) * (t_1 / ew);
double t_3 = tanh(asinh(t_2));
double t_4 = cos(atan(t_2));
double tmp;
if ((ew <= -4e+24) || !(ew <= 5e-30)) {
tmp = fabs((fma(((t_1 * t_3) / ew), -1.0, (t_4 * cos(t))) * ew));
} else {
tmp = fabs((((((cos(t) * ew) * t_4) / eh) - (t_3 * sin(t))) * eh));
}
return tmp;
}
function code(eh, ew, t) t_1 = Float64(sin(t) * eh) t_2 = Float64(Float64(-1.0 / cos(t)) * Float64(t_1 / ew)) t_3 = tanh(asinh(t_2)) t_4 = cos(atan(t_2)) tmp = 0.0 if ((ew <= -4e+24) || !(ew <= 5e-30)) tmp = abs(Float64(fma(Float64(Float64(t_1 * t_3) / ew), -1.0, Float64(t_4 * cos(t))) * ew)); else tmp = abs(Float64(Float64(Float64(Float64(Float64(cos(t) * ew) * t_4) / eh) - Float64(t_3 * sin(t))) * eh)); end return tmp end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision]}, Block[{t$95$2 = N[(N[(-1.0 / N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 / ew), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Tanh[N[ArcSinh[t$95$2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[ArcTan[t$95$2], $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[ew, -4e+24], N[Not[LessEqual[ew, 5e-30]], $MachinePrecision]], N[Abs[N[(N[(N[(N[(t$95$1 * t$95$3), $MachinePrecision] / ew), $MachinePrecision] * -1.0 + N[(t$95$4 * N[Cos[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(N[(N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision] * t$95$4), $MachinePrecision] / eh), $MachinePrecision] - N[(t$95$3 * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sin t \cdot eh\\
t_2 := \frac{-1}{\cos t} \cdot \frac{t\_1}{ew}\\
t_3 := \tanh \sinh^{-1} t\_2\\
t_4 := \cos \tan^{-1} t\_2\\
\mathbf{if}\;ew \leq -4 \cdot 10^{+24} \lor \neg \left(ew \leq 5 \cdot 10^{-30}\right):\\
\;\;\;\;\left|\mathsf{fma}\left(\frac{t\_1 \cdot t\_3}{ew}, -1, t\_4 \cdot \cos t\right) \cdot ew\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\left(\frac{\left(\cos t \cdot ew\right) \cdot t\_4}{eh} - t\_3 \cdot \sin t\right) \cdot eh\right|\\
\end{array}
\end{array}
if ew < -3.9999999999999999e24 or 4.99999999999999972e-30 < ew Initial program 99.8%
Taylor expanded in ew around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
if -3.9999999999999999e24 < ew < 4.99999999999999972e-30Initial program 99.8%
Taylor expanded in eh around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
Final simplification99.8%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (atan (* -1.0 (/ (* eh (tan t)) ew)))))
(fabs
(+
(* (* -1.0 (* eh (sin t))) (sin t_1))
(*
(*
(- (* -1.0 ew))
(fma
(cos t)
(sin (* 0.5 PI))
(* (sin (fma 0.5 PI (/ PI 2.0))) (sin t))))
(cos t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan((-1.0 * ((eh * tan(t)) / ew)));
return fabs((((-1.0 * (eh * sin(t))) * sin(t_1)) + ((-(-1.0 * ew) * fma(cos(t), sin((0.5 * ((double) M_PI))), (sin(fma(0.5, ((double) M_PI), (((double) M_PI) / 2.0))) * sin(t)))) * cos(t_1))));
}
function code(eh, ew, t) t_1 = atan(Float64(-1.0 * Float64(Float64(eh * tan(t)) / ew))) return abs(Float64(Float64(Float64(-1.0 * Float64(eh * sin(t))) * sin(t_1)) + Float64(Float64(Float64(-Float64(-1.0 * ew)) * fma(cos(t), sin(Float64(0.5 * pi)), Float64(sin(fma(0.5, pi, Float64(pi / 2.0))) * sin(t)))) * cos(t_1)))) end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(-1.0 * N[(N[(eh * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(-1.0 * N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision] + N[(N[((-N[(-1.0 * ew), $MachinePrecision]) * N[(N[Cos[t], $MachinePrecision] * N[Sin[N[(0.5 * Pi), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(0.5 * Pi + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(-1 \cdot \frac{eh \cdot \tan t}{ew}\right)\\
\left|\left(-1 \cdot \left(eh \cdot \sin t\right)\right) \cdot \sin t\_1 + \left(\left(--1 \cdot ew\right) \cdot \mathsf{fma}\left(\cos t, \sin \left(0.5 \cdot \pi\right), \sin \left(\mathsf{fma}\left(0.5, \pi, \frac{\pi}{2}\right)\right) \cdot \sin t\right)\right) \cdot \cos t\_1\right|
\end{array}
\end{array}
Initial program 99.8%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lower-fma.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-PI.f6499.6
Applied rewrites99.6%
Taylor expanded in t around inf
lower-fma.f64N/A
lift-cos.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lower-fma.f64N/A
lift-PI.f64N/A
lift-sin.f6499.5
Applied rewrites99.5%
Final simplification99.5%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (* (/ -1.0 (cos t)) (/ (* (sin t) eh) ew))))
(fabs
(*
(-
(/ (* (* (cos t) ew) (cos (atan t_1))) eh)
(* (tanh (asinh t_1)) (sin t)))
eh))))
double code(double eh, double ew, double t) {
double t_1 = (-1.0 / cos(t)) * ((sin(t) * eh) / ew);
return fabs((((((cos(t) * ew) * cos(atan(t_1))) / eh) - (tanh(asinh(t_1)) * sin(t))) * eh));
}
def code(eh, ew, t): t_1 = (-1.0 / math.cos(t)) * ((math.sin(t) * eh) / ew) return math.fabs((((((math.cos(t) * ew) * math.cos(math.atan(t_1))) / eh) - (math.tanh(math.asinh(t_1)) * math.sin(t))) * eh))
function code(eh, ew, t) t_1 = Float64(Float64(-1.0 / cos(t)) * Float64(Float64(sin(t) * eh) / ew)) return abs(Float64(Float64(Float64(Float64(Float64(cos(t) * ew) * cos(atan(t_1))) / eh) - Float64(tanh(asinh(t_1)) * sin(t))) * eh)) end
function tmp = code(eh, ew, t) t_1 = (-1.0 / cos(t)) * ((sin(t) * eh) / ew); tmp = abs((((((cos(t) * ew) * cos(atan(t_1))) / eh) - (tanh(asinh(t_1)) * sin(t))) * eh)); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[(-1.0 / N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(N[(N[(N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision] * N[Cos[N[ArcTan[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / eh), $MachinePrecision] - N[(N[Tanh[N[ArcSinh[t$95$1], $MachinePrecision]], $MachinePrecision] * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{-1}{\cos t} \cdot \frac{\sin t \cdot eh}{ew}\\
\left|\left(\frac{\left(\cos t \cdot ew\right) \cdot \cos \tan^{-1} t\_1}{eh} - \tanh \sinh^{-1} t\_1 \cdot \sin t\right) \cdot eh\right|
\end{array}
\end{array}
Initial program 99.8%
Taylor expanded in eh around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites86.2%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (* (* -1.0 (cos t)) (cos (atan (* (* -1.0 (/ eh ew)) (tan t))))))
(t_2
(*
(exp (+ (log 2.0) (log (/ (sin t) (* ew (cos t))))))
(exp (log (pow (/ 1.0 (* -1.0 eh)) -1.0)))))
(t_3 (pow t_2 -1.0)))
(if (or (<= ew -3.5e-116) (not (<= ew 2.05e-177)))
(fabs
(*
(*
ew
(fma
(/ eh (* ew ew))
(/ (pow (sin t) 2.0) (cos t))
(/ t_1 (* -1.0 eh))))
eh))
(fabs
(*
(*
(* -1.0 eh)
(+ (/ t_1 eh) (* (/ (sin t) ew) (/ (- t_2 t_3) (+ t_2 t_3)))))
ew)))))
double code(double eh, double ew, double t) {
double t_1 = (-1.0 * cos(t)) * cos(atan(((-1.0 * (eh / ew)) * tan(t))));
double t_2 = exp((log(2.0) + log((sin(t) / (ew * cos(t)))))) * exp(log(pow((1.0 / (-1.0 * eh)), -1.0)));
double t_3 = pow(t_2, -1.0);
double tmp;
if ((ew <= -3.5e-116) || !(ew <= 2.05e-177)) {
tmp = fabs(((ew * fma((eh / (ew * ew)), (pow(sin(t), 2.0) / cos(t)), (t_1 / (-1.0 * eh)))) * eh));
} else {
tmp = fabs((((-1.0 * eh) * ((t_1 / eh) + ((sin(t) / ew) * ((t_2 - t_3) / (t_2 + t_3))))) * ew));
}
return tmp;
}
function code(eh, ew, t) t_1 = Float64(Float64(-1.0 * cos(t)) * cos(atan(Float64(Float64(-1.0 * Float64(eh / ew)) * tan(t))))) t_2 = Float64(exp(Float64(log(2.0) + log(Float64(sin(t) / Float64(ew * cos(t)))))) * exp(log((Float64(1.0 / Float64(-1.0 * eh)) ^ -1.0)))) t_3 = t_2 ^ -1.0 tmp = 0.0 if ((ew <= -3.5e-116) || !(ew <= 2.05e-177)) tmp = abs(Float64(Float64(ew * fma(Float64(eh / Float64(ew * ew)), Float64((sin(t) ^ 2.0) / cos(t)), Float64(t_1 / Float64(-1.0 * eh)))) * eh)); else tmp = abs(Float64(Float64(Float64(-1.0 * eh) * Float64(Float64(t_1 / eh) + Float64(Float64(sin(t) / ew) * Float64(Float64(t_2 - t_3) / Float64(t_2 + t_3))))) * ew)); end return tmp end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[(-1.0 * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[N[ArcTan[N[(N[(-1.0 * N[(eh / ew), $MachinePrecision]), $MachinePrecision] * N[Tan[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(N[Log[2.0], $MachinePrecision] + N[Log[N[(N[Sin[t], $MachinePrecision] / N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[N[Log[N[Power[N[(1.0 / N[(-1.0 * eh), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, -1.0], $MachinePrecision]}, If[Or[LessEqual[ew, -3.5e-116], N[Not[LessEqual[ew, 2.05e-177]], $MachinePrecision]], N[Abs[N[(N[(ew * N[(N[(eh / N[(ew * ew), $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[Sin[t], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[t], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 / N[(-1.0 * eh), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(-1.0 * eh), $MachinePrecision] * N[(N[(t$95$1 / eh), $MachinePrecision] + N[(N[(N[Sin[t], $MachinePrecision] / ew), $MachinePrecision] * N[(N[(t$95$2 - t$95$3), $MachinePrecision] / N[(t$95$2 + t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(-1 \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\left(-1 \cdot \frac{eh}{ew}\right) \cdot \tan t\right)\\
t_2 := e^{\log 2 + \log \left(\frac{\sin t}{ew \cdot \cos t}\right)} \cdot e^{\log \left({\left(\frac{1}{-1 \cdot eh}\right)}^{-1}\right)}\\
t_3 := {t\_2}^{-1}\\
\mathbf{if}\;ew \leq -3.5 \cdot 10^{-116} \lor \neg \left(ew \leq 2.05 \cdot 10^{-177}\right):\\
\;\;\;\;\left|\left(ew \cdot \mathsf{fma}\left(\frac{eh}{ew \cdot ew}, \frac{{\sin t}^{2}}{\cos t}, \frac{t\_1}{-1 \cdot eh}\right)\right) \cdot eh\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\left(\left(-1 \cdot eh\right) \cdot \left(\frac{t\_1}{eh} + \frac{\sin t}{ew} \cdot \frac{t\_2 - t\_3}{t\_2 + t\_3}\right)\right) \cdot ew\right|\\
\end{array}
\end{array}
if ew < -3.49999999999999984e-116 or 2.05e-177 < ew Initial program 99.8%
Taylor expanded in eh around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites82.5%
Taylor expanded in ew around inf
lower-*.f64N/A
times-fracN/A
lower-fma.f64N/A
Applied rewrites52.5%
if -3.49999999999999984e-116 < ew < 2.05e-177Initial program 99.7%
Taylor expanded in ew around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites83.0%
Taylor expanded in eh around -inf
Applied rewrites24.9%
Final simplification46.5%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1
(*
(exp (+ (log 2.0) (log (/ (sin t) (* ew (cos t))))))
(exp (log (pow (/ 1.0 (* -1.0 eh)) -1.0)))))
(t_2 (pow t_1 -1.0)))
(fabs
(*
(*
(* -1.0 eh)
(+
(/ (* (* -1.0 (cos t)) (cos (atan (* (* -1.0 (/ eh ew)) (tan t))))) eh)
(* (/ (sin t) ew) (/ (- t_1 t_2) (+ t_1 t_2)))))
ew))))
double code(double eh, double ew, double t) {
double t_1 = exp((log(2.0) + log((sin(t) / (ew * cos(t)))))) * exp(log(pow((1.0 / (-1.0 * eh)), -1.0)));
double t_2 = pow(t_1, -1.0);
return fabs((((-1.0 * eh) * ((((-1.0 * cos(t)) * cos(atan(((-1.0 * (eh / ew)) * tan(t))))) / eh) + ((sin(t) / ew) * ((t_1 - t_2) / (t_1 + t_2))))) * ew));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(eh, ew, t)
use fmin_fmax_functions
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
t_1 = exp((log(2.0d0) + log((sin(t) / (ew * cos(t)))))) * exp(log(((1.0d0 / ((-1.0d0) * eh)) ** (-1.0d0))))
t_2 = t_1 ** (-1.0d0)
code = abs(((((-1.0d0) * eh) * (((((-1.0d0) * cos(t)) * cos(atan((((-1.0d0) * (eh / ew)) * tan(t))))) / eh) + ((sin(t) / ew) * ((t_1 - t_2) / (t_1 + t_2))))) * ew))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.exp((Math.log(2.0) + Math.log((Math.sin(t) / (ew * Math.cos(t)))))) * Math.exp(Math.log(Math.pow((1.0 / (-1.0 * eh)), -1.0)));
double t_2 = Math.pow(t_1, -1.0);
return Math.abs((((-1.0 * eh) * ((((-1.0 * Math.cos(t)) * Math.cos(Math.atan(((-1.0 * (eh / ew)) * Math.tan(t))))) / eh) + ((Math.sin(t) / ew) * ((t_1 - t_2) / (t_1 + t_2))))) * ew));
}
def code(eh, ew, t): t_1 = math.exp((math.log(2.0) + math.log((math.sin(t) / (ew * math.cos(t)))))) * math.exp(math.log(math.pow((1.0 / (-1.0 * eh)), -1.0))) t_2 = math.pow(t_1, -1.0) return math.fabs((((-1.0 * eh) * ((((-1.0 * math.cos(t)) * math.cos(math.atan(((-1.0 * (eh / ew)) * math.tan(t))))) / eh) + ((math.sin(t) / ew) * ((t_1 - t_2) / (t_1 + t_2))))) * ew))
function code(eh, ew, t) t_1 = Float64(exp(Float64(log(2.0) + log(Float64(sin(t) / Float64(ew * cos(t)))))) * exp(log((Float64(1.0 / Float64(-1.0 * eh)) ^ -1.0)))) t_2 = t_1 ^ -1.0 return abs(Float64(Float64(Float64(-1.0 * eh) * Float64(Float64(Float64(Float64(-1.0 * cos(t)) * cos(atan(Float64(Float64(-1.0 * Float64(eh / ew)) * tan(t))))) / eh) + Float64(Float64(sin(t) / ew) * Float64(Float64(t_1 - t_2) / Float64(t_1 + t_2))))) * ew)) end
function tmp = code(eh, ew, t) t_1 = exp((log(2.0) + log((sin(t) / (ew * cos(t)))))) * exp(log(((1.0 / (-1.0 * eh)) ^ -1.0))); t_2 = t_1 ^ -1.0; tmp = abs((((-1.0 * eh) * ((((-1.0 * cos(t)) * cos(atan(((-1.0 * (eh / ew)) * tan(t))))) / eh) + ((sin(t) / ew) * ((t_1 - t_2) / (t_1 + t_2))))) * ew)); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[Exp[N[(N[Log[2.0], $MachinePrecision] + N[Log[N[(N[Sin[t], $MachinePrecision] / N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[N[Log[N[Power[N[(1.0 / N[(-1.0 * eh), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, -1.0], $MachinePrecision]}, N[Abs[N[(N[(N[(-1.0 * eh), $MachinePrecision] * N[(N[(N[(N[(-1.0 * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[N[ArcTan[N[(N[(-1.0 * N[(eh / ew), $MachinePrecision]), $MachinePrecision] * N[Tan[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / eh), $MachinePrecision] + N[(N[(N[Sin[t], $MachinePrecision] / ew), $MachinePrecision] * N[(N[(t$95$1 - t$95$2), $MachinePrecision] / N[(t$95$1 + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := e^{\log 2 + \log \left(\frac{\sin t}{ew \cdot \cos t}\right)} \cdot e^{\log \left({\left(\frac{1}{-1 \cdot eh}\right)}^{-1}\right)}\\
t_2 := {t\_1}^{-1}\\
\left|\left(\left(-1 \cdot eh\right) \cdot \left(\frac{\left(-1 \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\left(-1 \cdot \frac{eh}{ew}\right) \cdot \tan t\right)}{eh} + \frac{\sin t}{ew} \cdot \frac{t\_1 - t\_2}{t\_1 + t\_2}\right)\right) \cdot ew\right|
\end{array}
\end{array}
Initial program 99.8%
Taylor expanded in ew around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.5%
Taylor expanded in eh around -inf
Applied rewrites14.1%
Final simplification14.1%
herbie shell --seed 2025064
(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)))))))