
(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 6 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 94.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.75e-44) (not (<= x 1.28e+42))) (* (- 1.0 (/ z t)) x) (+ x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.75e-44) || !(x <= 1.28e+42)) {
tmp = (1.0 - (z / t)) * x;
} else {
tmp = x + ((z * y) / t);
}
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 <= (-1.75d-44)) .or. (.not. (x <= 1.28d+42))) then
tmp = (1.0d0 - (z / t)) * x
else
tmp = x + ((z * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.75e-44) || !(x <= 1.28e+42)) {
tmp = (1.0 - (z / t)) * x;
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.75e-44) or not (x <= 1.28e+42): tmp = (1.0 - (z / t)) * x else: tmp = x + ((z * y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.75e-44) || !(x <= 1.28e+42)) tmp = Float64(Float64(1.0 - Float64(z / t)) * x); else tmp = Float64(x + Float64(Float64(z * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.75e-44) || ~((x <= 1.28e+42))) tmp = (1.0 - (z / t)) * x; else tmp = x + ((z * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.75e-44], N[Not[LessEqual[x, 1.28e+42]], $MachinePrecision]], N[(N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-44} \lor \neg \left(x \leq 1.28 \cdot 10^{+42}\right):\\
\;\;\;\;\left(1 - \frac{z}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if x < -1.7499999999999999e-44 or 1.28000000000000004e42 < x Initial program 88.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6487.3
Applied rewrites87.3%
if -1.7499999999999999e-44 < x < 1.28000000000000004e42Initial program 99.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6491.6
Applied rewrites91.6%
Final simplification89.7%
(FPCore (x y z t) :precision binary64 (if (or (<= x -310000000000.0) (not (<= x 2.05e+71))) (* (- 1.0 (/ z t)) x) (fma (/ y t) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -310000000000.0) || !(x <= 2.05e+71)) {
tmp = (1.0 - (z / t)) * x;
} else {
tmp = fma((y / t), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((x <= -310000000000.0) || !(x <= 2.05e+71)) tmp = Float64(Float64(1.0 - Float64(z / t)) * x); else tmp = fma(Float64(y / t), z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -310000000000.0], N[Not[LessEqual[x, 2.05e+71]], $MachinePrecision]], N[(N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -310000000000 \lor \neg \left(x \leq 2.05 \cdot 10^{+71}\right):\\
\;\;\;\;\left(1 - \frac{z}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\end{array}
\end{array}
if x < -3.1e11 or 2.0500000000000001e71 < x Initial program 91.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6492.1
Applied rewrites92.1%
if -3.1e11 < x < 2.0500000000000001e71Initial program 96.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.7
Applied rewrites94.7%
Taylor expanded in x around 0
lower-/.f6485.1
Applied rewrites85.1%
Final simplification87.7%
(FPCore (x y z t) :precision binary64 (if (<= z -5.2e+169) (* (- x) (/ z t)) (fma (/ y t) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.2e+169) {
tmp = -x * (z / t);
} else {
tmp = fma((y / t), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -5.2e+169) tmp = Float64(Float64(-x) * Float64(z / t)); else tmp = fma(Float64(y / t), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.2e+169], N[((-x) * N[(z / t), $MachinePrecision]), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+169}:\\
\;\;\;\;\left(-x\right) \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\end{array}
\end{array}
if z < -5.19999999999999999e169Initial program 90.9%
Taylor expanded in z around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6496.9
Applied rewrites96.9%
Taylor expanded in x around inf
Applied rewrites70.5%
Applied rewrites75.2%
if -5.19999999999999999e169 < z Initial program 94.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.0
Applied rewrites93.0%
Taylor expanded in x around 0
lower-/.f6478.8
Applied rewrites78.8%
(FPCore (x y z t) :precision binary64 (fma (/ y t) z x))
double code(double x, double y, double z, double t) {
return fma((y / t), z, x);
}
function code(x, y, z, t) return fma(Float64(y / t), z, x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z, x\right)
\end{array}
Initial program 94.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.3
Applied rewrites93.3%
Taylor expanded in x around 0
lower-/.f6476.3
Applied rewrites76.3%
(FPCore (x y z t) :precision binary64 (* y (/ z t)))
double code(double x, double y, double z, double t) {
return y * (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 = y * (z / t)
end function
public static double code(double x, double y, double z, double t) {
return y * (z / t);
}
def code(x, y, z, t): return y * (z / t)
function code(x, y, z, t) return Float64(y * Float64(z / t)) end
function tmp = code(x, y, z, t) tmp = y * (z / t); end
code[x_, y_, z_, t_] := N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{z}{t}
\end{array}
Initial program 94.3%
Taylor expanded in x around 0
associate-*l/N/A
lower-*.f64N/A
lower-/.f6440.7
Applied rewrites40.7%
Applied rewrites42.9%
(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 2024320
(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)))