
(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 5 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: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (* z t) 2e+306) (/ x (- y (* z t))) (/ (/ x z) (- t))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= 2e+306) {
tmp = x / (y - (z * t));
} else {
tmp = (x / z) / -t;
}
return tmp;
}
NOTE: x, y, 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 * t) <= 2d+306) then
tmp = x / (y - (z * t))
else
tmp = (x / z) / -t
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= 2e+306) {
tmp = x / (y - (z * t));
} else {
tmp = (x / z) / -t;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (z * t) <= 2e+306: tmp = x / (y - (z * t)) else: tmp = (x / z) / -t return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= 2e+306) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(Float64(x / z) / Float64(-t)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z * t) <= 2e+306)
tmp = x / (y - (z * t));
else
tmp = (x / z) / -t;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], 2e+306], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] / (-t)), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq 2 \cdot 10^{+306}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z}}{-t}\\
\end{array}
\end{array}
if (*.f64 z t) < 2.00000000000000003e306Initial program 99.0%
if 2.00000000000000003e306 < (*.f64 z t) Initial program 71.9%
Taylor expanded in y around 0 71.9%
associate-*r/71.9%
neg-mul-171.9%
Simplified71.9%
distribute-frac-neg71.9%
*-commutative71.9%
associate-/r*99.9%
Applied egg-rr99.9%
Final simplification99.1%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -2.1e-9) (not (<= z 7e-83))) (/ (/ x z) (- t)) (/ 1.0 (/ y x))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.1e-9) || !(z <= 7e-83)) {
tmp = (x / z) / -t;
} else {
tmp = 1.0 / (y / x);
}
return tmp;
}
NOTE: x, y, 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 <= (-2.1d-9)) .or. (.not. (z <= 7d-83))) then
tmp = (x / z) / -t
else
tmp = 1.0d0 / (y / x)
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.1e-9) || !(z <= 7e-83)) {
tmp = (x / z) / -t;
} else {
tmp = 1.0 / (y / x);
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (z <= -2.1e-9) or not (z <= 7e-83): tmp = (x / z) / -t else: tmp = 1.0 / (y / x) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -2.1e-9) || !(z <= 7e-83)) tmp = Float64(Float64(x / z) / Float64(-t)); else tmp = Float64(1.0 / Float64(y / x)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -2.1e-9) || ~((z <= 7e-83)))
tmp = (x / z) / -t;
else
tmp = 1.0 / (y / x);
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.1e-9], N[Not[LessEqual[z, 7e-83]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] / (-t)), $MachinePrecision], N[(1.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-9} \lor \neg \left(z \leq 7 \cdot 10^{-83}\right):\\
\;\;\;\;\frac{\frac{x}{z}}{-t}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{y}{x}}\\
\end{array}
\end{array}
if z < -2.10000000000000019e-9 or 7.00000000000000061e-83 < z Initial program 95.5%
Taylor expanded in y around 0 70.8%
associate-*r/70.8%
neg-mul-170.8%
Simplified70.8%
distribute-frac-neg70.8%
*-commutative70.8%
associate-/r*72.0%
Applied egg-rr72.0%
if -2.10000000000000019e-9 < z < 7.00000000000000061e-83Initial program 99.9%
Taylor expanded in y around inf 73.3%
clear-num72.7%
inv-pow72.7%
Applied egg-rr72.7%
unpow-172.7%
Simplified72.7%
Final simplification72.3%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= t -1.55e-53) (not (<= t 3.4e+195))) (/ x (* z t)) (/ x y)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.55e-53) || !(t <= 3.4e+195)) {
tmp = x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
NOTE: x, y, 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 ((t <= (-1.55d-53)) .or. (.not. (t <= 3.4d+195))) then
tmp = x / (z * t)
else
tmp = x / y
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.55e-53) || !(t <= 3.4e+195)) {
tmp = x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (t <= -1.55e-53) or not (t <= 3.4e+195): tmp = x / (z * t) else: tmp = x / y return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if ((t <= -1.55e-53) || !(t <= 3.4e+195)) tmp = Float64(x / Float64(z * t)); else tmp = Float64(x / y); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((t <= -1.55e-53) || ~((t <= 3.4e+195)))
tmp = x / (z * t);
else
tmp = x / y;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.55e-53], N[Not[LessEqual[t, 3.4e+195]], $MachinePrecision]], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.55 \cdot 10^{-53} \lor \neg \left(t \leq 3.4 \cdot 10^{+195}\right):\\
\;\;\;\;\frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if t < -1.55000000000000008e-53 or 3.4000000000000001e195 < t Initial program 93.2%
Taylor expanded in y around 0 78.7%
associate-*r/78.7%
neg-mul-178.7%
Simplified78.7%
neg-sub078.7%
sub-neg78.7%
add-sqr-sqrt42.4%
sqrt-unprod51.6%
sqr-neg51.6%
sqrt-unprod15.9%
add-sqr-sqrt40.8%
Applied egg-rr40.8%
+-lft-identity40.8%
Simplified40.8%
if -1.55000000000000008e-53 < t < 3.4000000000000001e195Initial program 99.3%
Taylor expanded in y around inf 60.6%
Final simplification53.8%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= t -1.55e-53) (/ x (* z t)) (if (<= t 1.3e+197) (/ x y) (/ (/ x t) z))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.55e-53) {
tmp = x / (z * t);
} else if (t <= 1.3e+197) {
tmp = x / y;
} else {
tmp = (x / t) / z;
}
return tmp;
}
NOTE: x, y, 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 (t <= (-1.55d-53)) then
tmp = x / (z * t)
else if (t <= 1.3d+197) then
tmp = x / y
else
tmp = (x / t) / z
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.55e-53) {
tmp = x / (z * t);
} else if (t <= 1.3e+197) {
tmp = x / y;
} else {
tmp = (x / t) / z;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if t <= -1.55e-53: tmp = x / (z * t) elif t <= 1.3e+197: tmp = x / y else: tmp = (x / t) / z return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (t <= -1.55e-53) tmp = Float64(x / Float64(z * t)); elseif (t <= 1.3e+197) tmp = Float64(x / y); else tmp = Float64(Float64(x / t) / z); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (t <= -1.55e-53)
tmp = x / (z * t);
elseif (t <= 1.3e+197)
tmp = x / y;
else
tmp = (x / t) / z;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[t, -1.55e-53], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.3e+197], N[(x / y), $MachinePrecision], N[(N[(x / t), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.55 \cdot 10^{-53}:\\
\;\;\;\;\frac{x}{z \cdot t}\\
\mathbf{elif}\;t \leq 1.3 \cdot 10^{+197}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{t}}{z}\\
\end{array}
\end{array}
if t < -1.55000000000000008e-53Initial program 93.9%
Taylor expanded in y around 0 76.2%
associate-*r/76.2%
neg-mul-176.2%
Simplified76.2%
neg-sub076.2%
sub-neg76.2%
add-sqr-sqrt37.6%
sqrt-unprod48.4%
sqr-neg48.4%
sqrt-unprod17.7%
add-sqr-sqrt35.5%
Applied egg-rr35.5%
+-lft-identity35.5%
Simplified35.5%
if -1.55000000000000008e-53 < t < 1.29999999999999994e197Initial program 99.3%
Taylor expanded in y around inf 60.6%
if 1.29999999999999994e197 < t Initial program 90.9%
Taylor expanded in y around 0 86.5%
associate-*r/86.5%
neg-mul-186.5%
Simplified86.5%
add-sqr-sqrt57.4%
sqrt-unprod61.6%
sqr-neg61.6%
sqrt-unprod10.4%
add-sqr-sqrt57.2%
div-inv57.2%
Applied egg-rr57.2%
associate-*r/57.2%
*-rgt-identity57.2%
associate-/r*57.2%
Simplified57.2%
Final simplification53.8%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (/ x y))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return x / y;
}
NOTE: x, y, 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 x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return x / y;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return x / y
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(x / y) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = x / y;
end
NOTE: x, y, 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}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\frac{x}{y}
\end{array}
Initial program 97.2%
Taylor expanded in y around inf 48.3%
(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 2024110
(FPCore (x y z t)
:name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, B"
:precision binary64
:alt
(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))))