
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
double code(double x, double y, double z, double t) {
return x / (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 = x / (y - (z * t))
end function
public static double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
def code(x, y, z, t): return x / (y - (z * t))
function code(x, y, z, t) return Float64(x / Float64(y - Float64(z * t))) end
function tmp = code(x, y, z, t) tmp = x / (y - (z * t)); end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y - z \cdot t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
double code(double x, double y, double z, double t) {
return x / (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 = x / (y - (z * t))
end function
public static double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
def code(x, y, z, t): return x / (y - (z * t))
function code(x, y, z, t) return Float64(x / Float64(y - Float64(z * t))) end
function tmp = code(x, y, z, t) tmp = x / (y - (z * t)); end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y - z \cdot t}
\end{array}
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (* z t) (- INFINITY)) (/ (/ (- x) t) z) (if (<= (* z t) 2e+254) (/ x (fma (- z) t y)) (/ 1.0 (* t (/ (- z) x))))))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -((double) INFINITY)) {
tmp = (-x / t) / z;
} else if ((z * t) <= 2e+254) {
tmp = x / fma(-z, t, y);
} else {
tmp = 1.0 / (t * (-z / x));
}
return tmp;
}
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= Float64(-Inf)) tmp = Float64(Float64(Float64(-x) / t) / z); elseif (Float64(z * t) <= 2e+254) tmp = Float64(x / fma(Float64(-z), t, y)); else tmp = Float64(1.0 / Float64(t * Float64(Float64(-z) / x))); end return tmp end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+254], N[(x / N[((-z) * t + y), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(t * N[((-z) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+254}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t \cdot \frac{-z}{x}}\\
\end{array}
\end{array}
if (*.f64 z t) < -inf.0Initial program 60.8%
clear-num60.8%
associate-/r/60.8%
Applied egg-rr60.8%
Taylor expanded in y around 0 60.8%
mul-1-neg60.8%
associate-/r*100.0%
distribute-neg-frac100.0%
Simplified100.0%
if -inf.0 < (*.f64 z t) < 1.9999999999999999e254Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
distribute-lft-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
if 1.9999999999999999e254 < (*.f64 z t) Initial program 69.6%
clear-num69.6%
inv-pow69.6%
Applied egg-rr69.6%
div-sub66.0%
associate-/l*96.3%
Applied egg-rr96.3%
unpow-196.3%
associate-/r/96.2%
Applied egg-rr96.2%
Taylor expanded in y around 0 69.6%
associate-*r/69.6%
mul-1-neg69.6%
distribute-rgt-neg-in69.6%
associate-*r/99.8%
Simplified99.8%
Final simplification99.8%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (* z t) (- INFINITY)) (/ (/ (- x) t) z) (if (<= (* z t) 2e+254) (/ x (- y (* z t))) (/ 1.0 (* t (/ (- z) x))))))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -((double) INFINITY)) {
tmp = (-x / t) / z;
} else if ((z * t) <= 2e+254) {
tmp = x / (y - (z * t));
} else {
tmp = 1.0 / (t * (-z / x));
}
return tmp;
}
assert z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -Double.POSITIVE_INFINITY) {
tmp = (-x / t) / z;
} else if ((z * t) <= 2e+254) {
tmp = x / (y - (z * t));
} else {
tmp = 1.0 / (t * (-z / x));
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if (z * t) <= -math.inf: tmp = (-x / t) / z elif (z * t) <= 2e+254: tmp = x / (y - (z * t)) else: tmp = 1.0 / (t * (-z / x)) return tmp
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= Float64(-Inf)) tmp = Float64(Float64(Float64(-x) / t) / z); elseif (Float64(z * t) <= 2e+254) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(1.0 / Float64(t * Float64(Float64(-z) / x))); end return tmp end
z, t = num2cell(sort([z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z * t) <= -Inf)
tmp = (-x / t) / z;
elseif ((z * t) <= 2e+254)
tmp = x / (y - (z * t));
else
tmp = 1.0 / (t * (-z / x));
end
tmp_2 = tmp;
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+254], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(t * N[((-z) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+254}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t \cdot \frac{-z}{x}}\\
\end{array}
\end{array}
if (*.f64 z t) < -inf.0Initial program 60.8%
clear-num60.8%
associate-/r/60.8%
Applied egg-rr60.8%
Taylor expanded in y around 0 60.8%
mul-1-neg60.8%
associate-/r*100.0%
distribute-neg-frac100.0%
Simplified100.0%
if -inf.0 < (*.f64 z t) < 1.9999999999999999e254Initial program 99.8%
if 1.9999999999999999e254 < (*.f64 z t) Initial program 69.6%
clear-num69.6%
inv-pow69.6%
Applied egg-rr69.6%
div-sub66.0%
associate-/l*96.3%
Applied egg-rr96.3%
unpow-196.3%
associate-/r/96.2%
Applied egg-rr96.2%
Taylor expanded in y around 0 69.6%
associate-*r/69.6%
mul-1-neg69.6%
distribute-rgt-neg-in69.6%
associate-*r/99.8%
Simplified99.8%
Final simplification99.8%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= (* z t) (- INFINITY)) (not (<= (* z t) 2e+272))) (/ (/ (- x) t) z) (/ x (- y (* z t)))))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -((double) INFINITY)) || !((z * t) <= 2e+272)) {
tmp = (-x / t) / z;
} else {
tmp = x / (y - (z * t));
}
return tmp;
}
assert z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -Double.POSITIVE_INFINITY) || !((z * t) <= 2e+272)) {
tmp = (-x / t) / z;
} else {
tmp = x / (y - (z * t));
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if ((z * t) <= -math.inf) or not ((z * t) <= 2e+272): tmp = (-x / t) / z else: tmp = x / (y - (z * t)) return tmp
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= Float64(-Inf)) || !(Float64(z * t) <= 2e+272)) tmp = Float64(Float64(Float64(-x) / t) / z); else tmp = Float64(x / Float64(y - Float64(z * t))); end return tmp end
z, t = num2cell(sort([z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (((z * t) <= -Inf) || ~(((z * t) <= 2e+272)))
tmp = (-x / t) / z;
else
tmp = x / (y - (z * t));
end
tmp_2 = tmp;
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+272]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+272}\right):\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\end{array}
\end{array}
if (*.f64 z t) < -inf.0 or 2.0000000000000001e272 < (*.f64 z t) Initial program 64.9%
clear-num64.9%
associate-/r/64.8%
Applied egg-rr64.8%
Taylor expanded in y around 0 64.9%
mul-1-neg64.9%
associate-/r*100.0%
distribute-neg-frac100.0%
Simplified100.0%
if -inf.0 < (*.f64 z t) < 2.0000000000000001e272Initial program 99.8%
Final simplification99.9%
NOTE: z and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(if (<= y -1.5e+26)
(/ x y)
(if (or (<= y 4.6e-147) (and (not (<= y 2.35e-99)) (<= y 34000.0)))
(/ (- x) (* z t))
(/ x y))))assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+26) {
tmp = x / y;
} else if ((y <= 4.6e-147) || (!(y <= 2.35e-99) && (y <= 34000.0))) {
tmp = -x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
NOTE: z and t should be sorted in increasing order before calling this function.
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 (y <= (-1.5d+26)) then
tmp = x / y
else if ((y <= 4.6d-147) .or. (.not. (y <= 2.35d-99)) .and. (y <= 34000.0d0)) then
tmp = -x / (z * t)
else
tmp = x / y
end if
code = tmp
end function
assert z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+26) {
tmp = x / y;
} else if ((y <= 4.6e-147) || (!(y <= 2.35e-99) && (y <= 34000.0))) {
tmp = -x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if y <= -1.5e+26: tmp = x / y elif (y <= 4.6e-147) or (not (y <= 2.35e-99) and (y <= 34000.0)): tmp = -x / (z * t) else: tmp = x / y return tmp
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -1.5e+26) tmp = Float64(x / y); elseif ((y <= 4.6e-147) || (!(y <= 2.35e-99) && (y <= 34000.0))) tmp = Float64(Float64(-x) / Float64(z * t)); else tmp = Float64(x / y); end return tmp end
z, t = num2cell(sort([z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -1.5e+26)
tmp = x / y;
elseif ((y <= 4.6e-147) || (~((y <= 2.35e-99)) && (y <= 34000.0)))
tmp = -x / (z * t);
else
tmp = x / y;
end
tmp_2 = tmp;
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[y, -1.5e+26], N[(x / y), $MachinePrecision], If[Or[LessEqual[y, 4.6e-147], And[N[Not[LessEqual[y, 2.35e-99]], $MachinePrecision], LessEqual[y, 34000.0]]], N[((-x) / N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+26}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{-147} \lor \neg \left(y \leq 2.35 \cdot 10^{-99}\right) \land y \leq 34000:\\
\;\;\;\;\frac{-x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -1.49999999999999999e26 or 4.59999999999999981e-147 < y < 2.34999999999999995e-99 or 34000 < y Initial program 90.8%
Taylor expanded in y around inf 76.7%
if -1.49999999999999999e26 < y < 4.59999999999999981e-147 or 2.34999999999999995e-99 < y < 34000Initial program 95.0%
Taylor expanded in y around 0 79.3%
associate-*r/79.3%
neg-mul-179.3%
Simplified79.3%
Final simplification78.0%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -1.75e+22) (not (<= z 8.2e-44))) (/ (/ (- x) t) z) (/ x y)))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.75e+22) || !(z <= 8.2e-44)) {
tmp = (-x / t) / z;
} else {
tmp = x / y;
}
return tmp;
}
NOTE: z and t should be sorted in increasing order before calling this function.
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 <= (-1.75d+22)) .or. (.not. (z <= 8.2d-44))) then
tmp = (-x / t) / z
else
tmp = x / y
end if
code = tmp
end function
assert z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.75e+22) || !(z <= 8.2e-44)) {
tmp = (-x / t) / z;
} else {
tmp = x / y;
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if (z <= -1.75e+22) or not (z <= 8.2e-44): tmp = (-x / t) / z else: tmp = x / y return tmp
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -1.75e+22) || !(z <= 8.2e-44)) tmp = Float64(Float64(Float64(-x) / t) / z); else tmp = Float64(x / y); end return tmp end
z, t = num2cell(sort([z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -1.75e+22) || ~((z <= 8.2e-44)))
tmp = (-x / t) / z;
else
tmp = x / y;
end
tmp_2 = tmp;
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.75e+22], N[Not[LessEqual[z, 8.2e-44]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+22} \lor \neg \left(z \leq 8.2 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if z < -1.75e22 or 8.19999999999999984e-44 < z Initial program 87.6%
clear-num87.1%
associate-/r/87.4%
Applied egg-rr87.4%
Taylor expanded in y around 0 67.8%
mul-1-neg67.8%
associate-/r*75.9%
distribute-neg-frac75.9%
Simplified75.9%
if -1.75e22 < z < 8.19999999999999984e-44Initial program 99.0%
Taylor expanded in y around inf 71.3%
Final simplification73.8%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (/ x y))
assert(z < t);
double code(double x, double y, double z, double t) {
return x / y;
}
NOTE: z and t should be sorted in increasing order before calling this function.
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
end function
assert z < t;
public static double code(double x, double y, double z, double t) {
return x / y;
}
[z, t] = sort([z, t]) def code(x, y, z, t): return x / y
z, t = sort([z, t]) function code(x, y, z, t) return Float64(x / y) end
z, t = num2cell(sort([z, t])){:}
function tmp = code(x, y, z, t)
tmp = x / y;
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\frac{x}{y}
\end{array}
Initial program 92.9%
Taylor expanded in y around inf 50.4%
Final simplification50.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ 1.0 (- (/ y x) (* (/ z x) t)))))
(if (< x -1.618195973607049e+50)
t_1
(if (< x 2.1378306434876444e+131) (/ x (- y (* z t))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = 1.0 / ((y / x) - ((z / x) * t));
double tmp;
if (x < -1.618195973607049e+50) {
tmp = t_1;
} else if (x < 2.1378306434876444e+131) {
tmp = x / (y - (z * 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 = 1.0d0 / ((y / x) - ((z / x) * t))
if (x < (-1.618195973607049d+50)) then
tmp = t_1
else if (x < 2.1378306434876444d+131) then
tmp = x / (y - (z * 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 = 1.0 / ((y / x) - ((z / x) * t));
double tmp;
if (x < -1.618195973607049e+50) {
tmp = t_1;
} else if (x < 2.1378306434876444e+131) {
tmp = x / (y - (z * t));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = 1.0 / ((y / x) - ((z / x) * t)) tmp = 0 if x < -1.618195973607049e+50: tmp = t_1 elif x < 2.1378306434876444e+131: tmp = x / (y - (z * t)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(1.0 / Float64(Float64(y / x) - Float64(Float64(z / x) * t))) tmp = 0.0 if (x < -1.618195973607049e+50) tmp = t_1; elseif (x < 2.1378306434876444e+131) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = 1.0 / ((y / x) - ((z / x) * t)); tmp = 0.0; if (x < -1.618195973607049e+50) tmp = t_1; elseif (x < 2.1378306434876444e+131) tmp = x / (y - (z * t)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(1.0 / N[(N[(y / x), $MachinePrecision] - N[(N[(z / x), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[x, -1.618195973607049e+50], t$95$1, If[Less[x, 2.1378306434876444e+131], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\
\mathbf{if}\;x < -1.618195973607049 \cdot 10^{+50}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x < 2.1378306434876444 \cdot 10^{+131}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2023173
(FPCore (x y z t)
:name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(if (< x -1.618195973607049e+50) (/ 1.0 (- (/ y x) (* (/ z x) t))) (if (< x 2.1378306434876444e+131) (/ x (- y (* z t))) (/ 1.0 (- (/ y x) (* (/ z x) t)))))
(/ x (- y (* z t))))