Linear.Quaternion:$ctan from linear-1.19.1.3

Percentage Accurate: 84.6% → 95.4%
Time: 5.1s
Alternatives: 13
Speedup: 0.8×

Specification

?
\[\begin{array}{l} \\ \frac{\cosh x \cdot \frac{y}{x}}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
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(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (cosh(x) * (y / x)) / z
end function
public static double code(double x, double y, double z) {
	return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function tmp = code(x, y, z)
	tmp = (cosh(x) * (y / x)) / z;
end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\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 13 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: 84.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\cosh x \cdot \frac{y}{x}}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
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(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (cosh(x) * (y / x)) / z
end function
public static double code(double x, double y, double z) {
	return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function tmp = code(x, y, z)
	tmp = (cosh(x) * (y / x)) / z;
end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\end{array}

Alternative 1: 95.4% accurate, 0.8× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 1.26 \cdot 10^{+141}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y\_m}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y\_m}{z \cdot x} \cdot \cosh x\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= y_m 1.26e+141)
    (/ (/ (* (cosh x) y_m) x) z)
    (* (/ y_m (* z x)) (cosh x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 1.26e+141) {
		tmp = ((cosh(x) * y_m) / x) / z;
	} else {
		tmp = (y_m / (z * x)) * cosh(x);
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 1.26d+141) then
        tmp = ((cosh(x) * y_m) / x) / z
    else
        tmp = (y_m / (z * x)) * cosh(x)
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 1.26e+141) {
		tmp = ((Math.cosh(x) * y_m) / x) / z;
	} else {
		tmp = (y_m / (z * x)) * Math.cosh(x);
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if y_m <= 1.26e+141:
		tmp = ((math.cosh(x) * y_m) / x) / z
	else:
		tmp = (y_m / (z * x)) * math.cosh(x)
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 1.26e+141)
		tmp = Float64(Float64(Float64(cosh(x) * y_m) / x) / z);
	else
		tmp = Float64(Float64(y_m / Float64(z * x)) * cosh(x));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (y_m <= 1.26e+141)
		tmp = ((cosh(x) * y_m) / x) / z;
	else
		tmp = (y_m / (z * x)) * cosh(x);
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 1.26e+141], N[(N[(N[(N[Cosh[x], $MachinePrecision] * y$95$m), $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision], N[(N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.26 \cdot 10^{+141}:\\
\;\;\;\;\frac{\frac{\cosh x \cdot y\_m}{x}}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{y\_m}{z \cdot x} \cdot \cosh x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.25999999999999994e141

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x \cdot \frac{y}{x}}}{z} \]
      2. lift-cosh.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x} \cdot \frac{y}{x}}{z} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\cosh x \cdot \color{blue}{\frac{y}{x}}}{z} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z} \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{\cosh x \cdot y}}{x}}{z} \]
      7. lift-cosh.f6496.0

        \[\leadsto \frac{\frac{\color{blue}{\cosh x} \cdot y}{x}}{z} \]
    3. Applied rewrites96.0%

      \[\leadsto \color{blue}{\frac{\frac{\cosh x \cdot y}{x}}{z}} \]

    if 1.25999999999999994e141 < y

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\cosh x \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x \cdot \frac{y}{x}}}{z} \]
      3. lift-cosh.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x} \cdot \frac{y}{x}}{z} \]
      4. associate-/l*N/A

        \[\leadsto \color{blue}{\cosh x \cdot \frac{\frac{y}{x}}{z}} \]
      5. lift-/.f64N/A

        \[\leadsto \cosh x \cdot \frac{\color{blue}{\frac{y}{x}}}{z} \]
      6. associate-/r*N/A

        \[\leadsto \cosh x \cdot \color{blue}{\frac{y}{x \cdot z}} \]
      7. *-commutativeN/A

        \[\leadsto \cosh x \cdot \frac{y}{\color{blue}{z \cdot x}} \]
      8. associate-/l/N/A

        \[\leadsto \cosh x \cdot \color{blue}{\frac{\frac{y}{z}}{x}} \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \cosh x} \]
      10. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \cosh x} \]
      11. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \cosh x \]
      12. *-commutativeN/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \cdot \cosh x \]
      13. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \cdot \cosh x \]
      14. *-commutativeN/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \cosh x \]
      15. lower-*.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \cosh x \]
      16. lift-cosh.f6478.5

        \[\leadsto \frac{y}{z \cdot x} \cdot \color{blue}{\cosh x} \]
    3. Applied rewrites78.5%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} \cdot \cosh x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 94.3% accurate, 0.7× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.25 \cdot 10^{-196}:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+135}:\\ \;\;\;\;\frac{\cosh x \cdot y\_m}{z \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= x 1.25e-196)
    (/ (/ y_m z) x)
    (if (<= x 7e+135)
      (/ (* (cosh x) y_m) (* z x))
      (/ (/ (* (* (* x x) y_m) 0.5) z) x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.25e-196) {
		tmp = (y_m / z) / x;
	} else if (x <= 7e+135) {
		tmp = (cosh(x) * y_m) / (z * x);
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.25d-196) then
        tmp = (y_m / z) / x
    else if (x <= 7d+135) then
        tmp = (cosh(x) * y_m) / (z * x)
    else
        tmp = ((((x * x) * y_m) * 0.5d0) / z) / x
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.25e-196) {
		tmp = (y_m / z) / x;
	} else if (x <= 7e+135) {
		tmp = (Math.cosh(x) * y_m) / (z * x);
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.25e-196:
		tmp = (y_m / z) / x
	elif x <= 7e+135:
		tmp = (math.cosh(x) * y_m) / (z * x)
	else:
		tmp = ((((x * x) * y_m) * 0.5) / z) / x
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.25e-196)
		tmp = Float64(Float64(y_m / z) / x);
	elseif (x <= 7e+135)
		tmp = Float64(Float64(cosh(x) * y_m) / Float64(z * x));
	else
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) * y_m) * 0.5) / z) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.25e-196)
		tmp = (y_m / z) / x;
	elseif (x <= 7e+135)
		tmp = (cosh(x) * y_m) / (z * x);
	else
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.25e-196], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 7e+135], N[(N[(N[Cosh[x], $MachinePrecision] * y$95$m), $MachinePrecision] / N[(z * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] * 0.5), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.25 \cdot 10^{-196}:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{elif}\;x \leq 7 \cdot 10^{+135}:\\
\;\;\;\;\frac{\cosh x \cdot y\_m}{z \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 1.2500000000000001e-196

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.2500000000000001e-196 < x < 7.0000000000000005e135

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\cosh x \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x \cdot \frac{y}{x}}}{z} \]
      3. lift-cosh.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x} \cdot \frac{y}{x}}{z} \]
      4. lift-/.f64N/A

        \[\leadsto \frac{\cosh x \cdot \color{blue}{\frac{y}{x}}}{z} \]
      5. associate-*r/N/A

        \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z} \]
      6. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{\cosh x \cdot y}{x \cdot z}} \]
      7. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\cosh x \cdot y}{x \cdot z}} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x \cdot y}}{x \cdot z} \]
      9. lift-cosh.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x} \cdot y}{x \cdot z} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\cosh x \cdot y}{\color{blue}{z \cdot x}} \]
      11. lower-*.f6483.9

        \[\leadsto \frac{\cosh x \cdot y}{\color{blue}{z \cdot x}} \]
    3. Applied rewrites83.9%

      \[\leadsto \color{blue}{\frac{\cosh x \cdot y}{z \cdot x}} \]

    if 7.0000000000000005e135 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      3. pow2N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      5. lift-*.f6440.4

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
    7. Applied rewrites40.4%

      \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 78.3% accurate, 0.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \frac{\cosh x \cdot \frac{y\_m}{x}}{z}\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq \infty:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y\_m}{x}\\ \end{array} \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (/ (* (cosh x) (/ y_m x)) z)))
   (* y_s (if (<= t_0 INFINITY) t_0 (/ (* (* (/ (* x x) z) 0.5) y_m) x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double t_0 = (cosh(x) * (y_m / x)) / z;
	double tmp;
	if (t_0 <= ((double) INFINITY)) {
		tmp = t_0;
	} else {
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	}
	return y_s * tmp;
}
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double t_0 = (Math.cosh(x) * (y_m / x)) / z;
	double tmp;
	if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = t_0;
	} else {
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	t_0 = (math.cosh(x) * (y_m / x)) / z
	tmp = 0
	if t_0 <= math.inf:
		tmp = t_0
	else:
		tmp = ((((x * x) / z) * 0.5) * y_m) / x
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	t_0 = Float64(Float64(cosh(x) * Float64(y_m / x)) / z)
	tmp = 0.0
	if (t_0 <= Inf)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) / z) * 0.5) * y_m) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	t_0 = (cosh(x) * (y_m / x)) / z;
	tmp = 0.0;
	if (t_0 <= Inf)
		tmp = t_0;
	else
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := Block[{t$95$0 = N[(N[(N[Cosh[x], $MachinePrecision] * N[(y$95$m / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, N[(y$95$s * If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[(N[(N[(N[(x * x), $MachinePrecision] / z), $MachinePrecision] * 0.5), $MachinePrecision] * y$95$m), $MachinePrecision] / x), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
\begin{array}{l}
t_0 := \frac{\cosh x \cdot \frac{y\_m}{x}}{z}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y\_m}{x}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < +inf.0

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]

    if +inf.0 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      2. lift-fma.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left(\left(x \cdot x\right) \cdot y\right) + y}{z}}{x} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2}\right) \cdot y + y}{z}}{x} \]
      8. distribute-lft1-inN/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2} + 1\right) \cdot y}{z}}{x} \]
      9. +-commutativeN/A

        \[\leadsto \frac{\frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot y}{z}}{x} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\frac{y \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{z}}{x} \]
      11. associate-/l*N/A

        \[\leadsto \frac{y \cdot \frac{1 + \frac{1}{2} \cdot {x}^{2}}{z}}{x} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
    6. Applied rewrites81.1%

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)}{z} \cdot y}{x} \]
    7. Taylor expanded in x around inf

      \[\leadsto \frac{\left(\frac{1}{2} \cdot \frac{{x}^{2}}{z}\right) \cdot y}{x} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      3. lower-/.f64N/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      4. pow2N/A

        \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      5. lift-*.f6440.5

        \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y}{x} \]
    9. Applied rewrites40.5%

      \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 78.1% accurate, 0.7× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.25 \cdot 10^{-196}:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{+127}:\\ \;\;\;\;\frac{y\_m}{z \cdot x} \cdot \cosh x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= x 1.25e-196)
    (/ (/ y_m z) x)
    (if (<= x 7.5e+127)
      (* (/ y_m (* z x)) (cosh x))
      (/ (/ (* (* (* x x) y_m) 0.5) z) x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.25e-196) {
		tmp = (y_m / z) / x;
	} else if (x <= 7.5e+127) {
		tmp = (y_m / (z * x)) * cosh(x);
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.25d-196) then
        tmp = (y_m / z) / x
    else if (x <= 7.5d+127) then
        tmp = (y_m / (z * x)) * cosh(x)
    else
        tmp = ((((x * x) * y_m) * 0.5d0) / z) / x
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.25e-196) {
		tmp = (y_m / z) / x;
	} else if (x <= 7.5e+127) {
		tmp = (y_m / (z * x)) * Math.cosh(x);
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.25e-196:
		tmp = (y_m / z) / x
	elif x <= 7.5e+127:
		tmp = (y_m / (z * x)) * math.cosh(x)
	else:
		tmp = ((((x * x) * y_m) * 0.5) / z) / x
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.25e-196)
		tmp = Float64(Float64(y_m / z) / x);
	elseif (x <= 7.5e+127)
		tmp = Float64(Float64(y_m / Float64(z * x)) * cosh(x));
	else
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) * y_m) * 0.5) / z) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.25e-196)
		tmp = (y_m / z) / x;
	elseif (x <= 7.5e+127)
		tmp = (y_m / (z * x)) * cosh(x);
	else
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.25e-196], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 7.5e+127], N[(N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] * 0.5), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.25 \cdot 10^{-196}:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{elif}\;x \leq 7.5 \cdot 10^{+127}:\\
\;\;\;\;\frac{y\_m}{z \cdot x} \cdot \cosh x\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 1.2500000000000001e-196

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.2500000000000001e-196 < x < 7.4999999999999996e127

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\cosh x \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x \cdot \frac{y}{x}}}{z} \]
      3. lift-cosh.f64N/A

        \[\leadsto \frac{\color{blue}{\cosh x} \cdot \frac{y}{x}}{z} \]
      4. associate-/l*N/A

        \[\leadsto \color{blue}{\cosh x \cdot \frac{\frac{y}{x}}{z}} \]
      5. lift-/.f64N/A

        \[\leadsto \cosh x \cdot \frac{\color{blue}{\frac{y}{x}}}{z} \]
      6. associate-/r*N/A

        \[\leadsto \cosh x \cdot \color{blue}{\frac{y}{x \cdot z}} \]
      7. *-commutativeN/A

        \[\leadsto \cosh x \cdot \frac{y}{\color{blue}{z \cdot x}} \]
      8. associate-/l/N/A

        \[\leadsto \cosh x \cdot \color{blue}{\frac{\frac{y}{z}}{x}} \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \cosh x} \]
      10. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \cosh x} \]
      11. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \cosh x \]
      12. *-commutativeN/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \cdot \cosh x \]
      13. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \cdot \cosh x \]
      14. *-commutativeN/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \cosh x \]
      15. lower-*.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \cosh x \]
      16. lift-cosh.f6478.5

        \[\leadsto \frac{y}{z \cdot x} \cdot \color{blue}{\cosh x} \]
    3. Applied rewrites78.5%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} \cdot \cosh x} \]

    if 7.4999999999999996e127 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      3. pow2N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      5. lift-*.f6440.4

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
    7. Applied rewrites40.4%

      \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 72.4% accurate, 0.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{\cosh x \cdot \frac{y\_m}{x}}{z} \leq 1:\\ \;\;\;\;\frac{y\_m}{z \cdot x} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y\_m, 0.5, y\_m\right)}{z}}{x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= (/ (* (cosh x) (/ y_m x)) z) 1.0)
    (* (/ y_m (* z x)) (fma (* x x) 0.5 1.0))
    (/ (/ (fma (* (* x x) y_m) 0.5 y_m) z) x))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (((cosh(x) * (y_m / x)) / z) <= 1.0) {
		tmp = (y_m / (z * x)) * fma((x * x), 0.5, 1.0);
	} else {
		tmp = (fma(((x * x) * y_m), 0.5, y_m) / z) / x;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (Float64(Float64(cosh(x) * Float64(y_m / x)) / z) <= 1.0)
		tmp = Float64(Float64(y_m / Float64(z * x)) * fma(Float64(x * x), 0.5, 1.0));
	else
		tmp = Float64(Float64(fma(Float64(Float64(x * x) * y_m), 0.5, y_m) / z) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[N[(N[(N[Cosh[x], $MachinePrecision] * N[(y$95$m / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 1.0], N[(N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] * 0.5 + y$95$m), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cosh x \cdot \frac{y\_m}{x}}{z} \leq 1:\\
\;\;\;\;\frac{y\_m}{z \cdot x} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y\_m, 0.5, y\_m\right)}{z}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 1

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{\left(1 + \frac{1}{2} \cdot {x}^{2}\right)} \cdot \frac{y}{x}}{z} \]
    3. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot {x}^{2} + \color{blue}{1}\right) \cdot \frac{y}{x}}{z} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\left({x}^{2} \cdot \frac{1}{2} + 1\right) \cdot \frac{y}{x}}{z} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{2}, \color{blue}{\frac{1}{2}}, 1\right) \cdot \frac{y}{x}}{z} \]
      4. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}{z} \]
      5. lower-*.f6469.1

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right) \cdot \frac{y}{x}}{z} \]
    4. Applied rewrites69.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)} \cdot \frac{y}{x}}{z} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}}{z} \]
      3. associate-/l*N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{\frac{y}{x}}{z}} \]
      4. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{\color{blue}{\frac{y}{x}}}{z} \]
      5. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \color{blue}{\frac{y}{x \cdot z}} \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{\color{blue}{z \cdot x}} \]
      7. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \color{blue}{\frac{\frac{y}{z}}{x}} \]
      8. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right)} \]
      9. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right)} \]
      10. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \]
      11. lift-*.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \]
      12. lift-/.f6464.7

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right) \]
    6. Applied rewrites64.7%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right)} \]

    if 1 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 71.1% accurate, 0.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \mathsf{fma}\left(x \cdot x, 0.5, 1\right)\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{\cosh x \cdot \frac{y\_m}{x}}{z} \leq 1:\\ \;\;\;\;\frac{y\_m}{z \cdot x} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t\_0}{z} \cdot y\_m}{x}\\ \end{array} \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (fma (* x x) 0.5 1.0)))
   (*
    y_s
    (if (<= (/ (* (cosh x) (/ y_m x)) z) 1.0)
      (* (/ y_m (* z x)) t_0)
      (/ (* (/ t_0 z) y_m) x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double t_0 = fma((x * x), 0.5, 1.0);
	double tmp;
	if (((cosh(x) * (y_m / x)) / z) <= 1.0) {
		tmp = (y_m / (z * x)) * t_0;
	} else {
		tmp = ((t_0 / z) * y_m) / x;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	t_0 = fma(Float64(x * x), 0.5, 1.0)
	tmp = 0.0
	if (Float64(Float64(cosh(x) * Float64(y_m / x)) / z) <= 1.0)
		tmp = Float64(Float64(y_m / Float64(z * x)) * t_0);
	else
		tmp = Float64(Float64(Float64(t_0 / z) * y_m) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision]}, N[(y$95$s * If[LessEqual[N[(N[(N[Cosh[x], $MachinePrecision] * N[(y$95$m / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 1.0], N[(N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(N[(t$95$0 / z), $MachinePrecision] * y$95$m), $MachinePrecision] / x), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x \cdot x, 0.5, 1\right)\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cosh x \cdot \frac{y\_m}{x}}{z} \leq 1:\\
\;\;\;\;\frac{y\_m}{z \cdot x} \cdot t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{z} \cdot y\_m}{x}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 1

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{\left(1 + \frac{1}{2} \cdot {x}^{2}\right)} \cdot \frac{y}{x}}{z} \]
    3. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot {x}^{2} + \color{blue}{1}\right) \cdot \frac{y}{x}}{z} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\left({x}^{2} \cdot \frac{1}{2} + 1\right) \cdot \frac{y}{x}}{z} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{2}, \color{blue}{\frac{1}{2}}, 1\right) \cdot \frac{y}{x}}{z} \]
      4. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}{z} \]
      5. lower-*.f6469.1

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right) \cdot \frac{y}{x}}{z} \]
    4. Applied rewrites69.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)} \cdot \frac{y}{x}}{z} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}}{z} \]
      3. associate-/l*N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{\frac{y}{x}}{z}} \]
      4. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{\color{blue}{\frac{y}{x}}}{z} \]
      5. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \color{blue}{\frac{y}{x \cdot z}} \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{\color{blue}{z \cdot x}} \]
      7. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \color{blue}{\frac{\frac{y}{z}}{x}} \]
      8. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right)} \]
      9. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right)} \]
      10. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \]
      11. lift-*.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \]
      12. lift-/.f6464.7

        \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right) \]
    6. Applied rewrites64.7%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} \cdot \mathsf{fma}\left(x \cdot x, 0.5, 1\right)} \]

    if 1 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      2. lift-fma.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left(\left(x \cdot x\right) \cdot y\right) + y}{z}}{x} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2}\right) \cdot y + y}{z}}{x} \]
      8. distribute-lft1-inN/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2} + 1\right) \cdot y}{z}}{x} \]
      9. +-commutativeN/A

        \[\leadsto \frac{\frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot y}{z}}{x} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\frac{y \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{z}}{x} \]
      11. associate-/l*N/A

        \[\leadsto \frac{y \cdot \frac{1 + \frac{1}{2} \cdot {x}^{2}}{z}}{x} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
    6. Applied rewrites81.1%

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)}{z} \cdot y}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 66.4% accurate, 1.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 1.4) (/ (/ y_m z) x) (/ (/ (* (* (* x x) y_m) 0.5) z) x))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.4d0) then
        tmp = (y_m / z) / x
    else
        tmp = ((((x * x) * y_m) * 0.5d0) / z) / x
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.4:
		tmp = (y_m / z) / x
	else:
		tmp = ((((x * x) * y_m) * 0.5) / z) / x
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.4)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) * y_m) * 0.5) / z) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.4)
		tmp = (y_m / z) / x;
	else
		tmp = ((((x * x) * y_m) * 0.5) / z) / x;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.4], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * y$95$m), $MachinePrecision] * 0.5), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(\left(x \cdot x\right) \cdot y\_m\right) \cdot 0.5}{z}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3999999999999999

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.3999999999999999 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      3. pow2N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2}}{z}}{x} \]
      5. lift-*.f6440.4

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
    7. Applied rewrites40.4%

      \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot 0.5}{z}}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 66.4% accurate, 1.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y\_m}{x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 1.4) (/ (/ y_m z) x) (/ (* (* (/ (* x x) z) 0.5) y_m) x))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.4d0) then
        tmp = (y_m / z) / x
    else
        tmp = ((((x * x) / z) * 0.5d0) * y_m) / x
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.4:
		tmp = (y_m / z) / x
	else:
		tmp = ((((x * x) / z) * 0.5) * y_m) / x
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.4)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) / z) * 0.5) * y_m) / x);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.4)
		tmp = (y_m / z) / x;
	else
		tmp = ((((x * x) / z) * 0.5) * y_m) / x;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.4], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] / z), $MachinePrecision] * 0.5), $MachinePrecision] * y$95$m), $MachinePrecision] / x), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y\_m}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3999999999999999

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.3999999999999999 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      2. lift-fma.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left(\left(x \cdot x\right) \cdot y\right) + y}{z}}{x} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2}\right) \cdot y + y}{z}}{x} \]
      8. distribute-lft1-inN/A

        \[\leadsto \frac{\frac{\left(\frac{1}{2} \cdot {x}^{2} + 1\right) \cdot y}{z}}{x} \]
      9. +-commutativeN/A

        \[\leadsto \frac{\frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot y}{z}}{x} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\frac{y \cdot \left(1 + \frac{1}{2} \cdot {x}^{2}\right)}{z}}{x} \]
      11. associate-/l*N/A

        \[\leadsto \frac{y \cdot \frac{1 + \frac{1}{2} \cdot {x}^{2}}{z}}{x} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\frac{1 + \frac{1}{2} \cdot {x}^{2}}{z} \cdot y}{x} \]
    6. Applied rewrites81.1%

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)}{z} \cdot y}{x} \]
    7. Taylor expanded in x around inf

      \[\leadsto \frac{\left(\frac{1}{2} \cdot \frac{{x}^{2}}{z}\right) \cdot y}{x} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      3. lower-/.f64N/A

        \[\leadsto \frac{\left(\frac{{x}^{2}}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      4. pow2N/A

        \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot \frac{1}{2}\right) \cdot y}{x} \]
      5. lift-*.f6440.5

        \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y}{x} \]
    9. Applied rewrites40.5%

      \[\leadsto \frac{\left(\frac{x \cdot x}{z} \cdot 0.5\right) \cdot y}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 60.6% accurate, 1.1× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(x \cdot x\right) \cdot 0.5\right) \cdot y\_m}{z \cdot x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 1.4) (/ (/ y_m z) x) (/ (* (* (* x x) 0.5) y_m) (* z x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = (((x * x) * 0.5) * y_m) / (z * x);
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.4d0) then
        tmp = (y_m / z) / x
    else
        tmp = (((x * x) * 0.5d0) * y_m) / (z * x)
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = (((x * x) * 0.5) * y_m) / (z * x);
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.4:
		tmp = (y_m / z) / x
	else:
		tmp = (((x * x) * 0.5) * y_m) / (z * x)
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.4)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(Float64(Float64(Float64(x * x) * 0.5) * y_m) / Float64(z * x));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.4)
		tmp = (y_m / z) / x;
	else
		tmp = (((x * x) * 0.5) * y_m) / (z * x);
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.4], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * y$95$m), $MachinePrecision] / N[(z * x), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x \cdot x\right) \cdot 0.5\right) \cdot y\_m}{z \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3999999999999999

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.3999999999999999 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{\left(1 + \frac{1}{2} \cdot {x}^{2}\right)} \cdot \frac{y}{x}}{z} \]
    3. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot {x}^{2} + \color{blue}{1}\right) \cdot \frac{y}{x}}{z} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\left({x}^{2} \cdot \frac{1}{2} + 1\right) \cdot \frac{y}{x}}{z} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{2}, \color{blue}{\frac{1}{2}}, 1\right) \cdot \frac{y}{x}}{z} \]
      4. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, \frac{1}{2}, 1\right) \cdot \frac{y}{x}}{z} \]
      5. lower-*.f6469.1

        \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right) \cdot \frac{y}{x}}{z} \]
    4. Applied rewrites69.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)} \cdot \frac{y}{x}}{z} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{\left(\frac{1}{2} \cdot \color{blue}{{x}^{2}}\right) \cdot \frac{y}{x}}{z} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\left({x}^{2} \cdot \frac{1}{2}\right) \cdot \frac{y}{x}}{z} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\left({x}^{2} \cdot \frac{1}{2}\right) \cdot \frac{y}{x}}{z} \]
      3. pow2N/A

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot \frac{y}{x}}{z} \]
      4. lift-*.f6429.5

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot 0.5\right) \cdot \frac{y}{x}}{z} \]
    7. Applied rewrites29.5%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \color{blue}{0.5}\right) \cdot \frac{y}{x}}{z} \]
    8. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot \frac{y}{x}}{z}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot \frac{y}{x}}}{z} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot \color{blue}{\frac{y}{x}}}{z} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\color{blue}{\frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot y}{x}}}{z} \]
      5. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot y}{x \cdot z}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot y}{x \cdot z}} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot y}}{x \cdot z} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \frac{1}{2}\right) \cdot y}{\color{blue}{z \cdot x}} \]
      9. lift-*.f6429.3

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot 0.5\right) \cdot y}{\color{blue}{z \cdot x}} \]
    9. Applied rewrites29.3%

      \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot 0.5\right) \cdot y}{z \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 59.2% accurate, 1.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{0.5}{z} \cdot x\right) \cdot y\_m\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 1.4) (/ (/ y_m z) x) (* (* (/ 0.5 z) x) y_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((0.5 / z) * x) * y_m;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.4d0) then
        tmp = (y_m / z) / x
    else
        tmp = ((0.5d0 / z) * x) * y_m
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((0.5 / z) * x) * y_m;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.4:
		tmp = (y_m / z) / x
	else:
		tmp = ((0.5 / z) * x) * y_m
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.4)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(Float64(Float64(0.5 / z) * x) * y_m);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.4)
		tmp = (y_m / z) / x;
	else
		tmp = ((0.5 / z) * x) * y_m;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.4], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(0.5 / z), $MachinePrecision] * x), $MachinePrecision] * y$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{0.5}{z} \cdot x\right) \cdot y\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3999999999999999

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.3999999999999999 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Step-by-step derivation
      1. associate-/l*81.1

        \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}}{z}}{x} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{\color{blue}{x}} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      4. lift-fma.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{\frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      7. associate-/l/N/A

        \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot y\right) \cdot \frac{1}{2} + y}{\color{blue}{z \cdot x}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \left(\left(x \cdot x\right) \cdot y\right) + y}{z \cdot x} \]
      9. pow2N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z \cdot x} \]
      10. associate-*r*N/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot {x}^{2}\right) \cdot y + y}{z \cdot x} \]
      11. distribute-lft1-inN/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot {x}^{2} + 1\right) \cdot y}{\color{blue}{z} \cdot x} \]
      12. +-commutativeN/A

        \[\leadsto \frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot y}{z \cdot x} \]
      13. *-commutativeN/A

        \[\leadsto \frac{\left(1 + \frac{1}{2} \cdot {x}^{2}\right) \cdot y}{x \cdot \color{blue}{z}} \]
    6. Applied rewrites68.5%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x \cdot x, 0.5, 1\right)}{z \cdot x} \cdot y} \]
    7. Taylor expanded in x around inf

      \[\leadsto \left(\frac{1}{2} \cdot \frac{x}{z}\right) \cdot y \]
    8. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot x}{z} \cdot y \]
      2. associate-*l/N/A

        \[\leadsto \left(\frac{\frac{1}{2}}{z} \cdot x\right) \cdot y \]
      3. mult-flip-revN/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \frac{1}{z}\right) \cdot x\right) \cdot y \]
      4. lower-*.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \frac{1}{z}\right) \cdot x\right) \cdot y \]
      5. mult-flip-revN/A

        \[\leadsto \left(\frac{\frac{1}{2}}{z} \cdot x\right) \cdot y \]
      6. lower-/.f6425.9

        \[\leadsto \left(\frac{0.5}{z} \cdot x\right) \cdot y \]
    9. Applied rewrites25.9%

      \[\leadsto \left(\frac{0.5}{z} \cdot x\right) \cdot y \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 57.3% accurate, 1.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y\_m}{z} \cdot x\right) \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 1.4) (/ (/ y_m z) x) (* (* (/ y_m z) x) 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((y_m / z) * x) * 0.5;
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.4d0) then
        tmp = (y_m / z) / x
    else
        tmp = ((y_m / z) * x) * 0.5d0
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 1.4) {
		tmp = (y_m / z) / x;
	} else {
		tmp = ((y_m / z) * x) * 0.5;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 1.4:
		tmp = (y_m / z) / x
	else:
		tmp = ((y_m / z) * x) * 0.5
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 1.4)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(Float64(Float64(y_m / z) * x) * 0.5);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 1.4)
		tmp = (y_m / z) / x;
	else
		tmp = ((y_m / z) * x) * 0.5;
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[x, 1.4], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(y$95$m / z), $MachinePrecision] * x), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{y\_m}{z} \cdot x\right) \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3999999999999999

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.3999999999999999 < x

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{{x}^{2} \cdot y}{z} + \frac{y}{z}}{\color{blue}{x}} \]
      2. associate-*r/N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z} + \frac{y}{z}}{x} \]
      3. div-add-revN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\frac{y + \frac{1}{2} \cdot \left({x}^{2} \cdot y\right)}{z}}{x} \]
      6. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \left({x}^{2} \cdot y\right) + y}{z}}{x} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\frac{\left({x}^{2} \cdot y\right) \cdot \frac{1}{2} + y}{z}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{2} \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      10. unpow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \frac{1}{2}, y\right)}{z}}{x} \]
      11. lower-*.f6481.1

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x} \]
    4. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, 0.5, y\right)}{z}}{x}} \]
    5. Taylor expanded in x around inf

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{x \cdot y}{z}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{x \cdot y}{z} \cdot \frac{1}{2} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{x \cdot y}{z} \cdot \frac{1}{2} \]
      3. associate-/l*N/A

        \[\leadsto \left(x \cdot \frac{y}{z}\right) \cdot \frac{1}{2} \]
      4. *-commutativeN/A

        \[\leadsto \left(\frac{y}{z} \cdot x\right) \cdot \frac{1}{2} \]
      5. lower-*.f64N/A

        \[\leadsto \left(\frac{y}{z} \cdot x\right) \cdot \frac{1}{2} \]
      6. lower-/.f6426.0

        \[\leadsto \left(\frac{y}{z} \cdot x\right) \cdot 0.5 \]
    7. Applied rewrites26.0%

      \[\leadsto \left(\frac{y}{z} \cdot x\right) \cdot \color{blue}{0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 54.4% accurate, 1.8× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq 10^{-35}:\\ \;\;\;\;\frac{\frac{y\_m}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{y\_m}{z \cdot x}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= z 1e-35) (/ (/ y_m z) x) (/ y_m (* z x)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (z <= 1e-35) {
		tmp = (y_m / z) / x;
	} else {
		tmp = y_m / (z * x);
	}
	return y_s * tmp;
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= 1d-35) then
        tmp = (y_m / z) / x
    else
        tmp = y_m / (z * x)
    end if
    code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (z <= 1e-35) {
		tmp = (y_m / z) / x;
	} else {
		tmp = y_m / (z * x);
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if z <= 1e-35:
		tmp = (y_m / z) / x
	else:
		tmp = y_m / (z * x)
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (z <= 1e-35)
		tmp = Float64(Float64(y_m / z) / x);
	else
		tmp = Float64(y_m / Float64(z * x));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (z <= 1e-35)
		tmp = (y_m / z) / x;
	else
		tmp = y_m / (z * x);
	end
	tmp_2 = y_s * tmp;
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[z, 1e-35], N[(N[(y$95$m / z), $MachinePrecision] / x), $MachinePrecision], N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq 10^{-35}:\\
\;\;\;\;\frac{\frac{y\_m}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{y\_m}{z \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 1.00000000000000001e-35

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{z \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]
      5. lower-/.f6452.7

        \[\leadsto \frac{\frac{y}{z}}{x} \]
    6. Applied rewrites52.7%

      \[\leadsto \frac{\frac{y}{z}}{\color{blue}{x}} \]

    if 1.00000000000000001e-35 < z

    1. Initial program 84.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
      3. lower-*.f6449.1

        \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    4. Applied rewrites49.1%

      \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 49.1% accurate, 2.9× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \frac{y\_m}{z \cdot x} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z) :precision binary64 (* y_s (/ y_m (* z x))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	return y_s * (y_m / (z * x));
}
y\_m =     private
y\_s =     private
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(y_s, x, y_m, z)
use fmin_fmax_functions
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    code = y_s * (y_m / (z * x))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
	return y_s * (y_m / (z * x));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	return y_s * (y_m / (z * x))
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	return Float64(y_s * Float64(y_m / Float64(z * x)))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp = code(y_s, x, y_m, z)
	tmp = y_s * (y_m / (z * x));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * N[(y$95$m / N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \frac{y\_m}{z \cdot x}
\end{array}
Derivation
  1. Initial program 84.6%

    \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
  3. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{y}{\color{blue}{x \cdot z}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
    3. lower-*.f6449.1

      \[\leadsto \frac{y}{z \cdot \color{blue}{x}} \]
  4. Applied rewrites49.1%

    \[\leadsto \color{blue}{\frac{y}{z \cdot x}} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025132 
(FPCore (x y z)
  :name "Linear.Quaternion:$ctan from linear-1.19.1.3"
  :precision binary64
  (/ (* (cosh x) (/ y x)) z))