FastMath test2

Percentage Accurate: 99.7% → 100.0%
Time: 1.8s
Alternatives: 3
Speedup: 2.3×

Specification

?
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
(FPCore (d1 d2) :precision binary64 (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))
double code(double d1, double d2) {
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
}
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(d1, d2)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    code = ((d1 * 10.0d0) + (d1 * d2)) + (d1 * 20.0d0)
end function
public static double code(double d1, double d2) {
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
}
def code(d1, d2):
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0)
function code(d1, d2)
	return Float64(Float64(Float64(d1 * 10.0) + Float64(d1 * d2)) + Float64(d1 * 20.0))
end
function tmp = code(d1, d2)
	tmp = ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
end
code[d1_, d2_] := N[(N[(N[(d1 * 10.0), $MachinePrecision] + N[(d1 * d2), $MachinePrecision]), $MachinePrecision] + N[(d1 * 20.0), $MachinePrecision]), $MachinePrecision]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20

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 3 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.7% accurate, 1.0× speedup?

\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
(FPCore (d1 d2) :precision binary64 (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))
double code(double d1, double d2) {
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
}
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(d1, d2)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    code = ((d1 * 10.0d0) + (d1 * d2)) + (d1 * 20.0d0)
end function
public static double code(double d1, double d2) {
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
}
def code(d1, d2):
	return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0)
function code(d1, d2)
	return Float64(Float64(Float64(d1 * 10.0) + Float64(d1 * d2)) + Float64(d1 * 20.0))
end
function tmp = code(d1, d2)
	tmp = ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
end
code[d1_, d2_] := N[(N[(N[(d1 * 10.0), $MachinePrecision] + N[(d1 * d2), $MachinePrecision]), $MachinePrecision] + N[(d1 * 20.0), $MachinePrecision]), $MachinePrecision]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20

Alternative 1: 100.0% accurate, 2.3× speedup?

\[\left(d2 - -30\right) \cdot d1 \]
(FPCore (d1 d2) :precision binary64 (* (- d2 -30.0) d1))
double code(double d1, double d2) {
	return (d2 - -30.0) * d1;
}
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(d1, d2)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    code = (d2 - (-30.0d0)) * d1
end function
public static double code(double d1, double d2) {
	return (d2 - -30.0) * d1;
}
def code(d1, d2):
	return (d2 - -30.0) * d1
function code(d1, d2)
	return Float64(Float64(d2 - -30.0) * d1)
end
function tmp = code(d1, d2)
	tmp = (d2 - -30.0) * d1;
end
code[d1_, d2_] := N[(N[(d2 - -30.0), $MachinePrecision] * d1), $MachinePrecision]
\left(d2 - -30\right) \cdot d1
Derivation
  1. Initial program 99.7%

    \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20} \]
    2. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right)} + d1 \cdot 20 \]
    3. lift-*.f64N/A

      \[\leadsto \left(\color{blue}{d1 \cdot 10} + d1 \cdot d2\right) + d1 \cdot 20 \]
    4. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot 10 + \color{blue}{d1 \cdot d2}\right) + d1 \cdot 20 \]
    5. distribute-lft-outN/A

      \[\leadsto \color{blue}{d1 \cdot \left(10 + d2\right)} + d1 \cdot 20 \]
    6. lift-*.f64N/A

      \[\leadsto d1 \cdot \left(10 + d2\right) + \color{blue}{d1 \cdot 20} \]
    7. distribute-lft-outN/A

      \[\leadsto \color{blue}{d1 \cdot \left(\left(10 + d2\right) + 20\right)} \]
    8. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
    9. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
    10. add-flipN/A

      \[\leadsto \color{blue}{\left(\left(10 + d2\right) - \left(\mathsf{neg}\left(20\right)\right)\right)} \cdot d1 \]
    11. +-commutativeN/A

      \[\leadsto \left(\color{blue}{\left(d2 + 10\right)} - \left(\mathsf{neg}\left(20\right)\right)\right) \cdot d1 \]
    12. associate--l+N/A

      \[\leadsto \color{blue}{\left(d2 + \left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)} \cdot d1 \]
    13. add-flipN/A

      \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
    14. lower--.f64N/A

      \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
    15. metadata-evalN/A

      \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\left(10 - \color{blue}{-20}\right)\right)\right)\right) \cdot d1 \]
    16. metadata-evalN/A

      \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\color{blue}{30}\right)\right)\right) \cdot d1 \]
    17. metadata-eval100.0%

      \[\leadsto \left(d2 - \color{blue}{-30}\right) \cdot d1 \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(d2 - -30\right) \cdot d1} \]
  4. Add Preprocessing

