
(FPCore (x y z t) :precision binary64 (+ 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)
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]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot z}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ 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)
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]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot z}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ z t) (- y x) x))
double code(double x, double y, double z, double t) {
return fma((z / t), (y - x), x);
}
function code(x, y, z, t) return fma(Float64(z / t), Float64(y - x), x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)
\end{array}
Initial program 93.0%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.8
Applied egg-rr97.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (/ (- y x) t)))) (if (<= z -3.8e+33) t_1 (if (<= z 7e-29) (+ x (/ (* z y) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * ((y - x) / t);
double tmp;
if (z <= -3.8e+33) {
tmp = t_1;
} else if (z <= 7e-29) {
tmp = x + ((z * y) / t);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = z * ((y - x) / t)
if (z <= (-3.8d+33)) then
tmp = t_1
else if (z <= 7d-29) then
tmp = x + ((z * y) / t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z * ((y - x) / t);
double tmp;
if (z <= -3.8e+33) {
tmp = t_1;
} else if (z <= 7e-29) {
tmp = x + ((z * y) / t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = z * ((y - x) / t) tmp = 0 if z <= -3.8e+33: tmp = t_1 elif z <= 7e-29: tmp = x + ((z * y) / t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(z * Float64(Float64(y - x) / t)) tmp = 0.0 if (z <= -3.8e+33) tmp = t_1; elseif (z <= 7e-29) tmp = Float64(x + Float64(Float64(z * y) / t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z * ((y - x) / t); tmp = 0.0; if (z <= -3.8e+33) tmp = t_1; elseif (z <= 7e-29) tmp = x + ((z * y) / t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.8e+33], t$95$1, If[LessEqual[z, 7e-29], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \frac{y - x}{t}\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+33}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-29}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.80000000000000002e33 or 6.9999999999999995e-29 < z Initial program 87.2%
Taylor expanded in z around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6486.5
Simplified86.5%
if -3.80000000000000002e33 < z < 6.9999999999999995e-29Initial program 99.2%
Taylor expanded in y around inf
*-lowering-*.f6488.7
Simplified88.7%
Final simplification87.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (/ (- y x) t)))) (if (<= z -5.8e+35) t_1 (if (<= z 8.2e-29) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * ((y - x) / t);
double tmp;
if (z <= -5.8e+35) {
tmp = t_1;
} else if (z <= 8.2e-29) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(z * Float64(Float64(y - x) / t)) tmp = 0.0 if (z <= -5.8e+35) tmp = t_1; elseif (z <= 8.2e-29) tmp = fma(Float64(z / t), y, x); 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]), $MachinePrecision]}, If[LessEqual[z, -5.8e+35], t$95$1, If[LessEqual[z, 8.2e-29], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \frac{y - x}{t}\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+35}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -5.79999999999999989e35 or 8.1999999999999996e-29 < z Initial program 87.2%
Taylor expanded in z around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6486.5
Simplified86.5%
if -5.79999999999999989e35 < z < 8.1999999999999996e-29Initial program 99.2%
Taylor expanded in y around inf
*-lowering-*.f6488.7
Simplified88.7%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6488.1
Applied egg-rr88.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= t -1.08e-200) t_1 (if (<= t 7.5e-101) (* (/ z t) y) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), z, x);
double tmp;
if (t <= -1.08e-200) {
tmp = t_1;
} else if (t <= 7.5e-101) {
tmp = (z / t) * y;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), z, x) tmp = 0.0 if (t <= -1.08e-200) tmp = t_1; elseif (t <= 7.5e-101) tmp = Float64(Float64(z / t) * y); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[t, -1.08e-200], t$95$1, If[LessEqual[t, 7.5e-101], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{if}\;t \leq -1.08 \cdot 10^{-200}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 7.5 \cdot 10^{-101}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -1.08000000000000002e-200 or 7.5000000000000001e-101 < t Initial program 91.0%
Taylor expanded in y around inf
*-lowering-*.f6474.2
Simplified74.2%
+-commutativeN/A
associate-/l*N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6478.4
Applied egg-rr78.4%
if -1.08000000000000002e-200 < t < 7.5000000000000001e-101Initial program 98.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6451.3
Simplified51.3%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6470.2
Applied egg-rr70.2%
(FPCore (x y z t) :precision binary64 (if (<= t -1.66e+45) x (if (<= t 3e+55) (* (/ z t) y) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.66e+45) {
tmp = x;
} else if (t <= 3e+55) {
tmp = (z / t) * y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-1.66d+45)) then
tmp = x
else if (t <= 3d+55) then
tmp = (z / t) * y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.66e+45) {
tmp = x;
} else if (t <= 3e+55) {
tmp = (z / t) * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.66e+45: tmp = x elif t <= 3e+55: tmp = (z / t) * y else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.66e+45) tmp = x; elseif (t <= 3e+55) tmp = Float64(Float64(z / t) * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.66e+45) tmp = x; elseif (t <= 3e+55) tmp = (z / t) * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.66e+45], x, If[LessEqual[t, 3e+55], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.66 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 3 \cdot 10^{+55}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -1.6599999999999999e45 or 3.00000000000000017e55 < t Initial program 84.0%
Taylor expanded in z around 0
Simplified68.8%
if -1.6599999999999999e45 < t < 3.00000000000000017e55Initial program 98.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6445.9
Simplified45.9%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6454.3
Applied egg-rr54.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (/ y t)))) (if (<= z -7.2e-31) t_1 (if (<= z 1020000000.0) x t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * (y / t);
double tmp;
if (z <= -7.2e-31) {
tmp = t_1;
} else if (z <= 1020000000.0) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = z * (y / t)
if (z <= (-7.2d-31)) then
tmp = t_1
else if (z <= 1020000000.0d0) then
tmp = x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z * (y / t);
double tmp;
if (z <= -7.2e-31) {
tmp = t_1;
} else if (z <= 1020000000.0) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = z * (y / t) tmp = 0 if z <= -7.2e-31: tmp = t_1 elif z <= 1020000000.0: tmp = x else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(z * Float64(y / t)) tmp = 0.0 if (z <= -7.2e-31) tmp = t_1; elseif (z <= 1020000000.0) tmp = x; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z * (y / t); tmp = 0.0; if (z <= -7.2e-31) tmp = t_1; elseif (z <= 1020000000.0) tmp = x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.2e-31], t$95$1, If[LessEqual[z, 1020000000.0], x, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \frac{y}{t}\\
\mathbf{if}\;z \leq -7.2 \cdot 10^{-31}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1020000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -7.20000000000000007e-31 or 1.02e9 < z Initial program 87.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6454.3
Simplified54.3%
if -7.20000000000000007e-31 < z < 1.02e9Initial program 99.3%
Taylor expanded in z around 0
Simplified60.9%
(FPCore (x y z t) :precision binary64 (if (<= x 4.2e+258) (fma (/ z t) y x) (* z (/ (- x) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 4.2e+258) {
tmp = fma((z / t), y, x);
} else {
tmp = z * (-x / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 4.2e+258) tmp = fma(Float64(z / t), y, x); else tmp = Float64(z * Float64(Float64(-x) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 4.2e+258], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(z * N[((-x) / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.2 \cdot 10^{+258}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{t}\\
\end{array}
\end{array}
if x < 4.19999999999999994e258Initial program 92.8%
Taylor expanded in y around inf
*-lowering-*.f6474.0
Simplified74.0%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6478.8
Applied egg-rr78.8%
if 4.19999999999999994e258 < x Initial program 100.0%
Taylor expanded in z around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6485.8
Simplified85.8%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6485.8
Simplified85.8%
(FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
double code(double x, double y, double z, double t) {
return fma((z / t), y, x);
}
function code(x, y, z, t) return fma(Float64(z / t), y, x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y, x\right)
\end{array}
Initial program 93.0%
Taylor expanded in y around inf
*-lowering-*.f6472.4
Simplified72.4%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6477.1
Applied egg-rr77.1%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 93.0%
Taylor expanded in z around 0
Simplified37.3%
(FPCore (x y z t)
:precision binary64
(if (< x -9.025511195533005e-135)
(- x (* (/ z t) (- x y)))
(if (< x 4.275032163700715e-250)
(+ x (* (/ (- y x) t) z))
(+ x (/ (- y x) (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x < -9.025511195533005e-135) {
tmp = x - ((z / t) * (x - y));
} else if (x < 4.275032163700715e-250) {
tmp = x + (((y - x) / t) * z);
} else {
tmp = x + ((y - x) / (t / z));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (x < (-9.025511195533005d-135)) then
tmp = x - ((z / t) * (x - y))
else if (x < 4.275032163700715d-250) then
tmp = x + (((y - x) / t) * z)
else
tmp = x + ((y - x) / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x < -9.025511195533005e-135) {
tmp = x - ((z / t) * (x - y));
} else if (x < 4.275032163700715e-250) {
tmp = x + (((y - x) / t) * z);
} else {
tmp = x + ((y - x) / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x < -9.025511195533005e-135: tmp = x - ((z / t) * (x - y)) elif x < 4.275032163700715e-250: tmp = x + (((y - x) / t) * z) else: tmp = x + ((y - x) / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x < -9.025511195533005e-135) tmp = Float64(x - Float64(Float64(z / t) * Float64(x - y))); elseif (x < 4.275032163700715e-250) tmp = Float64(x + Float64(Float64(Float64(y - x) / t) * z)); else tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x < -9.025511195533005e-135) tmp = x - ((z / t) * (x - y)); elseif (x < 4.275032163700715e-250) tmp = x + (((y - x) / t) * z); else tmp = x + ((y - x) / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Less[x, -9.025511195533005e-135], N[(x - N[(N[(z / t), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Less[x, 4.275032163700715e-250], N[(x + N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\
\;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\
\mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\
\;\;\;\;x + \frac{y - x}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\
\end{array}
\end{array}
herbie shell --seed 2024198
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (if (< x -1805102239106601/200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- x (* (/ z t) (- x y))) (if (< x 855006432740143/2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z))))))
(+ x (/ (* (- y x) z) t)))