Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23

Percentage Accurate: 99.9% → 99.9%
Time: 2.4s
Alternatives: 7
Speedup: 1.0×

Specification

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

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Sampling outcomes in binary64 precision:

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 7 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

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

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 91.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(x \cdot y + z\right) \cdot y\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+136} \lor \neg \left(t\_1 \leq 4 \cdot 10^{+180}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (+ (* x y) z) y)))
   (if (or (<= t_1 -2e+136) (not (<= t_1 4e+180)))
     (* (fma y x z) y)
     (fma z y t))))
double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) + z) * y;
	double tmp;
	if ((t_1 <= -2e+136) || !(t_1 <= 4e+180)) {
		tmp = fma(y, x, z) * y;
	} else {
		tmp = fma(z, y, t);
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(x * y) + z) * y)
	tmp = 0.0
	if ((t_1 <= -2e+136) || !(t_1 <= 4e+180))
		tmp = Float64(fma(y, x, z) * y);
	else
		tmp = fma(z, y, t);
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+136], N[Not[LessEqual[t$95$1, 4e+180]], $MachinePrecision]], N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+136} \lor \neg \left(t\_1 \leq 4 \cdot 10^{+180}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -2.00000000000000012e136 or 4e180 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in t around 0

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

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

        \[\leadsto \left(x \cdot y + z\right) \cdot \color{blue}{y} \]
      3. lower-*.f64N/A

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

        \[\leadsto \left(y \cdot x + z\right) \cdot y \]
      5. lower-fma.f6498.0

        \[\leadsto \mathsf{fma}\left(y, x, z\right) \cdot y \]
    5. Applied rewrites98.0%

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

    if -2.00000000000000012e136 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4e180

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t + y \cdot z} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto z \cdot y + t \]
      3. lower-fma.f6489.3

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{y}, t\right) \]
    5. Applied rewrites89.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot y + z\right) \cdot y \leq -2 \cdot 10^{+136} \lor \neg \left(\left(x \cdot y + z\right) \cdot y \leq 4 \cdot 10^{+180}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(x \cdot y + z\right) \cdot y\\ \mathbf{if}\;t\_1 \leq -4 \cdot 10^{+283} \lor \neg \left(t\_1 \leq 10^{+232}\right):\\ \;\;\;\;\left(y \cdot x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (+ (* x y) z) y)))
   (if (or (<= t_1 -4e+283) (not (<= t_1 1e+232))) (* (* y x) y) (fma z y t))))
double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) + z) * y;
	double tmp;
	if ((t_1 <= -4e+283) || !(t_1 <= 1e+232)) {
		tmp = (y * x) * y;
	} else {
		tmp = fma(z, y, t);
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(x * y) + z) * y)
	tmp = 0.0
	if ((t_1 <= -4e+283) || !(t_1 <= 1e+232))
		tmp = Float64(Float64(y * x) * y);
	else
		tmp = fma(z, y, t);
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -4e+283], N[Not[LessEqual[t$95$1, 1e+232]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+283} \lor \neg \left(t\_1 \leq 10^{+232}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot y\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -3.99999999999999982e283 or 1.00000000000000006e232 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

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

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      2. lower-*.f64N/A

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      3. unpow2N/A

        \[\leadsto \left(y \cdot y\right) \cdot x \]
      4. lower-*.f6474.8

        \[\leadsto \left(y \cdot y\right) \cdot x \]
    5. Applied rewrites74.8%

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

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

        \[\leadsto \left(y \cdot y\right) \cdot x \]
      3. pow2N/A

        \[\leadsto {y}^{2} \cdot x \]
      4. *-commutativeN/A

        \[\leadsto x \cdot \color{blue}{{y}^{2}} \]
      5. pow2N/A

        \[\leadsto x \cdot \left(y \cdot \color{blue}{y}\right) \]
      6. associate-*r*N/A

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

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

        \[\leadsto \left(y \cdot x\right) \cdot y \]
      9. lower-*.f6475.6

        \[\leadsto \left(y \cdot x\right) \cdot y \]
    7. Applied rewrites75.6%

      \[\leadsto \left(y \cdot x\right) \cdot \color{blue}{y} \]

    if -3.99999999999999982e283 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.00000000000000006e232

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t + y \cdot z} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto z \cdot y + t \]
      3. lower-fma.f6484.9

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{y}, t\right) \]
    5. Applied rewrites84.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot y + z\right) \cdot y \leq -4 \cdot 10^{+283} \lor \neg \left(\left(x \cdot y + z\right) \cdot y \leq 10^{+232}\right):\\ \;\;\;\;\left(y \cdot x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 80.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(x \cdot y + z\right) \cdot y\\ \mathbf{if}\;t\_1 \leq -4 \cdot 10^{+283}:\\ \;\;\;\;\left(y \cdot x\right) \cdot y\\ \mathbf{elif}\;t\_1 \leq 10^{+278}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot y\right) \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (+ (* x y) z) y)))
   (if (<= t_1 -4e+283)
     (* (* y x) y)
     (if (<= t_1 1e+278) (fma z y t) (* (* y y) x)))))