Alternative 2: 97.4% accurate, 1.3× speedup?

\[\begin{array}{l} \mathbf{if}\;d2 \leq -21000:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 980000000:\\ \;\;\;\;30 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d2 \cdot d1\\ \end{array} \]
(FPCore (d1 d2)
 :precision binary64
 (if (<= d2 -21000.0)
   (* d2 d1)
   (if (<= d2 980000000.0) (* 30.0 d1) (* d2 d1))))
double code(double d1, double d2) {
	double tmp;
	if (d2 <= -21000.0) {
		tmp = d2 * d1;
	} else if (d2 <= 980000000.0) {
		tmp = 30.0 * d1;
	} else {
		tmp = d2 * d1;
	}
	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(d1, d2)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8) :: tmp
    if (d2 <= (-21000.0d0)) then
        tmp = d2 * d1
    else if (d2 <= 980000000.0d0) then
        tmp = 30.0d0 * d1
    else
        tmp = d2 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2) {
	double tmp;
	if (d2 <= -21000.0) {
		tmp = d2 * d1;
	} else if (d2 <= 980000000.0) {
		tmp = 30.0 * d1;
	} else {
		tmp = d2 * d1;
	}
	return tmp;
}
def code(d1, d2):
	tmp = 0
	if d2 <= -21000.0:
		tmp = d2 * d1
	elif d2 <= 980000000.0:
		tmp = 30.0 * d1
	else:
		tmp = d2 * d1
	return tmp
