Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B

Percentage Accurate: 91.3% → 97.9%
Time: 3.2s
Alternatives: 6
Speedup: 0.8×

Specification

?
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - ((y * 4.0) * ((z * z) - t));
end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)

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

\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - ((y * 4.0) * ((z * z) - t));
end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)

Alternative 1: 97.9% accurate, 0.8× speedup?

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

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Step-by-step derivation
    1. lift--.f64N/A

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

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

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z - t\right)} \]
    4. sub-flipN/A

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
    5. distribute-rgt-inN/A

      \[\leadsto x \cdot x - \color{blue}{\left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + \left(\mathsf{neg}\left(t\right)\right) \cdot \left(y \cdot 4\right)\right)} \]
    6. associate--r+N/A

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

      \[\leadsto \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) - \color{blue}{\left(y \cdot 4\right) \cdot \left(\mathsf{neg}\left(t\right)\right)} \]
    8. fp-cancel-sub-sign-invN/A

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

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

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    11. distribute-rgt-neg-outN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \left(y \cdot 4\right)\right)\right)} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    12. lift-*.f64N/A

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

      \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \color{blue}{\left(4 \cdot y\right)}\right)\right) + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    14. associate-*r*N/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right) \cdot y}\right)\right) + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    15. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right)\right) \cdot y} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    16. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right), y, x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right)} \]
  3. Applied rewrites97.2%

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

Alternative 2: 97.2% accurate, 0.8× speedup?

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

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Step-by-step derivation
    1. lift--.f64N/A

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

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

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z - t\right)} \]
    4. sub-flipN/A

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
    5. distribute-rgt-inN/A

      \[\leadsto x \cdot x - \color{blue}{\left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + \left(\mathsf{neg}\left(t\right)\right) \cdot \left(y \cdot 4\right)\right)} \]
    6. associate--r+N/A

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

      \[\leadsto \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) - \color{blue}{\left(y \cdot 4\right) \cdot \left(\mathsf{neg}\left(t\right)\right)} \]
    8. fp-cancel-sub-sign-invN/A

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

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

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    11. distribute-rgt-neg-outN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \left(y \cdot 4\right)\right)\right)} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    12. lift-*.f64N/A

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

      \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \color{blue}{\left(4 \cdot y\right)}\right)\right) + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    14. associate-*r*N/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right) \cdot y}\right)\right) + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    15. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right)\right) \cdot y} + \left(x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right) \]
    16. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot 4\right), y, x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right)} \]
  3. Applied rewrites97.2%

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

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, \color{blue}{\left(\left(-4 \cdot y\right) \cdot z\right) \cdot z + x \cdot x}\right) \]
    2. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, \color{blue}{x \cdot x + \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z}\right) \]
    3. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x + \color{blue}{\left(\left(-4 \cdot y\right) \cdot z\right)} \cdot z\right) \]
    4. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x + \color{blue}{\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)}\right) \]
    5. lift-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x + \color{blue}{\left(y \cdot -4\right)} \cdot \left(z \cdot z\right)\right) \]
    7. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x + \left(y \cdot -4\right) \cdot \color{blue}{\left(z \cdot z\right)}\right) \]
    8. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x + \color{blue}{y \cdot \left(-4 \cdot \left(z \cdot z\right)\right)}\right) \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, \color{blue}{x \cdot x - \left(\mathsf{neg}\left(y\right)\right) \cdot \left(-4 \cdot \left(z \cdot z\right)\right)}\right) \]
    10. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \color{blue}{\left(\mathsf{neg}\left(y \cdot \left(-4 \cdot \left(z \cdot z\right)\right)\right)\right)}\right) \]
    11. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(y \cdot -4\right) \cdot \left(z \cdot z\right)}\right)\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(-4 \cdot y\right)} \cdot \left(z \cdot z\right)\right)\right)\right) \]
    13. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(-4 \cdot y\right)} \cdot \left(z \cdot z\right)\right)\right)\right) \]
    14. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\left(-4 \cdot y\right) \cdot \color{blue}{\left(z \cdot z\right)}\right)\right)\right) \]
    15. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(\left(-4 \cdot y\right) \cdot z\right) \cdot z}\right)\right)\right) \]
    16. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(\left(-4 \cdot y\right) \cdot z\right)} \cdot z\right)\right)\right) \]
    17. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(\left(-4 \cdot y\right) \cdot z\right)} \cdot z\right)\right)\right) \]
    18. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\color{blue}{\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)}\right)\right)\right) \]
    19. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(\mathsf{neg}\left(\left(-4 \cdot y\right) \cdot \color{blue}{\left(z \cdot z\right)}\right)\right)\right) \]
    20. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \color{blue}{\left(-4 \cdot y\right) \cdot \left(\mathsf{neg}\left(z \cdot z\right)\right)}\right) \]
    21. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(-4 \cdot y\right) \cdot \left(\mathsf{neg}\left(\color{blue}{z \cdot z}\right)\right)\right) \]
    22. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{fma}\left(t \cdot 4, y, x \cdot x - \left(-4 \cdot y\right) \cdot \color{blue}{\left(z \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}\right) \]
  5. Applied rewrites97.9%

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

