
(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 8 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
(let* ((t_1 (+ x (/ (* z (- y x)) t))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 5e+301)))
(+ x (/ z (/ t (- y x))))
t_1)))
double code(double x, double y, double z, double t) {
double t_1 = x + ((z * (y - x)) / t);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 5e+301)) {
tmp = x + (z / (t / (y - x)));
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((z * (y - x)) / t);
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 5e+301)) {
tmp = x + (z / (t / (y - x)));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x + ((z * (y - x)) / t) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 5e+301): tmp = x + (z / (t / (y - x))) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(z * Float64(y - x)) / t)) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 5e+301)) tmp = Float64(x + Float64(z / Float64(t / Float64(y - x)))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + ((z * (y - x)) / t); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 5e+301))) tmp = x + (z / (t / (y - x))); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 5e+301]], $MachinePrecision]], N[(x + N[(z / N[(t / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{z \cdot \left(y - x\right)}{t}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+301}\right):\\
\;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -inf.0 or 5.0000000000000004e301 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) Initial program 76.0%
associate-/l*99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Taylor expanded in t around 0 76.0%
associate-/l*99.9%
Simplified99.9%
if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 5.0000000000000004e301Initial program 98.7%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (+ x (pow (/ (/ t z) (- y x)) -1.0)))
double code(double x, double y, double z, double t) {
return x + pow(((t / z) / (y - x)), -1.0);
}
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 + (((t / z) / (y - x)) ** (-1.0d0))
end function
public static double code(double x, double y, double z, double t) {
return x + Math.pow(((t / z) / (y - x)), -1.0);
}
def code(x, y, z, t): return x + math.pow(((t / z) / (y - x)), -1.0)
function code(x, y, z, t) return Float64(x + (Float64(Float64(t / z) / Float64(y - x)) ^ -1.0)) end
function tmp = code(x, y, z, t) tmp = x + (((t / z) / (y - x)) ^ -1.0); end
code[x_, y_, z_, t_] := N[(x + N[Power[N[(N[(t / z), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + {\left(\frac{\frac{t}{z}}{y - x}\right)}^{-1}
\end{array}
Initial program 91.3%
associate-/l*98.6%
clear-num98.6%
inv-pow98.6%
Applied egg-rr98.6%
Final simplification98.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1e-169) (not (<= z 7.5e-213))) (+ x (* z (/ (- y x) t))) (+ x (/ y (/ t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1e-169) || !(z <= 7.5e-213)) {
tmp = x + (z * ((y - x) / t));
} else {
tmp = x + (y / (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 ((z <= (-1d-169)) .or. (.not. (z <= 7.5d-213))) then
tmp = x + (z * ((y - x) / t))
else
tmp = x + (y / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1e-169) || !(z <= 7.5e-213)) {
tmp = x + (z * ((y - x) / t));
} else {
tmp = x + (y / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1e-169) or not (z <= 7.5e-213): tmp = x + (z * ((y - x) / t)) else: tmp = x + (y / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1e-169) || !(z <= 7.5e-213)) tmp = Float64(x + Float64(z * Float64(Float64(y - x) / t))); else tmp = Float64(x + Float64(y / Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1e-169) || ~((z <= 7.5e-213))) tmp = x + (z * ((y - x) / t)); else tmp = x + (y / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1e-169], N[Not[LessEqual[z, 7.5e-213]], $MachinePrecision]], N[(x + N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-169} \lor \neg \left(z \leq 7.5 \cdot 10^{-213}\right):\\
\;\;\;\;x + z \cdot \frac{y - x}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z}}\\
\end{array}
\end{array}
if z < -1.00000000000000002e-169 or 7.5000000000000006e-213 < z Initial program 89.2%
associate-*l/97.0%
Applied egg-rr97.0%
if -1.00000000000000002e-169 < z < 7.5000000000000006e-213Initial program 98.3%
associate-/l*98.3%
clear-num98.3%
inv-pow98.3%
Applied egg-rr98.3%
Taylor expanded in y around inf 93.8%
*-commutative93.8%
associate-*r/76.4%
Simplified76.4%
associate-*r/93.8%
associate-*l/93.8%
*-commutative93.8%
clear-num93.8%
un-div-inv93.9%
Applied egg-rr93.9%
Final simplification96.3%
(FPCore (x y z t) :precision binary64 (if (<= z -6e-170) (+ x (/ z (/ t (- y x)))) (if (<= z 9e-213) (+ x (/ y (/ t z))) (+ x (* z (/ (- y x) t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6e-170) {
tmp = x + (z / (t / (y - x)));
} else if (z <= 9e-213) {
tmp = x + (y / (t / z));
} else {
tmp = x + (z * ((y - x) / 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 (z <= (-6d-170)) then
tmp = x + (z / (t / (y - x)))
else if (z <= 9d-213) then
tmp = x + (y / (t / z))
else
tmp = x + (z * ((y - x) / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6e-170) {
tmp = x + (z / (t / (y - x)));
} else if (z <= 9e-213) {
tmp = x + (y / (t / z));
} else {
tmp = x + (z * ((y - x) / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -6e-170: tmp = x + (z / (t / (y - x))) elif z <= 9e-213: tmp = x + (y / (t / z)) else: tmp = x + (z * ((y - x) / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -6e-170) tmp = Float64(x + Float64(z / Float64(t / Float64(y - x)))); elseif (z <= 9e-213) tmp = Float64(x + Float64(y / Float64(t / z))); else tmp = Float64(x + Float64(z * Float64(Float64(y - x) / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -6e-170) tmp = x + (z / (t / (y - x))); elseif (z <= 9e-213) tmp = x + (y / (t / z)); else tmp = x + (z * ((y - x) / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -6e-170], N[(x + N[(z / N[(t / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9e-213], N[(x + N[(y / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-170}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-213}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z}}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y - x}{t}\\
\end{array}
\end{array}
if z < -6.00000000000000027e-170Initial program 88.6%
associate-/l*98.0%
clear-num98.1%
inv-pow98.1%
Applied egg-rr98.1%
Taylor expanded in t around 0 88.6%
associate-/l*96.3%
Simplified96.3%
if -6.00000000000000027e-170 < z < 9.0000000000000002e-213Initial program 98.3%
associate-/l*98.3%
clear-num98.3%
inv-pow98.3%
Applied egg-rr98.3%
Taylor expanded in y around inf 93.8%
*-commutative93.8%
associate-*r/76.4%
Simplified76.4%
associate-*r/93.8%
associate-*l/93.8%
*-commutative93.8%
clear-num93.8%
un-div-inv93.9%
Applied egg-rr93.9%
if 9.0000000000000002e-213 < z Initial program 89.8%
associate-*l/97.9%
Applied egg-rr97.9%
Final simplification96.3%
(FPCore (x y z t) :precision binary64 (if (or (<= x -7e+64) (not (<= x 2.6e+42))) (* x (- 1.0 (/ z t))) (+ x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -7e+64) || !(x <= 2.6e+42)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (y * (z / 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 <= (-7d+64)) .or. (.not. (x <= 2.6d+42))) then
tmp = x * (1.0d0 - (z / t))
else
tmp = x + (y * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -7e+64) || !(x <= 2.6e+42)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -7e+64) or not (x <= 2.6e+42): tmp = x * (1.0 - (z / t)) else: tmp = x + (y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -7e+64) || !(x <= 2.6e+42)) tmp = Float64(x * Float64(1.0 - Float64(z / t))); else tmp = Float64(x + Float64(y * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -7e+64) || ~((x <= 2.6e+42))) tmp = x * (1.0 - (z / t)); else tmp = x + (y * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -7e+64], N[Not[LessEqual[x, 2.6e+42]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+64} \lor \neg \left(x \leq 2.6 \cdot 10^{+42}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if x < -6.9999999999999997e64 or 2.5999999999999999e42 < x Initial program 87.7%
Taylor expanded in x around inf 96.4%
mul-1-neg96.4%
unsub-neg96.4%
Simplified96.4%
if -6.9999999999999997e64 < x < 2.5999999999999999e42Initial program 94.3%
Taylor expanded in y around inf 82.7%
associate-*r/87.2%
Simplified87.2%
Final simplification91.3%
(FPCore (x y z t) :precision binary64 (+ x (/ (- y x) (/ t z))))
double code(double x, double y, double z, double t) {
return x + ((y - x) / (t / z));
}
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) / (t / z))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - x) / (t / z));
}
def code(x, y, z, t): return x + ((y - x) / (t / z))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - x) / Float64(t / z))) end
function tmp = code(x, y, z, t) tmp = x + ((y - x) / (t / z)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{\frac{t}{z}}
\end{array}
Initial program 91.3%
associate-/l*98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ z t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (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 * (1.0d0 - (z / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (z / t));
}
def code(x, y, z, t): return x * (1.0 - (z / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (z / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{z}{t}\right)
\end{array}
Initial program 91.3%
Taylor expanded in x around inf 73.1%
mul-1-neg73.1%
unsub-neg73.1%
Simplified73.1%
Final simplification73.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 91.3%
Taylor expanded in z around 0 45.8%
Final simplification45.8%
(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 2024021
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:herbie-target
(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)))))
(+ x (/ (* (- y x) z) t)))