function code(d1, d2)
	tmp = 0.0
	if (d2 <= -21000.0)
		tmp = Float64(d2 * d1);
	elseif (d2 <= 980000000.0)
		tmp = Float64(30.0 * d1);
	else
		tmp = Float64(d2 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2)
	tmp = 0.0;
	if (d2 <= -21000.0)
		tmp = d2 * d1;
	elseif (d2 <= 980000000.0)
		tmp = 30.0 * d1;
	else
		tmp = d2 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_] := If[LessEqual[d2, -21000.0], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 980000000.0], N[(30.0 * d1), $MachinePrecision], N[(d2 * d1), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;d2 \leq -21000:\\
\;\;\;\;d2 \cdot d1\\

\mathbf{elif}\;d2 \leq 980000000:\\
\;\;\;\;30 \cdot d1\\

\mathbf{else}:\\
\;\;\;\;d2 \cdot d1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -21000 or 9.8e8 < d2

    1. Initial program 99.7%

      \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right)} + d1 \cdot 20 \]
      3. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{d1 \cdot 10} + d1 \cdot d2\right) + d1 \cdot 20 \]
      4. lift-*.f64N/A

        \[\leadsto \left(d1 \cdot 10 + \color{blue}{d1 \cdot d2}\right) + d1 \cdot 20 \]
      5. distribute-lft-outN/A

        \[\leadsto \color{blue}{d1 \cdot \left(10 + d2\right)} + d1 \cdot 20 \]
      6. lift-*.f64N/A

        \[\leadsto d1 \cdot \left(10 + d2\right) + \color{blue}{d1 \cdot 20} \]
      7. distribute-lft-outN/A

        \[\leadsto \color{blue}{d1 \cdot \left(\left(10 + d2\right) + 20\right)} \]
      8. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
      9. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
      10. add-flipN/A

        \[\leadsto \color{blue}{\left(\left(10 + d2\right) - \left(\mathsf{neg}\left(20\right)\right)\right)} \cdot d1 \]
      11. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(d2 + 10\right)} - \left(\mathsf{neg}\left(20\right)\right)\right) \cdot d1 \]
      12. associate--l+N/A

        \[\leadsto \color{blue}{\left(d2 + \left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)} \cdot d1 \]
      13. add-flipN/A

        \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
      14. lower--.f64N/A

        \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
      15. metadata-evalN/A

        \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\left(10 - \color{blue}{-20}\right)\right)\right)\right) \cdot d1 \]
      16. metadata-evalN/A

        \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\color{blue}{30}\right)\right)\right) \cdot d1 \]
      17. metadata-eval100.0%

        \[\leadsto \left(d2 - \color{blue}{-30}\right) \cdot d1 \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\left(d2 - -30\right) \cdot d1} \]
    4. Taylor expanded in d2 around 0

      \[\leadsto \color{blue}{30} \cdot d1 \]
    5. Step-by-step derivation
      1. Applied rewrites50.8%

        \[\leadsto \color{blue}{30} \cdot d1 \]
      2. Taylor expanded in d2 around inf

        \[\leadsto \color{blue}{d2} \cdot d1 \]
      3. Step-by-step derivation
        1. Applied rewrites51.0%

          \[\leadsto \color{blue}{d2} \cdot d1 \]

        if -21000 < d2 < 9.8e8

        1. Initial program 99.7%

          \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20} \]
          2. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right)} + d1 \cdot 20 \]
          3. lift-*.f64N/A

            \[\leadsto \left(\color{blue}{d1 \cdot 10} + d1 \cdot d2\right) + d1 \cdot 20 \]
          4. lift-*.f64N/A

            \[\leadsto \left(d1 \cdot 10 + \color{blue}{d1 \cdot d2}\right) + d1 \cdot 20 \]
          5. distribute-lft-outN/A

            \[\leadsto \color{blue}{d1 \cdot \left(10 + d2\right)} + d1 \cdot 20 \]
          6. lift-*.f64N/A

            \[\leadsto d1 \cdot \left(10 + d2\right) + \color{blue}{d1 \cdot 20} \]
          7. distribute-lft-outN/A

            \[\leadsto \color{blue}{d1 \cdot \left(\left(10 + d2\right) + 20\right)} \]
          8. *-commutativeN/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
          9. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
          10. add-flipN/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) - \left(\mathsf{neg}\left(20\right)\right)\right)} \cdot d1 \]
          11. +-commutativeN/A

            \[\leadsto \left(\color{blue}{\left(d2 + 10\right)} - \left(\mathsf{neg}\left(20\right)\right)\right) \cdot d1 \]
          12. associate--l+N/A

            \[\leadsto \color{blue}{\left(d2 + \left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)} \cdot d1 \]
          13. add-flipN/A

            \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
          14. lower--.f64N/A

            \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
          15. metadata-evalN/A

            \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\left(10 - \color{blue}{-20}\right)\right)\right)\right) \cdot d1 \]
          16. metadata-evalN/A

            \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\color{blue}{30}\right)\right)\right) \cdot d1 \]
          17. metadata-eval100.0%

            \[\leadsto \left(d2 - \color{blue}{-30}\right) \cdot d1 \]
        3. Applied rewrites100.0%

          \[\leadsto \color{blue}{\left(d2 - -30\right) \cdot d1} \]
        4. Taylor expanded in d2 around 0

          \[\leadsto \color{blue}{30} \cdot d1 \]
        5. Step-by-step derivation
          1. Applied rewrites50.8%

            \[\leadsto \color{blue}{30} \cdot d1 \]
        6. Recombined 2 regimes into one program.
        7. Add Preprocessing

        Alternative 3: 50.8% accurate, 3.9× speedup?

        \[30 \cdot d1 \]
        (FPCore (d1 d2) :precision binary64 (* 30.0 d1))
        double code(double d1, double d2) {
        	return 30.0 * d1;
        }
        
        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(d1, d2)
        use fmin_fmax_functions
            real(8), intent (in) :: d1
            real(8), intent (in) :: d2
            code = 30.0d0 * d1
        end function
        
        public static double code(double d1, double d2) {
        	return 30.0 * d1;
        }
        
        def code(d1, d2):
        	return 30.0 * d1
        
        function code(d1, d2)
        	return Float64(30.0 * d1)
        end
        
        function tmp = code(d1, d2)
        	tmp = 30.0 * d1;
        end
        
        code[d1_, d2_] := N[(30.0 * d1), $MachinePrecision]
        
        30 \cdot d1
        
        Derivation
        1. Initial program 99.7%

          \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20 \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20} \]
          2. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(d1 \cdot 10 + d1 \cdot d2\right)} + d1 \cdot 20 \]
          3. lift-*.f64N/A

            \[\leadsto \left(\color{blue}{d1 \cdot 10} + d1 \cdot d2\right) + d1 \cdot 20 \]
          4. lift-*.f64N/A

            \[\leadsto \left(d1 \cdot 10 + \color{blue}{d1 \cdot d2}\right) + d1 \cdot 20 \]
          5. distribute-lft-outN/A

            \[\leadsto \color{blue}{d1 \cdot \left(10 + d2\right)} + d1 \cdot 20 \]
          6. lift-*.f64N/A

            \[\leadsto d1 \cdot \left(10 + d2\right) + \color{blue}{d1 \cdot 20} \]
          7. distribute-lft-outN/A

            \[\leadsto \color{blue}{d1 \cdot \left(\left(10 + d2\right) + 20\right)} \]
          8. *-commutativeN/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
          9. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) + 20\right) \cdot d1} \]
          10. add-flipN/A

            \[\leadsto \color{blue}{\left(\left(10 + d2\right) - \left(\mathsf{neg}\left(20\right)\right)\right)} \cdot d1 \]
          11. +-commutativeN/A

            \[\leadsto \left(\color{blue}{\left(d2 + 10\right)} - \left(\mathsf{neg}\left(20\right)\right)\right) \cdot d1 \]
          12. associate--l+N/A

            \[\leadsto \color{blue}{\left(d2 + \left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)} \cdot d1 \]
          13. add-flipN/A

            \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
          14. lower--.f64N/A

            \[\leadsto \color{blue}{\left(d2 - \left(\mathsf{neg}\left(\left(10 - \left(\mathsf{neg}\left(20\right)\right)\right)\right)\right)\right)} \cdot d1 \]
          15. metadata-evalN/A

            \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\left(10 - \color{blue}{-20}\right)\right)\right)\right) \cdot d1 \]
          16. metadata-evalN/A

            \[\leadsto \left(d2 - \left(\mathsf{neg}\left(\color{blue}{30}\right)\right)\right) \cdot d1 \]
          17. metadata-eval100.0%

            \[\leadsto \left(d2 - \color{blue}{-30}\right) \cdot d1 \]
        3. Applied rewrites100.0%

          \[\leadsto \color{blue}{\left(d2 - -30\right) \cdot d1} \]
        4. Taylor expanded in d2 around 0

          \[\leadsto \color{blue}{30} \cdot d1 \]
        5. Step-by-step derivation
          1. Applied rewrites50.8%

            \[\leadsto \color{blue}{30} \cdot d1 \]
          2. Add Preprocessing

          Developer Target 1: 100.0% accurate, 2.3× speedup?

          \[d1 \cdot \left(30 + d2\right) \]
          (FPCore (d1 d2) :precision binary64 (* d1 (+ 30.0 d2)))
          double code(double d1, double d2) {
          	return d1 * (30.0 + d2);
          }
          
          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(d1, d2)
          use fmin_fmax_functions
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              code = d1 * (30.0d0 + d2)
          end function
          
          public static double code(double d1, double d2) {
          	return d1 * (30.0 + d2);
          }
          
          def code(d1, d2):
          	return d1 * (30.0 + d2)
          
          function code(d1, d2)
          	return Float64(d1 * Float64(30.0 + d2))
          end
          
          function tmp = code(d1, d2)
          	tmp = d1 * (30.0 + d2);
          end
          
          code[d1_, d2_] := N[(d1 * N[(30.0 + d2), $MachinePrecision]), $MachinePrecision]
          
          d1 \cdot \left(30 + d2\right)
          

          Reproduce

          ?
          herbie shell --seed 2025183 
          (FPCore (d1 d2)
            :name "FastMath test2"
            :precision binary64
          
            :alt
            (! :herbie-platform c (* d1 (+ 30 d2)))
          
            (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))