double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) + z) * y;
	double tmp;
	if (t_1 <= -4e+283) {
		tmp = (y * x) * y;
	} else if (t_1 <= 1e+278) {
		tmp = fma(z, y, t);
	} else {
		tmp = (y * y) * x;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(x * y) + z) * y)
	tmp = 0.0
	if (t_1 <= -4e+283)
		tmp = Float64(Float64(y * x) * y);
	elseif (t_1 <= 1e+278)
		tmp = fma(z, y, t);
	else
		tmp = Float64(Float64(y * y) * x);
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+283], N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$1, 1e+278], N[(z * y + t), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+283}:\\
\;\;\;\;\left(y \cdot x\right) \cdot y\\

\mathbf{elif}\;t\_1 \leq 10^{+278}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\

\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -3.99999999999999982e283

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

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

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      2. lower-*.f64N/A

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      3. unpow2N/A

        \[\leadsto \left(y \cdot y\right) \cdot x \]
      4. lower-*.f6476.5

        \[\leadsto \left(y \cdot y\right) \cdot x \]
    5. Applied rewrites76.5%

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

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

        \[\leadsto \left(y \cdot y\right) \cdot x \]
      3. pow2N/A

        \[\leadsto {y}^{2} \cdot x \]
      4. *-commutativeN/A

        \[\leadsto x \cdot \color{blue}{{y}^{2}} \]
      5. pow2N/A

        \[\leadsto x \cdot \left(y \cdot \color{blue}{y}\right) \]
      6. associate-*r*N/A

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

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

        \[\leadsto \left(y \cdot x\right) \cdot y \]
      9. lower-*.f6478.4

        \[\leadsto \left(y \cdot x\right) \cdot y \]
    7. Applied rewrites78.4%

      \[\leadsto \left(y \cdot x\right) \cdot \color{blue}{y} \]

    if -3.99999999999999982e283 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.99999999999999964e277

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t + y \cdot z} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto z \cdot y + t \]
      3. lower-fma.f6483.4

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{y}, t\right) \]
    5. Applied rewrites83.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]

    if 9.99999999999999964e277 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

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

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      2. lower-*.f64N/A

        \[\leadsto {y}^{2} \cdot \color{blue}{x} \]
      3. unpow2N/A

        \[\leadsto \left(y \cdot y\right) \cdot x \]
      4. lower-*.f6479.6

        \[\leadsto \left(y \cdot y\right) \cdot x \]
    5. Applied rewrites79.6%

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

Alternative 5: 52.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(x \cdot y + z\right) \cdot y\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+146} \lor \neg \left(t\_1 \leq 10^{+66}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (+ (* x y) z) y)))
   (if (or (<= t_1 -5e+146) (not (<= t_1 1e+66))) (* z y) t)))
