Numeric.Histogram:binBounds from Chart-1.5.3

Percentage Accurate: 92.6% → 97.7%
Time: 2.3s
Alternatives: 4
Speedup: 1.0×

Specification

?
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (+ x (/ (* (- y x) z) t)))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + (((y - x) * z) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
def code(x, y, z, t):
	return x + (((y - x) * z) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + (((y - x) * z) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	x + (((y - x) * z) / t)
END code
x + \frac{\left(y - x\right) \cdot z}{t}

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

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (+ x (/ (* (- y x) z) t)))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + (((y - x) * z) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
def code(x, y, z, t):
	return x + (((y - x) * z) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + (((y - x) * z) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	x + (((y - x) * z) / t)
END code
x + \frac{\left(y - x\right) \cdot z}{t}

Alternative 1: 97.7% accurate, 1.0× speedup?

\[\mathsf{fma}\left(y - x, \frac{z}{t}, x\right) \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (fma (- y x) (/ z t) x))
double code(double x, double y, double z, double t) {
	return fma((y - x), (z / t), x);
}
function code(x, y, z, t)
	return fma(Float64(y - x), Float64(z / t), x)
end
code[x_, y_, z_, t_] := N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	((y - x) * (z / t)) + x
END code
\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)
Derivation
  1. Initial program 92.6%

    \[x + \frac{\left(y - x\right) \cdot z}{t} \]
  2. Step-by-step derivation
    1. Applied rewrites97.7%

      \[\leadsto \mathsf{fma}\left(y - x, \frac{z}{t}, x\right) \]
    2. Add Preprocessing

    Alternative 2: 95.0% accurate, 0.6× speedup?

    \[\begin{array}{l} t_1 := \mathsf{fma}\left(z, \frac{y - x}{t}, x\right)\\ \mathbf{if}\;z \leq -4.728533899018201 \cdot 10^{-139}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 6.252784341431828 \cdot 10^{-144}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
    (FPCore (x y z t)
      :precision binary64
      :pre TRUE
      (let* ((t_1 (fma z (/ (- y x) t) x)))
      (if (<= z -4.728533899018201e-139)
        t_1
        (if (<= z 6.252784341431828e-144) (+ x (/ (* y z) t)) t_1))))
    double code(double x, double y, double z, double t) {
    	double t_1 = fma(z, ((y - x) / t), x);
    	double tmp;
    	if (z <= -4.728533899018201e-139) {
    		tmp = t_1;
    	} else if (z <= 6.252784341431828e-144) {
    		tmp = x + ((y * z) / t);
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    function code(x, y, z, t)
    	t_1 = fma(z, Float64(Float64(y - x) / t), x)
    	tmp = 0.0
    	if (z <= -4.728533899018201e-139)
    		tmp = t_1;
    	elseif (z <= 6.252784341431828e-144)
    		tmp = Float64(x + Float64(Float64(y * z) / t));
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -4.728533899018201e-139], t$95$1, If[LessEqual[z, 6.252784341431828e-144], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
    
    f(x, y, z, t):
    	x in [-inf, +inf],
    	y in [-inf, +inf],
    	z in [-inf, +inf],
    	t in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y, z, t: real): real =
    	LET t_1 = ((z * ((y - x) / t)) + x) IN
    		LET tmp_1 = IF (z <= (62527843414318284319719186882294129945665249758899645478466771126279286229732234053854960031919877088596234922290488433363746527256442759741628772655174069142188068917128278829357567423586008842545337851794968377781359039242519844761653512788956608172266090888065588382911232572899901562758371090199375151908011040129850746210936354266374617195956009396695662871934473514556884765625e-526)) THEN (x + ((y * z) / t)) ELSE t_1 ENDIF IN
    		LET tmp = IF (z <= (-4728533899018200774641182461610982058121710058363072129266127018695922885542054899446073763047811518160217172628469730287682553638056889081744717244442655850490171087568147235982100242987047427902356625302140388120547202609837905052830333942549129578531123285954401523057544004834867761435383436144458441063639988092998275693600355139289970196614376618526875972747802734375e-511)) THEN t_1 ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    t_1 := \mathsf{fma}\left(z, \frac{y - x}{t}, x\right)\\
    \mathbf{if}\;z \leq -4.728533899018201 \cdot 10^{-139}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;z \leq 6.252784341431828 \cdot 10^{-144}:\\
    \;\;\;\;x + \frac{y \cdot z}{t}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z < -4.7285338990182008e-139 or 6.2527843414318284e-144 < z

      1. Initial program 92.6%

        \[x + \frac{\left(y - x\right) \cdot z}{t} \]
      2. Step-by-step derivation
        1. Applied rewrites92.4%

          \[\leadsto \mathsf{fma}\left(z, \frac{y - x}{t}, x\right) \]

        if -4.7285338990182008e-139 < z < 6.2527843414318284e-144

        1. Initial program 92.6%

          \[x + \frac{\left(y - x\right) \cdot z}{t} \]
        2. Taylor expanded in x around 0

          \[\leadsto x + \frac{y \cdot z}{t} \]
        3. Step-by-step derivation
          1. Applied rewrites73.0%

            \[\leadsto x + \frac{y \cdot z}{t} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 3: 76.4% accurate, 1.3× speedup?

        \[\mathsf{fma}\left(y, \frac{z}{t}, x\right) \]
        (FPCore (x y z t)
          :precision binary64
          :pre TRUE
          (fma y (/ z t) x))
        double code(double x, double y, double z, double t) {
        	return fma(y, (z / t), x);
        }
        
        function code(x, y, z, t)
        	return fma(y, Float64(z / t), x)
        end
        
        code[x_, y_, z_, t_] := N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
        
        f(x, y, z, t):
        	x in [-inf, +inf],
        	y in [-inf, +inf],
        	z in [-inf, +inf],
        	t in [-inf, +inf]
        code: THEORY
        BEGIN
        f(x, y, z, t: real): real =
        	(y * (z / t)) + x
        END code
        \mathsf{fma}\left(y, \frac{z}{t}, x\right)
        
        Derivation
        1. Initial program 92.6%

          \[x + \frac{\left(y - x\right) \cdot z}{t} \]
        2. Taylor expanded in x around 0

          \[\leadsto x + \frac{y \cdot z}{t} \]
        3. Step-by-step derivation
          1. Applied rewrites73.0%

            \[\leadsto x + \frac{y \cdot z}{t} \]
          2. Step-by-step derivation
            1. Applied rewrites76.4%

              \[\leadsto \mathsf{fma}\left(y, \frac{z}{t}, x\right) \]
            2. Add Preprocessing

            Alternative 4: 72.8% accurate, 1.3× speedup?

            \[\mathsf{fma}\left(z, \frac{y}{t}, x\right) \]
            (FPCore (x y z t)
              :precision binary64
              :pre TRUE
              (fma z (/ y t) x))
            double code(double x, double y, double z, double t) {
            	return fma(z, (y / t), x);
            }
            
            function code(x, y, z, t)
            	return fma(z, Float64(y / t), x)
            end
            
            code[x_, y_, z_, t_] := N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision]
            
            f(x, y, z, t):
            	x in [-inf, +inf],
            	y in [-inf, +inf],
            	z in [-inf, +inf],
            	t in [-inf, +inf]
            code: THEORY
            BEGIN
            f(x, y, z, t: real): real =
            	(z * (y / t)) + x
            END code
            \mathsf{fma}\left(z, \frac{y}{t}, x\right)
            
            Derivation
            1. Initial program 92.6%

              \[x + \frac{\left(y - x\right) \cdot z}{t} \]
            2. Taylor expanded in x around 0

              \[\leadsto x + \frac{y \cdot z}{t} \]
            3. Step-by-step derivation
              1. Applied rewrites73.0%

                \[\leadsto x + \frac{y \cdot z}{t} \]
              2. Step-by-step derivation
                1. Applied rewrites72.8%

                  \[\leadsto \mathsf{fma}\left(z, \frac{y}{t}, x\right) \]
                2. Add Preprocessing

                Reproduce

                ?
                herbie shell --seed 2026092 
                (FPCore (x y z t)
                  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
                  :precision binary64
                  (+ x (/ (* (- y x) z) t)))