Example 2 from Robby

Percentage Accurate: 99.8% → 99.8%
Time: 13.6s
Alternatives: 8
Speedup: N/A×

Specification

?
\[\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 (/ (* (- 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}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\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 (/ (* (- 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}

Alternative 1: 99.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(-eh\right) \cdot \frac{\tan t}{ew}\\ \left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} t\_1 - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {t\_1}^{2}}}\right| \end{array} \end{array} \]
(FPCore (eh ew t)
 :precision binary64
 (let* ((t_1 (* (- eh) (/ (tan t) ew))))
   (fabs
    (-
     (* (* (sin t) eh) (tanh (asinh t_1)))
     (* (* (cos t) ew) (/ 1.0 (sqrt (+ 1.0 (pow t_1 2.0)))))))))
double code(double eh, double ew, double t) {
	double t_1 = -eh * (tan(t) / ew);
	return fabs((((sin(t) * eh) * tanh(asinh(t_1))) - ((cos(t) * ew) * (1.0 / sqrt((1.0 + pow(t_1, 2.0)))))));
}
def code(eh, ew, t):
	t_1 = -eh * (math.tan(t) / ew)
	return math.fabs((((math.sin(t) * eh) * math.tanh(math.asinh(t_1))) - ((math.cos(t) * ew) * (1.0 / math.sqrt((1.0 + math.pow(t_1, 2.0)))))))
function code(eh, ew, t)
	t_1 = Float64(Float64(-eh) * Float64(tan(t) / ew))
	return abs(Float64(Float64(Float64(sin(t) * eh) * tanh(asinh(t_1))) - Float64(Float64(cos(t) * ew) * Float64(1.0 / sqrt(Float64(1.0 + (t_1 ^ 2.0)))))))
end
function tmp = code(eh, ew, t)
	t_1 = -eh * (tan(t) / ew);
	tmp = abs((((sin(t) * eh) * tanh(asinh(t_1))) - ((cos(t) * ew) * (1.0 / sqrt((1.0 + (t_1 ^ 2.0)))))));
end
code[eh_, ew_, t_] := Block[{t$95$1 = N[((-eh) * N[(N[Tan[t], $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision] * N[Tanh[N[ArcSinh[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(1.0 + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(-eh\right) \cdot \frac{\tan t}{ew}\\
\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} t\_1 - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {t\_1}^{2}}}\right|
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
  2. Applied rewrites99.8%

    \[\leadsto \color{blue}{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right)}^{2}}}\right|} \]
  3. Add Preprocessing

Alternative 2: 97.5% accurate, 2.1× speedup?

\[\begin{array}{l} \\ {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - ew \cdot \cos t\right|}\right)}^{2} \end{array} \]
(FPCore (eh ew t)
 :precision binary64
 (pow
  (sqrt
   (fabs
    (- (* (* (sin t) eh) (tanh (asinh (* (- eh) (/ t ew))))) (* ew (cos t)))))
  2.0))
double code(double eh, double ew, double t) {
	return pow(sqrt(fabs((((sin(t) * eh) * tanh(asinh((-eh * (t / ew))))) - (ew * cos(t))))), 2.0);
}
def code(eh, ew, t):
	return math.pow(math.sqrt(math.fabs((((math.sin(t) * eh) * math.tanh(math.asinh((-eh * (t / ew))))) - (ew * math.cos(t))))), 2.0)
function code(eh, ew, t)
	return sqrt(abs(Float64(Float64(Float64(sin(t) * eh) * tanh(asinh(Float64(Float64(-eh) * Float64(t / ew))))) - Float64(ew * cos(t))))) ^ 2.0
end
function tmp = code(eh, ew, t)
	tmp = sqrt(abs((((sin(t) * eh) * tanh(asinh((-eh * (t / ew))))) - (ew * cos(t))))) ^ 2.0;
end
code[eh_, ew_, t_] := N[Power[N[Sqrt[N[Abs[N[(N[(N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision] * N[Tanh[N[ArcSinh[N[((-eh) * N[(t / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}

\\
{\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - ew \cdot \cos t\right|}\right)}^{2}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
  2. Applied rewrites99.2%

    \[\leadsto \color{blue}{{\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right)}^{2}}}\right|}\right)}^{2}} \]
  3. Taylor expanded in t around 0

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \color{blue}{\frac{t}{ew}}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right)}^{2}}}\right|}\right)}^{2} \]
  4. Step-by-step derivation
    1. lower-/.f6498.4

      \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{\color{blue}{ew}}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right)}^{2}}}\right|}\right)}^{2} \]
  5. Applied rewrites98.4%

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \color{blue}{\frac{t}{ew}}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{\tan t}{ew}\right)}^{2}}}\right|}\right)}^{2} \]
  6. Taylor expanded in t around 0

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \color{blue}{\frac{t}{ew}}\right)}^{2}}}\right|}\right)}^{2} \]
  7. Step-by-step derivation
    1. lower-/.f6489.5

      \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \frac{t}{\color{blue}{ew}}\right)}^{2}}}\right|}\right)}^{2} \]
  8. Applied rewrites89.5%

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - \left(\cos t \cdot ew\right) \cdot \frac{1}{\sqrt{1 + {\left(\left(-eh\right) \cdot \color{blue}{\frac{t}{ew}}\right)}^{2}}}\right|}\right)}^{2} \]
  9. Taylor expanded in eh around 0

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - \color{blue}{ew \cdot \cos t}\right|}\right)}^{2} \]
  10. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - ew \cdot \cos t\right|}\right)}^{2} \]
    2. lift-*.f6497.5

      \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - ew \cdot \color{blue}{\cos t}\right|}\right)}^{2} \]
  11. Applied rewrites97.5%

    \[\leadsto {\left(\sqrt{\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(\left(-eh\right) \cdot \frac{t}{ew}\right) - \color{blue}{ew \cdot \cos t}\right|}\right)}^{2} \]
  12. Add Preprocessing