double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) + z) * y;
	double tmp;
	if ((t_1 <= -5e+146) || !(t_1 <= 1e+66)) {
		tmp = z * y;
	} else {
		tmp = t;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ((x * y) + z) * y
    if ((t_1 <= (-5d+146)) .or. (.not. (t_1 <= 1d+66))) then
        tmp = z * y
    else
        tmp = t
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = ((x * y) + z) * y;
	double tmp;
	if ((t_1 <= -5e+146) || !(t_1 <= 1e+66)) {
		tmp = z * y;
	} else {
		tmp = t;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = ((x * y) + z) * y
	tmp = 0
	if (t_1 <= -5e+146) or not (t_1 <= 1e+66):
		tmp = z * y
	else:
		tmp = t
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(x * y) + z) * y)
	tmp = 0.0
	if ((t_1 <= -5e+146) || !(t_1 <= 1e+66))
		tmp = Float64(z * y);
	else
		tmp = t;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = ((x * y) + z) * y;
	tmp = 0.0;
	if ((t_1 <= -5e+146) || ~((t_1 <= 1e+66)))
		tmp = z * y;
	else
		tmp = t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+146], N[Not[LessEqual[t$95$1, 1e+66]], $MachinePrecision]], N[(z * y), $MachinePrecision], t]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+146} \lor \neg \left(t\_1 \leq 10^{+66}\right):\\
\;\;\;\;z \cdot y\\

\mathbf{else}:\\
\;\;\;\;t\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.9999999999999999e146 or 9.99999999999999945e65 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

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

        \[\leadsto z \cdot \color{blue}{y} \]
      2. lower-*.f6438.2

        \[\leadsto z \cdot \color{blue}{y} \]
    5. Applied rewrites38.2%

      \[\leadsto \color{blue}{z \cdot y} \]

    if -4.9999999999999999e146 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.99999999999999945e65

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{t} \]
    4. Step-by-step derivation
      1. Applied rewrites79.1%

        \[\leadsto \color{blue}{t} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification56.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot y + z\right) \cdot y \leq -5 \cdot 10^{+146} \lor \neg \left(\left(x \cdot y + z\right) \cdot y \leq 10^{+66}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
    7. Add Preprocessing

    Alternative 6: 66.5% accurate, 2.4× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(z, y, t\right) \end{array} \]
    (FPCore (x y z t) :precision binary64 (fma z y t))
    double code(double x, double y, double z, double t) {
    	return fma(z, y, t);
    }
    
    function code(x, y, z, t)
    	return fma(z, y, t)
    end
    
    code[x_, y_, z_, t_] := N[(z * y + t), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(z, y, t\right)
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t + y \cdot z} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto z \cdot y + t \]
      3. lower-fma.f6463.9

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{y}, t\right) \]
    5. Applied rewrites63.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
    6. Add Preprocessing

    Alternative 7: 38.2% accurate, 17.0× speedup?

    \[\begin{array}{l} \\ t \end{array} \]
    (FPCore (x y z t) :precision binary64 t)
    double code(double x, double y, double z, double t) {
    	return t;
    }
    
    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, t)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        real(8), intent (in) :: t
        code = t
    end function
    
    public static double code(double x, double y, double z, double t) {
    	return t;
    }
    
    def code(x, y, z, t):
    	return t
    
    function code(x, y, z, t)
    	return t
    end
    
    function tmp = code(x, y, z, t)
    	tmp = t;
    end
    
    code[x_, y_, z_, t_] := t
    
    \begin{array}{l}
    
    \\
    t
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{t} \]
    4. Step-by-step derivation
      1. Applied rewrites38.9%

        \[\leadsto \color{blue}{t} \]
      2. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2025051 
      (FPCore (x y z t)
        :name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
        :precision binary64
        (+ (* (+ (* x y) z) y) t))