peicewise-defined

Percentage Accurate: 75.6% → 76.4%
Time: 3.1s
Alternatives: 5
Speedup: 1.5×

Specification

?
\[p \geq -1.79 \cdot 10^{+308} \land p \leq 1.79 \cdot 10^{+308}\]
\[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
(FPCore (p)
  :precision binary64
  (- (+ p 1.0) (/ (pow (fmin p 0.0) 2.0) (- (fmin p 0.0) 1.0))))
double code(double p) {
	return (p + 1.0) - (pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.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(p)
use fmin_fmax_functions
    real(8), intent (in) :: p
    code = (p + 1.0d0) - ((fmin(p, 0.0d0) ** 2.0d0) / (fmin(p, 0.0d0) - 1.0d0))
end function
public static double code(double p) {
	return (p + 1.0) - (Math.pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.0));
}
def code(p):
	return (p + 1.0) - (math.pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.0))
function code(p)
	return Float64(Float64(p + 1.0) - Float64((fmin(p, 0.0) ^ 2.0) / Float64(fmin(p, 0.0) - 1.0)))
end
function tmp = code(p)
	tmp = (p + 1.0) - ((min(p, 0.0) ^ 2.0) / (min(p, 0.0) - 1.0));
end
code[p_] := N[(N[(p + 1.0), $MachinePrecision] - N[(N[Power[N[Min[p, 0.0], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Min[p, 0.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}

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 5 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: 75.6% accurate, 1.0× speedup?

\[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
(FPCore (p)
  :precision binary64
  (- (+ p 1.0) (/ (pow (fmin p 0.0) 2.0) (- (fmin p 0.0) 1.0))))
double code(double p) {
	return (p + 1.0) - (pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.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(p)
use fmin_fmax_functions
    real(8), intent (in) :: p
    code = (p + 1.0d0) - ((fmin(p, 0.0d0) ** 2.0d0) / (fmin(p, 0.0d0) - 1.0d0))
end function
public static double code(double p) {
	return (p + 1.0) - (Math.pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.0));
}
def code(p):
	return (p + 1.0) - (math.pow(fmin(p, 0.0), 2.0) / (fmin(p, 0.0) - 1.0))
function code(p)
	return Float64(Float64(p + 1.0) - Float64((fmin(p, 0.0) ^ 2.0) / Float64(fmin(p, 0.0) - 1.0)))
end
function tmp = code(p)
	tmp = (p + 1.0) - ((min(p, 0.0) ^ 2.0) / (min(p, 0.0) - 1.0));
end
code[p_] := N[(N[(p + 1.0), $MachinePrecision] - N[(N[Power[N[Min[p, 0.0], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Min[p, 0.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}

Alternative 1: 76.4% accurate, 1.5× speedup?

\[\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right) \]
(FPCore (p)
  :precision binary64
  (fma (fmin 0.0 p) (/ (fmin 0.0 p) (- 1.0 (fmin 0.0 p))) (- p -1.0)))
double code(double p) {
	return fma(fmin(0.0, p), (fmin(0.0, p) / (1.0 - fmin(0.0, p))), (p - -1.0));
}
function code(p)
	return fma(fmin(0.0, p), Float64(fmin(0.0, p) / Float64(1.0 - fmin(0.0, p))), Float64(p - -1.0))
end
code[p_] := N[(N[Min[0.0, p], $MachinePrecision] * N[(N[Min[0.0, p], $MachinePrecision] / N[(1.0 - N[Min[0.0, p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(p - -1.0), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)
Derivation
  1. Initial program 75.6%

    \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
  2. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
    2. sub-flipN/A

      \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
    3. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
    4. lift-/.f64N/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}}\right)\right) + \left(p + 1\right) \]
    5. distribute-neg-frac2N/A

      \[\leadsto \color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
    6. lift-pow.f64N/A

      \[\leadsto \frac{\color{blue}{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
    7. unpow2N/A

      \[\leadsto \frac{\color{blue}{\mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
    8. associate-/l*N/A

      \[\leadsto \color{blue}{\mathsf{min}\left(p, 0\right) \cdot \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
    9. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(p, 0\right), \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right)} \]
    10. lift-fmin.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(p, 0\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    11. fmin-swapN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    12. lower-fmin.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    13. lower-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \color{blue}{\frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}}, p + 1\right) \]
    14. lift-fmin.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    15. fmin-swapN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    16. lower-fmin.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
    17. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)}, p + 1\right) \]
    18. sub-negate-revN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
    19. lower--.f6476.4%

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
    20. lift-fmin.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
    21. fmin-swapN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
    22. lower-fmin.f6476.4%

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
    23. lift-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p + 1}\right) \]
    24. add-flipN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
    25. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
  3. Applied rewrites76.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)} \]
  4. Add Preprocessing

Alternative 2: 76.2% accurate, 1.5× speedup?

\[\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p\right) - -1 \]
(FPCore (p)
  :precision binary64
  (- (fma (fmin 0.0 p) (/ (fmin 0.0 p) (- 1.0 (fmin 0.0 p))) p) -1.0))
double code(double p) {
	return fma(fmin(0.0, p), (fmin(0.0, p) / (1.0 - fmin(0.0, p))), p) - -1.0;
}
function code(p)
	return Float64(fma(fmin(0.0, p), Float64(fmin(0.0, p) / Float64(1.0 - fmin(0.0, p))), p) - -1.0)
end
code[p_] := N[(N[(N[Min[0.0, p], $MachinePrecision] * N[(N[Min[0.0, p], $MachinePrecision] / N[(1.0 - N[Min[0.0, p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + p), $MachinePrecision] - -1.0), $MachinePrecision]
\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p\right) - -1
Derivation
  1. Initial program 75.6%

    \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
  2. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
    2. sub-flipN/A

      \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
    3. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
    4. lift-+.f64N/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \color{blue}{\left(p + 1\right)} \]
    5. add-flipN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \color{blue}{\left(p - \left(\mathsf{neg}\left(1\right)\right)\right)} \]
    6. associate-+r-N/A

      \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + p\right) - \left(\mathsf{neg}\left(1\right)\right)} \]
    7. +-commutativeN/A

      \[\leadsto \color{blue}{\left(p + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)\right)} - \left(\mathsf{neg}\left(1\right)\right) \]
    8. sub-flip-reverseN/A

      \[\leadsto \color{blue}{\left(p - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)} - \left(\mathsf{neg}\left(1\right)\right) \]
    9. lower--.f64N/A

      \[\leadsto \color{blue}{\left(p - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right) - \left(\mathsf{neg}\left(1\right)\right)} \]
  3. Applied rewrites76.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p\right) - -1} \]
  4. Add Preprocessing

Alternative 3: 74.1% accurate, 1.4× speedup?

\[\begin{array}{l} t_0 := \mathsf{min}\left(0, p\right) - 1\\ \mathbf{if}\;p \leq 17.5:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0 \cdot p}{t\_0}\\ \end{array} \]
(FPCore (p)
  :precision binary64
  (let* ((t_0 (- (fmin 0.0 p) 1.0)))
  (if (<= p 17.5)
    (fma (fmin 0.0 p) (/ (fmin 0.0 p) (- 1.0 (fmin 0.0 p))) 1.0)
    (/ (* t_0 p) t_0))))
double code(double p) {
	double t_0 = fmin(0.0, p) - 1.0;
	double tmp;
	if (p <= 17.5) {
		tmp = fma(fmin(0.0, p), (fmin(0.0, p) / (1.0 - fmin(0.0, p))), 1.0);
	} else {
		tmp = (t_0 * p) / t_0;
	}
	return tmp;
}
function code(p)
	t_0 = Float64(fmin(0.0, p) - 1.0)
	tmp = 0.0
	if (p <= 17.5)
		tmp = fma(fmin(0.0, p), Float64(fmin(0.0, p) / Float64(1.0 - fmin(0.0, p))), 1.0);
	else
		tmp = Float64(Float64(t_0 * p) / t_0);
	end
	return tmp
end
code[p_] := Block[{t$95$0 = N[(N[Min[0.0, p], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[p, 17.5], N[(N[Min[0.0, p], $MachinePrecision] * N[(N[Min[0.0, p], $MachinePrecision] / N[(1.0 - N[Min[0.0, p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 * p), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(0, p\right) - 1\\
\mathbf{if}\;p \leq 17.5:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, 1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot p}{t\_0}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if p < 17.5

    1. Initial program 75.6%

      \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
      4. lift-/.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}}\right)\right) + \left(p + 1\right) \]
      5. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      6. lift-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      7. unpow2N/A

        \[\leadsto \frac{\color{blue}{\mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      8. associate-/l*N/A

        \[\leadsto \color{blue}{\mathsf{min}\left(p, 0\right) \cdot \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(p, 0\right), \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right)} \]
      10. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(p, 0\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      11. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      12. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \color{blue}{\frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}}, p + 1\right) \]
      14. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      15. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      16. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      17. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)}, p + 1\right) \]
      18. sub-negate-revN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      19. lower--.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      20. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      21. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      22. lower-fmin.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      23. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p + 1}\right) \]
      24. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
      25. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
    3. Applied rewrites76.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)} \]
    4. Taylor expanded in p around 0

      \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{1}\right) \]
    5. Step-by-step derivation
      1. Applied rewrites51.3%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{1}\right) \]

      if 17.5 < p

      1. Initial program 75.6%

        \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
        2. sub-flipN/A

          \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
        3. +-commutativeN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
        4. lift-/.f64N/A

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}}\right)\right) + \left(p + 1\right) \]
        5. distribute-neg-frac2N/A

          \[\leadsto \color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
        6. lift-pow.f64N/A

          \[\leadsto \frac{\color{blue}{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
        7. unpow2N/A

          \[\leadsto \frac{\color{blue}{\mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
        8. associate-/l*N/A

          \[\leadsto \color{blue}{\mathsf{min}\left(p, 0\right) \cdot \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
        9. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(p, 0\right), \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right)} \]
        10. lift-fmin.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(p, 0\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        11. fmin-swapN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        12. lower-fmin.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        13. lower-/.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \color{blue}{\frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}}, p + 1\right) \]
        14. lift-fmin.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        15. fmin-swapN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        16. lower-fmin.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
        17. lift--.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)}, p + 1\right) \]
        18. sub-negate-revN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
        19. lower--.f6476.4%

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
        20. lift-fmin.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
        21. fmin-swapN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
        22. lower-fmin.f6476.4%

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
        23. lift-+.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p + 1}\right) \]
        24. add-flipN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
        25. lower--.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
      3. Applied rewrites76.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)} \]
      4. Applied rewrites75.6%

        \[\leadsto \color{blue}{\frac{\left(-1 - p\right) \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right) - \mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      5. Taylor expanded in p around inf

        \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
        2. lower-/.f64N/A

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
        3. lower-*.f64N/A

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right)} - 1} \]
        4. lower--.f64N/A

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
        5. lower-fmin.f64N/A

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
        6. lower--.f64N/A

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - \color{blue}{1}} \]
        7. lower-fmin.f6426.3%

          \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
      7. Applied rewrites26.3%

        \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      8. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
        2. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
        3. lift-/.f64N/A

          \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
        4. distribute-neg-frac2N/A

          \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} \]
        5. lift-*.f64N/A

          \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)} \]
        6. lift--.f64N/A

          \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - \color{blue}{1}\right)\right)} \]
        7. sub-negate-revN/A

          \[\leadsto \frac{p \cdot \left(\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - \color{blue}{1}\right)\right)} \]
        8. lift--.f64N/A

          \[\leadsto \frac{p \cdot \left(\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} \]
        9. distribute-rgt-neg-outN/A

          \[\leadsto \frac{\mathsf{neg}\left(p \cdot \left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)} \]
        10. *-commutativeN/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p\right)}{\mathsf{neg}\left(\left(\color{blue}{\mathsf{min}\left(p, 0\right)} - 1\right)\right)} \]
        11. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p\right)}{\mathsf{neg}\left(\left(\color{blue}{\mathsf{min}\left(p, 0\right)} - 1\right)\right)} \]
        12. frac-2neg-revN/A

          \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
        13. lower-/.f6426.3%

          \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
        14. lift-fmin.f64N/A

          \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
        15. fmin-swapN/A

          \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
        16. lift-fmin.f6426.3%

          \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
        17. lift-fmin.f64N/A

          \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
        18. fmin-swapN/A

          \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(0, p\right) - 1} \]
        19. lift-fmin.f6426.3%

          \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(0, p\right) - 1} \]
      9. Applied rewrites26.3%

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(0, p\right) - 1}} \]
    6. Recombined 2 regimes into one program.
    7. Add Preprocessing

    Alternative 4: 26.3% accurate, 1.8× speedup?

    \[\left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(0, p\right) - 1} \]
    (FPCore (p)
      :precision binary64
      (* (- p) (/ (- 1.0 (fmin 0.0 p)) (- (fmin 0.0 p) 1.0))))
    double code(double p) {
    	return -p * ((1.0 - fmin(0.0, p)) / (fmin(0.0, p) - 1.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(p)
    use fmin_fmax_functions
        real(8), intent (in) :: p
        code = -p * ((1.0d0 - fmin(0.0d0, p)) / (fmin(0.0d0, p) - 1.0d0))
    end function
    
    public static double code(double p) {
    	return -p * ((1.0 - fmin(0.0, p)) / (fmin(0.0, p) - 1.0));
    }
    
    def code(p):
    	return -p * ((1.0 - fmin(0.0, p)) / (fmin(0.0, p) - 1.0))
    
    function code(p)
    	return Float64(Float64(-p) * Float64(Float64(1.0 - fmin(0.0, p)) / Float64(fmin(0.0, p) - 1.0)))
    end
    
    function tmp = code(p)
    	tmp = -p * ((1.0 - min(0.0, p)) / (min(0.0, p) - 1.0));
    end
    
    code[p_] := N[((-p) * N[(N[(1.0 - N[Min[0.0, p], $MachinePrecision]), $MachinePrecision] / N[(N[Min[0.0, p], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
    
    \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(0, p\right) - 1}
    
    Derivation
    1. Initial program 75.6%

      \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
      4. lift-/.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}}\right)\right) + \left(p + 1\right) \]
      5. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      6. lift-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      7. unpow2N/A

        \[\leadsto \frac{\color{blue}{\mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      8. associate-/l*N/A

        \[\leadsto \color{blue}{\mathsf{min}\left(p, 0\right) \cdot \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(p, 0\right), \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right)} \]
      10. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(p, 0\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      11. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      12. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \color{blue}{\frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}}, p + 1\right) \]
      14. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      15. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      16. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      17. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)}, p + 1\right) \]
      18. sub-negate-revN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      19. lower--.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      20. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      21. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      22. lower-fmin.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      23. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p + 1}\right) \]
      24. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
      25. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
    3. Applied rewrites76.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)} \]
    4. Applied rewrites75.6%

      \[\leadsto \color{blue}{\frac{\left(-1 - p\right) \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right) - \mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    5. Taylor expanded in p around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
      3. lower-*.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right)} - 1} \]
      4. lower--.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
      5. lower-fmin.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
      6. lower--.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - \color{blue}{1}} \]
      7. lower-fmin.f6426.3%

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
    7. Applied rewrites26.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      5. associate-/l*N/A

        \[\leadsto \mathsf{neg}\left(p \cdot \frac{1 - \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(p\right)\right) \cdot \color{blue}{\frac{1 - \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      7. lift-neg.f64N/A

        \[\leadsto \left(-p\right) \cdot \frac{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}{\mathsf{min}\left(p, 0\right) - 1} \]
      8. lower-*.f64N/A

        \[\leadsto \left(-p\right) \cdot \color{blue}{\frac{1 - \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      9. lower-/.f6426.3%

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(p, 0\right)}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
      10. lift-fmin.f64N/A

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
      11. fmin-swapN/A

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
      12. lift-fmin.f6426.3%

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
      13. lift-fmin.f64N/A

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
      14. fmin-swapN/A

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(0, p\right) - 1} \]
      15. lift-fmin.f6426.3%

        \[\leadsto \left(-p\right) \cdot \frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(0, p\right) - 1} \]
    9. Applied rewrites26.3%

      \[\leadsto \left(-p\right) \cdot \color{blue}{\frac{1 - \mathsf{min}\left(0, p\right)}{\mathsf{min}\left(0, p\right) - 1}} \]
    10. Add Preprocessing

    Alternative 5: 26.3% accurate, 1.9× speedup?

    \[\begin{array}{l} t_0 := \mathsf{min}\left(0, p\right) - 1\\ \frac{t\_0 \cdot p}{t\_0} \end{array} \]
    (FPCore (p)
      :precision binary64
      (let* ((t_0 (- (fmin 0.0 p) 1.0))) (/ (* t_0 p) t_0)))
    double code(double p) {
    	double t_0 = fmin(0.0, p) - 1.0;
    	return (t_0 * p) / t_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(p)
    use fmin_fmax_functions
        real(8), intent (in) :: p
        real(8) :: t_0
        t_0 = fmin(0.0d0, p) - 1.0d0
        code = (t_0 * p) / t_0
    end function
    
    public static double code(double p) {
    	double t_0 = fmin(0.0, p) - 1.0;
    	return (t_0 * p) / t_0;
    }
    
    def code(p):
    	t_0 = fmin(0.0, p) - 1.0
    	return (t_0 * p) / t_0
    
    function code(p)
    	t_0 = Float64(fmin(0.0, p) - 1.0)
    	return Float64(Float64(t_0 * p) / t_0)
    end
    
    function tmp = code(p)
    	t_0 = min(0.0, p) - 1.0;
    	tmp = (t_0 * p) / t_0;
    end
    
    code[p_] := Block[{t$95$0 = N[(N[Min[0.0, p], $MachinePrecision] - 1.0), $MachinePrecision]}, N[(N[(t$95$0 * p), $MachinePrecision] / t$95$0), $MachinePrecision]]
    
    \begin{array}{l}
    t_0 := \mathsf{min}\left(0, p\right) - 1\\
    \frac{t\_0 \cdot p}{t\_0}
    \end{array}
    
    Derivation
    1. Initial program 75.6%

      \[\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(p + 1\right) - \frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\left(p + 1\right) + \left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}\right)\right) + \left(p + 1\right)} \]
      4. lift-/.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{min}\left(p, 0\right) - 1}}\right)\right) + \left(p + 1\right) \]
      5. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      6. lift-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\left(\mathsf{min}\left(p, 0\right)\right)}^{2}}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      7. unpow2N/A

        \[\leadsto \frac{\color{blue}{\mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} + \left(p + 1\right) \]
      8. associate-/l*N/A

        \[\leadsto \color{blue}{\mathsf{min}\left(p, 0\right) \cdot \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} + \left(p + 1\right) \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(p, 0\right), \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right)} \]
      10. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(p, 0\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      11. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      12. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{min}\left(0, p\right)}, \frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \color{blue}{\frac{\mathsf{min}\left(p, 0\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}}, p + 1\right) \]
      14. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(p, 0\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      15. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      16. lower-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\color{blue}{\mathsf{min}\left(0, p\right)}}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}, p + 1\right) \]
      17. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)}, p + 1\right) \]
      18. sub-negate-revN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      19. lower--.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{\color{blue}{1 - \mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      20. lift-fmin.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(p, 0\right)}}, p + 1\right) \]
      21. fmin-swapN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      22. lower-fmin.f6476.4%

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \color{blue}{\mathsf{min}\left(0, p\right)}}, p + 1\right) \]
      23. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p + 1}\right) \]
      24. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
      25. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, \color{blue}{p - \left(\mathsf{neg}\left(1\right)\right)}\right) \]
    3. Applied rewrites76.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{min}\left(0, p\right), \frac{\mathsf{min}\left(0, p\right)}{1 - \mathsf{min}\left(0, p\right)}, p - -1\right)} \]
    4. Applied rewrites75.6%

      \[\leadsto \color{blue}{\frac{\left(-1 - p\right) \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right) - \mathsf{min}\left(p, 0\right) \cdot \mathsf{min}\left(p, 0\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    5. Taylor expanded in p around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
      3. lower-*.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{min}\left(p, 0\right)} - 1} \]
      4. lower--.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, \color{blue}{0}\right) - 1} \]
      5. lower-fmin.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
      6. lower--.f64N/A

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - \color{blue}{1}} \]
      7. lower-fmin.f6426.3%

        \[\leadsto -1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1} \]
    7. Applied rewrites26.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{min}\left(p, 0\right) - 1}\right) \]
      4. distribute-neg-frac2N/A

        \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \frac{p \cdot \left(1 - \mathsf{min}\left(p, 0\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - \color{blue}{1}\right)\right)} \]
      7. sub-negate-revN/A

        \[\leadsto \frac{p \cdot \left(\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - \color{blue}{1}\right)\right)} \]
      8. lift--.f64N/A

        \[\leadsto \frac{p \cdot \left(\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right)\right)} \]
      9. distribute-rgt-neg-outN/A

        \[\leadsto \frac{\mathsf{neg}\left(p \cdot \left(\mathsf{min}\left(p, 0\right) - 1\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{min}\left(p, 0\right) - 1\right)}\right)} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p\right)}{\mathsf{neg}\left(\left(\color{blue}{\mathsf{min}\left(p, 0\right)} - 1\right)\right)} \]
      11. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p\right)}{\mathsf{neg}\left(\left(\color{blue}{\mathsf{min}\left(p, 0\right)} - 1\right)\right)} \]
      12. frac-2neg-revN/A

        \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
      13. lower-/.f6426.3%

        \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(p, 0\right) - 1}} \]
      14. lift-fmin.f64N/A

        \[\leadsto \frac{\left(\mathsf{min}\left(p, 0\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
      15. fmin-swapN/A

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
      16. lift-fmin.f6426.3%

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
      17. lift-fmin.f64N/A

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(p, 0\right) - 1} \]
      18. fmin-swapN/A

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(0, p\right) - 1} \]
      19. lift-fmin.f6426.3%

        \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\mathsf{min}\left(0, p\right) - 1} \]
    9. Applied rewrites26.3%

      \[\leadsto \frac{\left(\mathsf{min}\left(0, p\right) - 1\right) \cdot p}{\color{blue}{\mathsf{min}\left(0, p\right) - 1}} \]
    10. Add Preprocessing

    Developer Target 1: 52.1% accurate, 1.5× speedup?

    \[\begin{array}{l} \mathbf{if}\;p \geq -1 \cdot 10^{-6} \land p \leq 0:\\ \;\;\;\;\left(p + 1\right) - \frac{p \cdot p}{p - 1}\\ \mathbf{else}:\\ \;\;\;\;p - \mathsf{fma}\left(\frac{p}{p - 1}, p, -1\right)\\ \end{array} \]
    (FPCore (p)
      :precision binary64
      (if (and (>= p -1e-6) (<= p 0.0))
      (- (+ p 1.0) (/ (* p p) (- p 1.0)))
      (- p (fma (/ p (- p 1.0)) p -1.0))))
    double code(double p) {
    	double tmp;
    	if ((p >= -1e-6) && (p <= 0.0)) {
    		tmp = (p + 1.0) - ((p * p) / (p - 1.0));
    	} else {
    		tmp = p - fma((p / (p - 1.0)), p, -1.0);
    	}
    	return tmp;
    }
    
    function code(p)
    	tmp = 0.0
    	if ((p >= -1e-6) && (p <= 0.0))
    		tmp = Float64(Float64(p + 1.0) - Float64(Float64(p * p) / Float64(p - 1.0)));
    	else
    		tmp = Float64(p - fma(Float64(p / Float64(p - 1.0)), p, -1.0));
    	end
    	return tmp
    end
    
    code[p_] := If[And[GreaterEqual[p, -1e-6], LessEqual[p, 0.0]], N[(N[(p + 1.0), $MachinePrecision] - N[(N[(p * p), $MachinePrecision] / N[(p - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(p - N[(N[(p / N[(p - 1.0), $MachinePrecision]), $MachinePrecision] * p + -1.0), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    \mathbf{if}\;p \geq -1 \cdot 10^{-6} \land p \leq 0:\\
    \;\;\;\;\left(p + 1\right) - \frac{p \cdot p}{p - 1}\\
    
    \mathbf{else}:\\
    \;\;\;\;p - \mathsf{fma}\left(\frac{p}{p - 1}, p, -1\right)\\
    
    
    \end{array}
    

    Reproduce

    ?
    herbie shell --seed 2025210 
    (FPCore (p)
      :name "peicewise-defined"
      :precision binary64
      :pre (and (>= p -1.79e+308) (<= p 1.79e+308))
    
      :alt
      (if (and (>= p -1/1000000) (<= p 0)) (- (+ p 1) (/ (* p p) (- p 1))) (- p (fma (/ p (- p 1)) p -1)))
    
      (- (+ p 1.0) (/ (pow (fmin p 0.0) 2.0) (- (fmin p 0.0) 1.0))))