Alternative 3: 95.1% accurate, 0.7× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 3.39999999999999991e159

    1. Initial program 91.3%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \left(z \cdot z - t\right) + x \cdot x} \]
      5. lift--.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \color{blue}{\left(z \cdot z - t\right)} + x \cdot x \]
      6. sub-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \color{blue}{\left(z \cdot z + \left(\mathsf{neg}\left(t\right)\right)\right)} + x \cdot x \]
      7. distribute-lft-inN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \left(z \cdot z\right) + \left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)} + x \cdot x \]
      8. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \left(z \cdot z\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)} + x \cdot x \]
      9. lift-*.f64N/A

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

        \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{4 \cdot y}\right)\right) \cdot \left(z \cdot z\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right) + x \cdot x \]
      11. distribute-rgt-neg-inN/A

        \[\leadsto \left(\color{blue}{\left(4 \cdot \left(\mathsf{neg}\left(y\right)\right)\right)} \cdot \left(z \cdot z\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right) + x \cdot x \]
      12. associate-*l*N/A

        \[\leadsto \left(\color{blue}{4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right)} - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right) + x \cdot x \]
      13. distribute-lft-neg-outN/A

        \[\leadsto \left(4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right) - \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y \cdot 4\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)\right)}\right) + x \cdot x \]
      14. distribute-lft-neg-outN/A

        \[\leadsto \left(4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(y \cdot 4\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)\right)}\right)\right)\right) + x \cdot x \]
      15. remove-double-negN/A

        \[\leadsto \left(4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right) - \color{blue}{\left(y \cdot 4\right) \cdot \left(\mathsf{neg}\left(t\right)\right)}\right) + x \cdot x \]
      16. lift-*.f64N/A

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

        \[\leadsto \left(4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right) - \color{blue}{\left(4 \cdot y\right)} \cdot \left(\mathsf{neg}\left(t\right)\right)\right) + x \cdot x \]
      18. associate-*l*N/A

        \[\leadsto \left(4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right)\right) - \color{blue}{4 \cdot \left(y \cdot \left(\mathsf{neg}\left(t\right)\right)\right)}\right) + x \cdot x \]
      19. distribute-lft-out--N/A

        \[\leadsto \color{blue}{4 \cdot \left(\left(\mathsf{neg}\left(y\right)\right) \cdot \left(z \cdot z\right) - y \cdot \left(\mathsf{neg}\left(t\right)\right)\right)} + x \cdot x \]
    3. Applied rewrites93.6%

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

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

        \[\leadsto \mathsf{fma}\left(4, \left(\left(-y\right) \cdot z\right) \cdot z - \color{blue}{\left(-t\right) \cdot y}, x \cdot x\right) \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot z + \left(\mathsf{neg}\left(\left(-t\right)\right)\right) \cdot y}, x \cdot x\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\left(\mathsf{neg}\left(\left(-t\right)\right)\right) \cdot y + \left(\left(-y\right) \cdot z\right) \cdot z}, x \cdot x\right) \]
      5. add-flipN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\left(\mathsf{neg}\left(\left(-t\right)\right)\right) \cdot y - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right)}, x \cdot x\right) \]
      6. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\left(\mathsf{neg}\left(\left(-t\right)\right)\right) \cdot y - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right)}, x \cdot x\right) \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\left(\mathsf{neg}\left(\left(-t\right) \cdot y\right)\right)} - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, \left(\mathsf{neg}\left(\color{blue}{\left(-t\right) \cdot y}\right)\right) - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      9. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(4, \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(t\right)\right)} \cdot y\right)\right) - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      11. distribute-lft-neg-outN/A

        \[\leadsto \mathsf{fma}\left(4, \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(t \cdot y\right)\right)}\right)\right) - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{t \cdot y}\right)\right)\right)\right) - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{t \cdot y} - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      14. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{t \cdot y} - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{y \cdot t} - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      16. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{y \cdot t} - \left(\mathsf{neg}\left(\left(\left(-y\right) \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      17. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \left(\mathsf{neg}\left(\color{blue}{\left(\left(-y\right) \cdot z\right) \cdot z}\right)\right), x \cdot x\right) \]
      18. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \left(\mathsf{neg}\left(\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot z\right) \cdot z\right)\right), x \cdot x\right) \]
      20. distribute-lft-neg-outN/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(y \cdot z\right)\right)} \cdot z\right)\right), x \cdot x\right) \]
      21. distribute-lft-neg-outN/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(y \cdot z\right) \cdot z\right)\right)}\right)\right), x \cdot x\right) \]
      22. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \color{blue}{\left(y \cdot z\right) \cdot z}, x \cdot x\right) \]
      23. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \color{blue}{\left(y \cdot z\right) \cdot z}, x \cdot x\right) \]
      24. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \color{blue}{\left(z \cdot y\right)} \cdot z, x \cdot x\right) \]
      25. lower-*.f6493.6%

        \[\leadsto \mathsf{fma}\left(4, y \cdot t - \color{blue}{\left(z \cdot y\right)} \cdot z, x \cdot x\right) \]
    5. Applied rewrites93.6%

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

    if 3.39999999999999991e159 < t

    1. Initial program 91.3%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \color{blue}{\left(z \cdot z - t\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + x \cdot x \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(y \cdot 4\right), x \cdot x\right)} \]
      7. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(\color{blue}{4 \cdot y}\right), x \cdot x\right) \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      11. metadata-eval92.4%

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{-4} \cdot y, x \cdot x\right) \]
    3. Applied rewrites92.4%

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