Alternative 3: 63.7% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ew \leq 8.5 \cdot 10^{-109}:\\ \;\;\;\;\left|\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\cos t \cdot ew\right|\\ \end{array} \end{array} \]
(FPCore (eh ew t)
 :precision binary64
 (if (<= ew 8.5e-109)
   (fabs (* (- eh) (* (tanh (asinh (- (* (/ eh ew) (tan t))))) (sin t))))
   (fabs (* (cos t) ew))))
double code(double eh, double ew, double t) {
	double tmp;
	if (ew <= 8.5e-109) {
		tmp = fabs((-eh * (tanh(asinh(-((eh / ew) * tan(t)))) * sin(t))));
	} else {
		tmp = fabs((cos(t) * ew));
	}
	return tmp;
}
def code(eh, ew, t):
	tmp = 0
	if ew <= 8.5e-109:
		tmp = math.fabs((-eh * (math.tanh(math.asinh(-((eh / ew) * math.tan(t)))) * math.sin(t))))
	else:
		tmp = math.fabs((math.cos(t) * ew))
	return tmp
function code(eh, ew, t)
	tmp = 0.0
	if (ew <= 8.5e-109)
		tmp = abs(Float64(Float64(-eh) * Float64(tanh(asinh(Float64(-Float64(Float64(eh / ew) * tan(t))))) * sin(t))));
	else
		tmp = abs(Float64(cos(t) * ew));
	end
	return tmp
end
function tmp_2 = code(eh, ew, t)
	tmp = 0.0;
	if (ew <= 8.5e-109)
		tmp = abs((-eh * (tanh(asinh(-((eh / ew) * tan(t)))) * sin(t))));
	else
		tmp = abs((cos(t) * ew));
	end
	tmp_2 = tmp;
