simple fma test

Percentage Accurate: 29.6% → 100.0%
Time: 1.8s
Alternatives: 1
Speedup: 16.8×

Specification

?
\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right) \]
(FPCore (x y z)
  :precision binary64
  :pre TRUE
  (- (fma x y z) (+ 1.0 (+ (* x y) z))))
double code(double x, double y, double z) {
	return fma(x, y, z) - (1.0 + ((x * y) + z));
}
function code(x, y, z)
	return Float64(fma(x, y, z) - Float64(1.0 + Float64(Float64(x * y) + z)))
end
code[x_, y_, z_] := N[(N[(x * y + z), $MachinePrecision] - N[(1.0 + N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z: real): real =
	((x * y) + z) - ((1) + ((x * y) + z))
END code
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\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 1 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: 29.6% accurate, 1.0× speedup?

\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right) \]
(FPCore (x y z)
  :precision binary64
  :pre TRUE
  (- (fma x y z) (+ 1.0 (+ (* x y) z))))
double code(double x, double y, double z) {
	return fma(x, y, z) - (1.0 + ((x * y) + z));
}
function code(x, y, z)
	return Float64(fma(x, y, z) - Float64(1.0 + Float64(Float64(x * y) + z)))
end
code[x_, y_, z_] := N[(N[(x * y + z), $MachinePrecision] - N[(1.0 + N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z: real): real =
	((x * y) + z) - ((1) + ((x * y) + z))
END code
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)

Alternative 1: 100.0% accurate, 16.8× speedup?

\[-1 \]
(FPCore (x y z)
  :precision binary64
  :pre TRUE
  -1.0)
double code(double x, double y, double z) {
	return -1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = -1.0d0
end function
public static double code(double x, double y, double z) {
	return -1.0;
}
def code(x, y, z):
	return -1.0
function code(x, y, z)
	return -1.0
end
function tmp = code(x, y, z)
	tmp = -1.0;
end
code[x_, y_, z_] := -1.0
f(x, y, z):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z: real): real =
	-1
END code
-1
Derivation
  1. Initial program 29.6%

    \[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right) \]
  2. Taylor expanded in x around 0

    \[\leadsto -1 \]
  3. Step-by-step derivation
    1. Applied rewrites100.0%

      \[\leadsto -1 \]
    2. Add Preprocessing

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

    \[-1 \]
    (FPCore (x y z)
      :precision binary64
      :pre TRUE
      -1.0)
    double code(double x, double y, double z) {
    	return -1.0;
    }
    
    real(8) function code(x, y, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        code = -1.0d0
    end function
    
    public static double code(double x, double y, double z) {
    	return -1.0;
    }
    
    def code(x, y, z):
    	return -1.0
    
    function code(x, y, z)
    	return -1.0
    end
    
    function tmp = code(x, y, z)
    	tmp = -1.0;
    end
    
    code[x_, y_, z_] := -1.0
    
    f(x, y, z):
    	x in [-inf, +inf],
    	y in [-inf, +inf],
    	z in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y, z: real): real =
    	-1
    END code
    -1
    

    Reproduce

    ?
    herbie shell --seed 2025363 
    (FPCore (x y z)
      :name "simple fma test"
      :precision binary64
    
      :alt
      (! :herbie-platform c -1)
    
      (- (fma x y z) (+ 1.0 (+ (* x y) z))))