Alternative 4: 93.9% accurate, 0.7× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 7.00000000000000031e303

    1. Initial program 91.3%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \color{blue}{\left(z \cdot z - t\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + x \cdot x \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(y \cdot 4\right), x \cdot x\right)} \]
      7. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(\color{blue}{4 \cdot y}\right), x \cdot x\right) \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      11. metadata-eval92.4%

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{-4} \cdot y, x \cdot x\right) \]
    3. Applied rewrites92.4%

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

    if 7.00000000000000031e303 < (*.f64 x x)

    1. Initial program 91.3%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \color{blue}{\left(z \cdot z - t\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + x \cdot x \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(y \cdot 4\right), x \cdot x\right)} \]
      7. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(\color{blue}{4 \cdot y}\right), x \cdot x\right) \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
      11. metadata-eval92.4%

        \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{-4} \cdot y, x \cdot x\right) \]
    3. Applied rewrites92.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, -4 \cdot y, x \cdot x\right)} \]
    4. Taylor expanded in z around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot t}, -4 \cdot y, x \cdot x\right) \]
    5. Step-by-step derivation
      1. lower-*.f6467.5%

        \[\leadsto \mathsf{fma}\left(-1 \cdot \color{blue}{t}, -4 \cdot y, x \cdot x\right) \]
    6. Applied rewrites67.5%

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

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

        \[\leadsto \left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \color{blue}{x \cdot x} \]
      3. sqr-neg-revN/A

        \[\leadsto \left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
      4. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
      5. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
      6. lift-*.f64N/A

        \[\leadsto \left(-1 \cdot t\right) \cdot \color{blue}{\left(-4 \cdot y\right)} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      8. remove-double-negN/A

        \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \left(\mathsf{neg}\left(\color{blue}{x}\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      9. sqr-neg-revN/A

        \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \color{blue}{x \cdot x} \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \color{blue}{x \cdot x} \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-1 \cdot t\right) \cdot -4, y, x \cdot x\right)} \]
      12. lower-*.f6467.5%

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

        \[\leadsto \mathsf{fma}\left(\left(-1 \cdot \color{blue}{t}\right) \cdot -4, y, x \cdot x\right) \]
      14. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot -4, y, x \cdot x\right) \]
      15. lower-neg.f6467.5%

        \[\leadsto \mathsf{fma}\left(\left(-t\right) \cdot -4, y, x \cdot x\right) \]
    8. Applied rewrites67.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-t\right) \cdot -4, y, x \cdot x\right)} \]
    9. Taylor expanded in z around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{4 \cdot t}, y, x \cdot x\right) \]
    10. Step-by-step derivation
      1. lower-*.f6467.5%

        \[\leadsto \mathsf{fma}\left(4 \cdot \color{blue}{t}, y, x \cdot x\right) \]
    11. Applied rewrites67.5%

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