end
code[eh_, ew_, t_] := If[LessEqual[ew, 8.5e-109], N[Abs[N[((-eh) * N[(N[Tanh[N[ArcSinh[(-N[(N[(eh / ew), $MachinePrecision] * N[Tan[t], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]], $MachinePrecision] * N[Sin[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ew \leq 8.5 \cdot 10^{-109}:\\
\;\;\;\;\left|\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\cos t \cdot ew\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ew < 8.50000000000000005e-109

    1. Initial program 99.8%

      \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    2. Taylor expanded in eh around inf

      \[\leadsto \left|\color{blue}{-1 \cdot \left(eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)\right)}\right| \]
    3. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left|\left(-1 \cdot eh\right) \cdot \color{blue}{\left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
      2. lower-*.f64N/A

        \[\leadsto \left|\left(-1 \cdot eh\right) \cdot \color{blue}{\left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
      3. mul-1-negN/A

        \[\leadsto \left|\left(\mathsf{neg}\left(eh\right)\right) \cdot \left(\color{blue}{\sin t} \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)\right| \]
      4. lift-neg.f64N/A

        \[\leadsto \left|\left(-eh\right) \cdot \left(\color{blue}{\sin t} \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)\right| \]
      5. *-commutativeN/A

        \[\leadsto \left|\left(-eh\right) \cdot \left(\sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{\sin t}\right)\right| \]
      6. lower-*.f64N/A

        \[\leadsto \left|\left(-eh\right) \cdot \left(\sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{\sin t}\right)\right| \]
    4. Applied rewrites41.2%

      \[\leadsto \left|\color{blue}{\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)}\right| \]

    if 8.50000000000000005e-109 < ew

    1. Initial program 99.8%

      \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    2. Taylor expanded in ew around inf

      \[\leadsto \left|\color{blue}{ew \cdot \left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
      2. lower-*.f64N/A

        \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
    4. Applied rewrites92.1%

      \[\leadsto \left|\color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}}, \cos t, \frac{\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)}{ew}\right) \cdot ew}\right| \]
    5. Taylor expanded in eh around 0

      \[\leadsto \left|\cos t \cdot ew\right| \]
    6. Step-by-step derivation
      1. lift-cos.f6462.0

        \[\leadsto \left|\cos t \cdot ew\right| \]
    7. Applied rewrites62.0%

      \[\leadsto \left|\cos t \cdot ew\right| \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 62.0% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(-eh\right) \cdot t\\ \mathbf{if}\;t \leq 6.2 \cdot 10^{-9}:\\ \;\;\;\;\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{t\_1 \cdot t\_1}{ew \cdot ew}}} - \left(eh \cdot t\right) \cdot \tanh \sinh^{-1} \left(\frac{t\_1}{ew}\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\cos t \cdot ew\right|\\ \end{array} \end{array} \]
(FPCore (eh ew t)
 :precision binary64
 (let* ((t_1 (* (- eh) t)))
   (if (<= t 6.2e-9)
     (fabs
      (-
       (* (* ew (cos t)) (/ 1.0 (sqrt (+ 1.0 (/ (* t_1 t_1) (* ew ew))))))
       (* (* eh t) (tanh (asinh (/ t_1 ew))))))
     (fabs (* (cos t) ew)))))
double code(double eh, double ew, double t) {
	double t_1 = -eh * t;
	double tmp;
	if (t <= 6.2e-9) {
		tmp = fabs((((ew * cos(t)) * (1.0 / sqrt((1.0 + ((t_1 * t_1) / (ew * ew)))))) - ((eh * t) * tanh(asinh((t_1 / ew))))));
	} else {
		tmp = fabs((cos(t) * ew));
	}
	return tmp;
}
def code(eh, ew, t):
	t_1 = -eh * t
	tmp = 0
	if t <= 6.2e-9:
		tmp = math.fabs((((ew * math.cos(t)) * (1.0 / math.sqrt((1.0 + ((t_1 * t_1) / (ew * ew)))))) - ((eh * t) * math.tanh(math.asinh((t_1 / ew))))))
	else:
		tmp = math.fabs((math.cos(t) * ew))
	return tmp
function code(eh, ew, t)
	t_1 = Float64(Float64(-eh) * t)
	tmp = 0.0
	if (t <= 6.2e-9)
		tmp = abs(Float64(Float64(Float64(ew * cos(t)) * Float64(1.0 / sqrt(Float64(1.0 + Float64(Float64(t_1 * t_1) / Float64(ew * ew)))))) - Float64(Float64(eh * t) * tanh(asinh(Float64(t_1 / ew))))));
	else
		tmp = abs(Float64(cos(t) * ew));
	end
	return tmp
end
function tmp_2 = code(eh, ew, t)
	t_1 = -eh * t;
	tmp = 0.0;
	if (t <= 6.2e-9)
		tmp = abs((((ew * cos(t)) * (1.0 / sqrt((1.0 + ((t_1 * t_1) / (ew * ew)))))) - ((eh * t) * tanh(asinh((t_1 / ew))))));
	else
		tmp = abs((cos(t) * ew));
	end
	tmp_2 = tmp;
end
code[eh_, ew_, t_] := Block[{t$95$1 = N[((-eh) * t), $MachinePrecision]}, If[LessEqual[t, 6.2e-9], N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(1.0 + N[(N[(t$95$1 * t$95$1), $MachinePrecision] / N[(ew * ew), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(eh * t), $MachinePrecision] * N[Tanh[N[ArcSinh[N[(t$95$1 / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(-eh\right) \cdot t\\
\mathbf{if}\;t \leq 6.2 \cdot 10^{-9}:\\
\;\;\;\;\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{t\_1 \cdot t\_1}{ew \cdot ew}}} - \left(eh \cdot t\right) \cdot \tanh \sinh^{-1} \left(\frac{t\_1}{ew}\right)\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\cos t \cdot ew\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 6.2000000000000001e-9

    1. Initial program 99.8%

      \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    2. Taylor expanded in t around 0

      \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    3. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
      2. lower-*.f64N/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
      3. mul-1-negN/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
      4. lift-neg.f6490.3

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    4. Applied rewrites90.3%

      \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    5. Taylor expanded in t around 0

      \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right)\right| \]
    6. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
      2. lower-*.f64N/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
      3. mul-1-negN/A

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right)\right| \]
      4. lift-neg.f6490.3

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right)\right| \]
    7. Applied rewrites90.3%

      \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right)\right| \]
    8. Step-by-step derivation
      1. Applied rewrites62.0%

        \[\leadsto \left|\color{blue}{\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \sin t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}}\right| \]
      2. Taylor expanded in t around 0

        \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \color{blue}{t}\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
      3. Step-by-step derivation
        1. Applied rewrites59.4%

          \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \color{blue}{t}\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
        2. Step-by-step derivation
          1. Applied rewrites58.4%

            \[\leadsto \color{blue}{\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(\left(-eh\right) \cdot t\right) \cdot \left(\left(-eh\right) \cdot t\right)}{ew \cdot ew}}} - \left(eh \cdot t\right) \cdot \tanh \sinh^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right)\right|} \]

          if 6.2000000000000001e-9 < t

          1. Initial program 99.8%

            \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
          2. Taylor expanded in ew around inf

            \[\leadsto \left|\color{blue}{ew \cdot \left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
          3. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
            2. lower-*.f64N/A

              \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
          4. Applied rewrites92.1%

            \[\leadsto \left|\color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}}, \cos t, \frac{\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)}{ew}\right) \cdot ew}\right| \]
          5. Taylor expanded in eh around 0

            \[\leadsto \left|\cos t \cdot ew\right| \]
          6. Step-by-step derivation
            1. lift-cos.f6462.0

              \[\leadsto \left|\cos t \cdot ew\right| \]
          7. Applied rewrites62.0%

            \[\leadsto \left|\cos t \cdot ew\right| \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 5: 58.5% accurate, 2.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\left(-eh\right) \cdot t}{ew}\\ t_2 := \sqrt{1 + t\_1 \cdot t\_1}\\ \mathbf{if}\;t \leq 0.027:\\ \;\;\;\;\left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(0.041666666666666664 \cdot \left(t \cdot t\right) - 0.5\right)\right)\right) \cdot \frac{1}{t\_2} - \left(eh \cdot t\right) \cdot \frac{t\_1}{t\_2}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\cos t \cdot ew\right|\\ \end{array} \end{array} \]
        (FPCore (eh ew t)
         :precision binary64
         (let* ((t_1 (/ (* (- eh) t) ew)) (t_2 (sqrt (+ 1.0 (* t_1 t_1)))))
           (if (<= t 0.027)
             (fabs
              (-
               (*
                (* ew (+ 1.0 (* (* t t) (- (* 0.041666666666666664 (* t t)) 0.5))))
                (/ 1.0 t_2))
               (* (* eh t) (/ t_1 t_2))))
             (fabs (* (cos t) ew)))))
        double code(double eh, double ew, double t) {
        	double t_1 = (-eh * t) / ew;
        	double t_2 = sqrt((1.0 + (t_1 * t_1)));
        	double tmp;
        	if (t <= 0.027) {
        		tmp = fabs((((ew * (1.0 + ((t * t) * ((0.041666666666666664 * (t * t)) - 0.5)))) * (1.0 / t_2)) - ((eh * t) * (t_1 / t_2))));
        	} else {
        		tmp = fabs((cos(t) * ew));
        	}
        	return tmp;
        }
        
        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
            real(8) :: tmp
            t_1 = (-eh * t) / ew
            t_2 = sqrt((1.0d0 + (t_1 * t_1)))
            if (t <= 0.027d0) then
                tmp = abs((((ew * (1.0d0 + ((t * t) * ((0.041666666666666664d0 * (t * t)) - 0.5d0)))) * (1.0d0 / t_2)) - ((eh * t) * (t_1 / t_2))))
            else
                tmp = abs((cos(t) * ew))
            end if
            code = tmp
        end function
        
        public static double code(double eh, double ew, double t) {
        	double t_1 = (-eh * t) / ew;
        	double t_2 = Math.sqrt((1.0 + (t_1 * t_1)));
        	double tmp;
        	if (t <= 0.027) {
        		tmp = Math.abs((((ew * (1.0 + ((t * t) * ((0.041666666666666664 * (t * t)) - 0.5)))) * (1.0 / t_2)) - ((eh * t) * (t_1 / t_2))));
        	} else {
        		tmp = Math.abs((Math.cos(t) * ew));
        	}
        	return tmp;
        }
        
        def code(eh, ew, t):
        	t_1 = (-eh * t) / ew
        	t_2 = math.sqrt((1.0 + (t_1 * t_1)))
        	tmp = 0
        	if t <= 0.027:
        		tmp = math.fabs((((ew * (1.0 + ((t * t) * ((0.041666666666666664 * (t * t)) - 0.5)))) * (1.0 / t_2)) - ((eh * t) * (t_1 / t_2))))
        	else:
        		tmp = math.fabs((math.cos(t) * ew))
        	return tmp
        
        function code(eh, ew, t)
        	t_1 = Float64(Float64(Float64(-eh) * t) / ew)
        	t_2 = sqrt(Float64(1.0 + Float64(t_1 * t_1)))
        	tmp = 0.0
        	if (t <= 0.027)
        		tmp = abs(Float64(Float64(Float64(ew * Float64(1.0 + Float64(Float64(t * t) * Float64(Float64(0.041666666666666664 * Float64(t * t)) - 0.5)))) * Float64(1.0 / t_2)) - Float64(Float64(eh * t) * Float64(t_1 / t_2))));
        	else
        		tmp = abs(Float64(cos(t) * ew));
        	end
        	return tmp
        end
        
        function tmp_2 = code(eh, ew, t)
        	t_1 = (-eh * t) / ew;
        	t_2 = sqrt((1.0 + (t_1 * t_1)));
        	tmp = 0.0;
        	if (t <= 0.027)
        		tmp = abs((((ew * (1.0 + ((t * t) * ((0.041666666666666664 * (t * t)) - 0.5)))) * (1.0 / t_2)) - ((eh * t) * (t_1 / t_2))));
        	else
        		tmp = abs((cos(t) * ew));
        	end
        	tmp_2 = tmp;
        end
        
        code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[((-eh) * t), $MachinePrecision] / ew), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t, 0.027], N[Abs[N[(N[(N[(ew * N[(1.0 + N[(N[(t * t), $MachinePrecision] * N[(N[(0.041666666666666664 * N[(t * t), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / t$95$2), $MachinePrecision]), $MachinePrecision] - N[(N[(eh * t), $MachinePrecision] * N[(t$95$1 / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[Cos[t], $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \frac{\left(-eh\right) \cdot t}{ew}\\
        t_2 := \sqrt{1 + t\_1 \cdot t\_1}\\
        \mathbf{if}\;t \leq 0.027:\\
        \;\;\;\;\left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(0.041666666666666664 \cdot \left(t \cdot t\right) - 0.5\right)\right)\right) \cdot \frac{1}{t\_2} - \left(eh \cdot t\right) \cdot \frac{t\_1}{t\_2}\right|\\
        
        \mathbf{else}:\\
        \;\;\;\;\left|\cos t \cdot ew\right|\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if t < 0.0269999999999999997

          1. Initial program 99.8%

            \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
          2. Taylor expanded in t around 0

            \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
          3. Step-by-step derivation
            1. associate-*r*N/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
            2. lower-*.f64N/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
            3. mul-1-negN/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
            4. lift-neg.f6490.3

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
          4. Applied rewrites90.3%

            \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
          5. Taylor expanded in t around 0

            \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right)\right| \]
          6. Step-by-step derivation
            1. associate-*r*N/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
            2. lower-*.f64N/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
            3. mul-1-negN/A

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right)\right| \]
            4. lift-neg.f6490.3

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right)\right| \]
          7. Applied rewrites90.3%

            \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right)\right| \]
          8. Step-by-step derivation
            1. Applied rewrites62.0%

              \[\leadsto \left|\color{blue}{\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \sin t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}}\right| \]
            2. Taylor expanded in t around 0

              \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \color{blue}{t}\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
            3. Step-by-step derivation
              1. Applied rewrites59.4%

                \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \color{blue}{t}\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
              2. Taylor expanded in t around 0

                \[\leadsto \left|\left(ew \cdot \color{blue}{\left(1 + {t}^{2} \cdot \left(\frac{1}{24} \cdot {t}^{2} - \frac{1}{2}\right)\right)}\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
              3. Step-by-step derivation
                1. lower-+.f64N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \color{blue}{{t}^{2} \cdot \left(\frac{1}{24} \cdot {t}^{2} - \frac{1}{2}\right)}\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                2. lower-*.f64N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + {t}^{2} \cdot \color{blue}{\left(\frac{1}{24} \cdot {t}^{2} - \frac{1}{2}\right)}\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                3. pow2N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(\color{blue}{\frac{1}{24} \cdot {t}^{2}} - \frac{1}{2}\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                4. lift-*.f64N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(\color{blue}{\frac{1}{24} \cdot {t}^{2}} - \frac{1}{2}\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                5. lower--.f64N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(\frac{1}{24} \cdot {t}^{2} - \color{blue}{\frac{1}{2}}\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                6. lower-*.f64N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(\frac{1}{24} \cdot {t}^{2} - \frac{1}{2}\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                7. pow2N/A

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(\frac{1}{24} \cdot \left(t \cdot t\right) - \frac{1}{2}\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
                8. lift-*.f6445.4

                  \[\leadsto \left|\left(ew \cdot \left(1 + \left(t \cdot t\right) \cdot \left(0.041666666666666664 \cdot \left(t \cdot t\right) - 0.5\right)\right)\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]
              4. Applied rewrites45.4%

                \[\leadsto \left|\left(ew \cdot \color{blue}{\left(1 + \left(t \cdot t\right) \cdot \left(0.041666666666666664 \cdot \left(t \cdot t\right) - 0.5\right)\right)}\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}\right| \]

              if 0.0269999999999999997 < t

              1. Initial program 99.8%

                \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
              2. Taylor expanded in ew around inf

                \[\leadsto \left|\color{blue}{ew \cdot \left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
              3. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
                2. lower-*.f64N/A

                  \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
              4. Applied rewrites92.1%

                \[\leadsto \left|\color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}}, \cos t, \frac{\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)}{ew}\right) \cdot ew}\right| \]
              5. Taylor expanded in eh around 0

                \[\leadsto \left|\cos t \cdot ew\right| \]
              6. Step-by-step derivation
                1. lift-cos.f6462.0

                  \[\leadsto \left|\cos t \cdot ew\right| \]
              7. Applied rewrites62.0%

                \[\leadsto \left|\cos t \cdot ew\right| \]
            4. Recombined 2 regimes into one program.
            5. Add Preprocessing

            Alternative 6: 57.6% accurate, 6.7× speedup?

            \[\begin{array}{l} \\ \left|\cos t \cdot ew\right| \end{array} \]
            (FPCore (eh ew t) :precision binary64 (fabs (* (cos t) ew)))
            double code(double eh, double ew, double t) {
            	return fabs((cos(t) * 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
                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}
            
            Derivation
            1. Initial program 99.8%

              \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
            2. Taylor expanded in ew around inf

              \[\leadsto \left|\color{blue}{ew \cdot \left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}\right| \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
              2. lower-*.f64N/A

                \[\leadsto \left|\left(-1 \cdot \frac{eh \cdot \left(\sin t \cdot \sin \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right)}{ew} + \cos t \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)\right) \cdot \color{blue}{ew}\right| \]
            4. Applied rewrites92.1%

              \[\leadsto \left|\color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}}, \cos t, \frac{\left(-eh\right) \cdot \left(\tanh \sinh^{-1} \left(-\frac{eh}{ew} \cdot \tan t\right) \cdot \sin t\right)}{ew}\right) \cdot ew}\right| \]
            5. Taylor expanded in eh around 0

              \[\leadsto \left|\cos t \cdot ew\right| \]
            6. Step-by-step derivation
              1. lift-cos.f6462.0

                \[\leadsto \left|\cos t \cdot ew\right| \]
            7. Applied rewrites62.0%

              \[\leadsto \left|\cos t \cdot ew\right| \]
            8. Add Preprocessing

            Alternative 7: 42.6% accurate, 12.3× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ew \leq 1.5 \cdot 10^{-165}:\\ \;\;\;\;\left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{eh \cdot eh}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|ew\right|\\ \end{array} \end{array} \]
            (FPCore (eh ew t)
             :precision binary64
             (if (<= ew 1.5e-165) (fabs (/ (* (* eh eh) t) (sqrt (* eh eh)))) (fabs ew)))
            double code(double eh, double ew, double t) {
            	double tmp;
            	if (ew <= 1.5e-165) {
            		tmp = fabs((((eh * eh) * t) / sqrt((eh * eh))));
            	} else {
            		tmp = fabs(ew);
            	}
            	return tmp;
            }
            
            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) :: tmp
                if (ew <= 1.5d-165) then
                    tmp = abs((((eh * eh) * t) / sqrt((eh * eh))))
                else
                    tmp = abs(ew)
                end if
                code = tmp
            end function
            
            public static double code(double eh, double ew, double t) {
            	double tmp;
            	if (ew <= 1.5e-165) {
            		tmp = Math.abs((((eh * eh) * t) / Math.sqrt((eh * eh))));
            	} else {
            		tmp = Math.abs(ew);
            	}
            	return tmp;
            }
            
            def code(eh, ew, t):
            	tmp = 0
            	if ew <= 1.5e-165:
            		tmp = math.fabs((((eh * eh) * t) / math.sqrt((eh * eh))))
            	else:
            		tmp = math.fabs(ew)
            	return tmp
            
            function code(eh, ew, t)
            	tmp = 0.0
            	if (ew <= 1.5e-165)
            		tmp = abs(Float64(Float64(Float64(eh * eh) * t) / sqrt(Float64(eh * eh))));
            	else
            		tmp = abs(ew);
            	end
            	return tmp
            end
            
            function tmp_2 = code(eh, ew, t)
            	tmp = 0.0;
            	if (ew <= 1.5e-165)
            		tmp = abs((((eh * eh) * t) / sqrt((eh * eh))));
            	else
            		tmp = abs(ew);
            	end
            	tmp_2 = tmp;
            end
            
            code[eh_, ew_, t_] := If[LessEqual[ew, 1.5e-165], N[Abs[N[(N[(N[(eh * eh), $MachinePrecision] * t), $MachinePrecision] / N[Sqrt[N[(eh * eh), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[ew], $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;ew \leq 1.5 \cdot 10^{-165}:\\
            \;\;\;\;\left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{eh \cdot eh}}\right|\\
            
            \mathbf{else}:\\
            \;\;\;\;\left|ew\right|\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if ew < 1.49999999999999989e-165

              1. Initial program 99.8%

                \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
              2. Taylor expanded in t around 0

                \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
              3. Step-by-step derivation
                1. associate-*r*N/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
                2. lower-*.f64N/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
                3. mul-1-negN/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
                4. lift-neg.f6490.3

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
              4. Applied rewrites90.3%

                \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
              5. Taylor expanded in t around 0

                \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{-1 \cdot \left(eh \cdot t\right)}}{ew}\right)\right| \]
              6. Step-by-step derivation
                1. associate-*r*N/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
                2. lower-*.f64N/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-1 \cdot eh\right) \cdot \color{blue}{t}}{ew}\right)\right| \]
                3. mul-1-negN/A

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(\mathsf{neg}\left(eh\right)\right) \cdot t}{ew}\right)\right| \]
                4. lift-neg.f6490.3

                  \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right)\right| \]
              7. Applied rewrites90.3%

                \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\color{blue}{\left(-eh\right) \cdot t}}{ew}\right)\right| \]
              8. Step-by-step derivation
                1. Applied rewrites62.0%

                  \[\leadsto \left|\color{blue}{\left(ew \cdot \cos t\right) \cdot \frac{1}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}} - \left(eh \cdot \sin t\right) \cdot \frac{\frac{\left(-eh\right) \cdot t}{ew}}{\sqrt{1 + \frac{\left(-eh\right) \cdot t}{ew} \cdot \frac{\left(-eh\right) \cdot t}{ew}}}}\right| \]
                2. Taylor expanded in ew around 0

                  \[\leadsto \left|\color{blue}{\frac{{eh}^{2} \cdot {\sin t}^{2}}{\cos t \cdot \sqrt{\frac{{eh}^{2} \cdot {\sin t}^{2}}{{\cos t}^{2}}}}}\right| \]
                3. Step-by-step derivation
                  1. cos-atan-revN/A

                    \[\leadsto \left|\frac{{eh}^{\color{blue}{2}} \cdot {\sin t}^{2}}{\cos t \cdot \sqrt{\frac{{eh}^{2} \cdot {\sin t}^{2}}{{\cos t}^{2}}}}\right| \]
                  2. sin-atan-revN/A

                    \[\leadsto \left|\frac{{eh}^{2} \cdot {\sin t}^{\color{blue}{2}}}{\cos t \cdot \sqrt{\frac{{eh}^{2} \cdot {\sin t}^{2}}{{\cos t}^{2}}}}\right| \]
                4. Applied rewrites24.5%

                  \[\leadsto \left|\color{blue}{\frac{{\left(eh \cdot \sin t\right)}^{2}}{\cos t \cdot \sqrt{\frac{{\left(eh \cdot \sin t\right)}^{2}}{{\cos t}^{2}}}}}\right| \]
                5. Taylor expanded in t around 0

                  \[\leadsto \left|\frac{{eh}^{2} \cdot t}{\color{blue}{\sqrt{{eh}^{2}}}}\right| \]
                6. Step-by-step derivation
                  1. lower-/.f64N/A

                    \[\leadsto \left|\frac{{eh}^{2} \cdot t}{\sqrt{{eh}^{2}}}\right| \]
                  2. lower-*.f64N/A

                    \[\leadsto \left|\frac{{eh}^{2} \cdot t}{\sqrt{{eh}^{2}}}\right| \]
                  3. unpow2N/A

                    \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{{eh}^{2}}}\right| \]
                  4. lower-*.f64N/A

                    \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{{eh}^{2}}}\right| \]
                  5. lower-sqrt.f64N/A

                    \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{{eh}^{2}}}\right| \]
                  6. unpow2N/A

                    \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{eh \cdot eh}}\right| \]
                  7. lower-*.f648.7

                    \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\sqrt{eh \cdot eh}}\right| \]
                7. Applied rewrites8.7%

                  \[\leadsto \left|\frac{\left(eh \cdot eh\right) \cdot t}{\color{blue}{\sqrt{eh \cdot eh}}}\right| \]

                if 1.49999999999999989e-165 < ew

                1. Initial program 99.8%

                  \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
                2. Taylor expanded in t around 0

                  \[\leadsto \left|\color{blue}{ew \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)}\right| \]
                3. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \left|\cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{ew}\right| \]
                  2. lower-*.f64N/A

                    \[\leadsto \left|\cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{ew}\right| \]
                4. Applied rewrites42.1%

                  \[\leadsto \left|\color{blue}{\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}} \cdot ew}\right| \]
                5. Taylor expanded in eh around 0

                  \[\leadsto \left|ew\right| \]
                6. Step-by-step derivation
                  1. Applied rewrites42.6%

                    \[\leadsto \left|ew\right| \]
                7. Recombined 2 regimes into one program.
                8. Add Preprocessing

                Alternative 8: 24.9% accurate, 112.6× speedup?

                \[\begin{array}{l} \\ \left|ew\right| \end{array} \]
                (FPCore (eh ew t) :precision binary64 (fabs ew))
                double code(double eh, double ew, double t) {
                	return fabs(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
                    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}
                
                Derivation
                1. Initial program 99.8%

                  \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
                2. Taylor expanded in t around 0

                  \[\leadsto \left|\color{blue}{ew \cdot \cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right)}\right| \]
                3. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \left|\cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{ew}\right| \]
                  2. lower-*.f64N/A

                    \[\leadsto \left|\cos \tan^{-1} \left(-1 \cdot \frac{eh \cdot \sin t}{ew \cdot \cos t}\right) \cdot \color{blue}{ew}\right| \]
                4. Applied rewrites42.1%

                  \[\leadsto \left|\color{blue}{\frac{1}{\sqrt{1 + {\left(-\frac{eh}{ew} \cdot \tan t\right)}^{2}}} \cdot ew}\right| \]
                5. Taylor expanded in eh around 0

                  \[\leadsto \left|ew\right| \]
                6. Step-by-step derivation
                  1. Applied rewrites42.6%

                    \[\leadsto \left|ew\right| \]
                  2. Add Preprocessing

                  Reproduce

                  ?
                  herbie shell --seed 2025140 
                  (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)))))))