Alternative 5: 67.5% accurate, 1.5× speedup?

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

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Step-by-step derivation
    1. lift--.f64N/A

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

      \[\leadsto x \cdot x - \color{blue}{\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]
    3. fp-cancel-sub-sign-invN/A

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

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

      \[\leadsto \color{blue}{\left(z \cdot z - t\right) \cdot \left(\mathsf{neg}\left(y \cdot 4\right)\right)} + x \cdot x \]
    6. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(y \cdot 4\right), x \cdot x\right)} \]
    7. lift-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(z \cdot z - t, \mathsf{neg}\left(\color{blue}{4 \cdot y}\right), x \cdot x\right) \]
    9. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
    10. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{\left(\mathsf{neg}\left(4\right)\right) \cdot y}, x \cdot x\right) \]
    11. metadata-eval92.4%

      \[\leadsto \mathsf{fma}\left(z \cdot z - t, \color{blue}{-4} \cdot y, x \cdot x\right) \]
  3. Applied rewrites92.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot z - t, -4 \cdot y, x \cdot x\right)} \]
  4. Taylor expanded in z around 0

    \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot t}, -4 \cdot y, x \cdot x\right) \]
  5. Step-by-step derivation
    1. lower-*.f6467.5%

      \[\leadsto \mathsf{fma}\left(-1 \cdot \color{blue}{t}, -4 \cdot y, x \cdot x\right) \]
  6. Applied rewrites67.5%

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

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

      \[\leadsto \left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \color{blue}{x \cdot x} \]
    3. sqr-neg-revN/A

      \[\leadsto \left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
    4. fp-cancel-sign-sub-invN/A

      \[\leadsto \color{blue}{\left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
    5. fp-cancel-sub-sign-invN/A

      \[\leadsto \color{blue}{\left(-1 \cdot t\right) \cdot \left(-4 \cdot y\right) + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)} \]
    6. lift-*.f64N/A

      \[\leadsto \left(-1 \cdot t\right) \cdot \color{blue}{\left(-4 \cdot y\right)} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
    7. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
    8. remove-double-negN/A

      \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \left(\mathsf{neg}\left(\color{blue}{x}\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
    9. sqr-neg-revN/A

      \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \color{blue}{x \cdot x} \]
    10. lift-*.f64N/A

      \[\leadsto \left(\left(-1 \cdot t\right) \cdot -4\right) \cdot y + \color{blue}{x \cdot x} \]
    11. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-1 \cdot t\right) \cdot -4, y, x \cdot x\right)} \]
    12. lower-*.f6467.5%

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

      \[\leadsto \mathsf{fma}\left(\left(-1 \cdot \color{blue}{t}\right) \cdot -4, y, x \cdot x\right) \]
    14. mul-1-negN/A

      \[\leadsto \mathsf{fma}\left(\left(\mathsf{neg}\left(t\right)\right) \cdot -4, y, x \cdot x\right) \]
    15. lower-neg.f6467.5%

      \[\leadsto \mathsf{fma}\left(\left(-t\right) \cdot -4, y, x \cdot x\right) \]
  8. Applied rewrites67.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-t\right) \cdot -4, y, x \cdot x\right)} \]
  9. Taylor expanded in z around 0

    \[\leadsto \mathsf{fma}\left(\color{blue}{4 \cdot t}, y, x \cdot x\right) \]
  10. Step-by-step derivation
    1. lower-*.f6467.5%

      \[\leadsto \mathsf{fma}\left(4 \cdot \color{blue}{t}, y, x \cdot x\right) \]
  11. Applied rewrites67.5%

    \[\leadsto \mathsf{fma}\left(\color{blue}{4 \cdot t}, y, x \cdot x\right) \]
  12. Add Preprocessing

Alternative 6: 32.3% accurate, 2.6× speedup?

\[4 \cdot \left(t \cdot y\right) \]
(FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
double code(double x, double y, double z, double t) {
	return 4.0 * (t * y);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = 4.0d0 * (t * y)
end function
public static double code(double x, double y, double z, double t) {
	return 4.0 * (t * y);
}
def code(x, y, z, t):
	return 4.0 * (t * y)
function code(x, y, z, t)
	return Float64(4.0 * Float64(t * y))
end
function tmp = code(x, y, z, t)
	tmp = 4.0 * (t * y);
end
code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
4 \cdot \left(t \cdot y\right)
Derivation
  1. Initial program 91.3%

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Taylor expanded in t around inf

    \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto 4 \cdot \color{blue}{\left(t \cdot y\right)} \]
    2. lower-*.f6432.3%

      \[\leadsto 4 \cdot \left(t \cdot \color{blue}{y}\right) \]
  4. Applied rewrites32.3%

    \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025188 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
  :precision binary64
  (- (* x x) (* (* y 4.0) (- (* z z) t))))