
(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 7 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}
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -5e+284) (not (<= (* z t) 5e+189))) (/ (/ (- x) t) z) (/ x (fma z (- t) y))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -5e+284) || !((z * t) <= 5e+189)) {
tmp = (-x / t) / z;
} else {
tmp = x / fma(z, -t, y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -5e+284) || !(Float64(z * t) <= 5e+189)) tmp = Float64(Float64(Float64(-x) / t) / z); else tmp = Float64(x / fma(z, Float64(-t), y)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e+284], N[Not[LessEqual[N[(z * t), $MachinePrecision], 5e+189]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(z * (-t) + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+284} \lor \neg \left(z \cdot t \leq 5 \cdot 10^{+189}\right):\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(z, -t, y\right)}\\
\end{array}
\end{array}
if (*.f64 z t) < -4.9999999999999999e284 or 5.0000000000000004e189 < (*.f64 z t) Initial program 78.7%
Taylor expanded in y around 0 78.7%
mul-1-neg78.7%
associate-/r*99.9%
distribute-neg-frac99.9%
Simplified99.9%
if -4.9999999999999999e284 < (*.f64 z t) < 5.0000000000000004e189Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-out99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -5e+284) (not (<= (* z t) 5e+189))) (/ (/ (- x) t) z) (/ x (- y (* z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -5e+284) || !((z * t) <= 5e+189)) {
tmp = (-x / t) / z;
} 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 (((z * t) <= (-5d+284)) .or. (.not. ((z * t) <= 5d+189))) then
tmp = (-x / t) / z
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 (((z * t) <= -5e+284) || !((z * t) <= 5e+189)) {
tmp = (-x / t) / z;
} else {
tmp = x / (y - (z * t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -5e+284) or not ((z * t) <= 5e+189): tmp = (-x / t) / z else: tmp = x / (y - (z * t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -5e+284) || !(Float64(z * t) <= 5e+189)) tmp = Float64(Float64(Float64(-x) / t) / z); 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 (((z * t) <= -5e+284) || ~(((z * t) <= 5e+189))) tmp = (-x / t) / z; else tmp = x / (y - (z * t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e+284], N[Not[LessEqual[N[(z * t), $MachinePrecision], 5e+189]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+284} \lor \neg \left(z \cdot t \leq 5 \cdot 10^{+189}\right):\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\end{array}
\end{array}
if (*.f64 z t) < -4.9999999999999999e284 or 5.0000000000000004e189 < (*.f64 z t) Initial program 78.7%
Taylor expanded in y around 0 78.7%
mul-1-neg78.7%
associate-/r*99.9%
distribute-neg-frac99.9%
Simplified99.9%
if -4.9999999999999999e284 < (*.f64 z t) < 5.0000000000000004e189Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1e-44) (not (<= y 1.85e-35))) (/ x y) (/ (- x) (* z t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1e-44) || !(y <= 1.85e-35)) {
tmp = x / y;
} else {
tmp = -x / (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 ((y <= (-1d-44)) .or. (.not. (y <= 1.85d-35))) then
tmp = x / y
else
tmp = -x / (z * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1e-44) || !(y <= 1.85e-35)) {
tmp = x / y;
} else {
tmp = -x / (z * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1e-44) or not (y <= 1.85e-35): tmp = x / y else: tmp = -x / (z * t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1e-44) || !(y <= 1.85e-35)) tmp = Float64(x / y); else tmp = Float64(Float64(-x) / Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1e-44) || ~((y <= 1.85e-35))) tmp = x / y; else tmp = -x / (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1e-44], N[Not[LessEqual[y, 1.85e-35]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[((-x) / N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-44} \lor \neg \left(y \leq 1.85 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z \cdot t}\\
\end{array}
\end{array}
if y < -9.99999999999999953e-45 or 1.8499999999999999e-35 < y Initial program 95.7%
Taylor expanded in y around inf 77.7%
if -9.99999999999999953e-45 < y < 1.8499999999999999e-35Initial program 96.2%
Taylor expanded in y around 0 76.4%
associate-*r/76.4%
neg-mul-176.4%
Simplified76.4%
Final simplification77.1%
(FPCore (x y z t) :precision binary64 (if (or (<= t -5.8e-95) (not (<= t 1.35e+123))) (/ (/ (- x) z) t) (/ x y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -5.8e-95) || !(t <= 1.35e+123)) {
tmp = (-x / z) / t;
} else {
tmp = x / y;
}
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 <= (-5.8d-95)) .or. (.not. (t <= 1.35d+123))) then
tmp = (-x / z) / t
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -5.8e-95) || !(t <= 1.35e+123)) {
tmp = (-x / z) / t;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -5.8e-95) or not (t <= 1.35e+123): tmp = (-x / z) / t else: tmp = x / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -5.8e-95) || !(t <= 1.35e+123)) tmp = Float64(Float64(Float64(-x) / z) / t); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -5.8e-95) || ~((t <= 1.35e+123))) tmp = (-x / z) / t; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -5.8e-95], N[Not[LessEqual[t, 1.35e+123]], $MachinePrecision]], N[(N[((-x) / z), $MachinePrecision] / t), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.8 \cdot 10^{-95} \lor \neg \left(t \leq 1.35 \cdot 10^{+123}\right):\\
\;\;\;\;\frac{\frac{-x}{z}}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if t < -5.80000000000000004e-95 or 1.35000000000000007e123 < t Initial program 92.2%
Taylor expanded in y around 0 68.2%
associate-*r/68.2%
neg-mul-168.2%
Simplified68.2%
neg-mul-168.2%
times-frac70.3%
Applied egg-rr70.3%
Taylor expanded in t around 0 68.2%
associate-*r/68.2%
associate-/l*68.1%
associate-/l*69.3%
associate-/l*70.3%
mul-1-neg70.3%
Simplified70.3%
if -5.80000000000000004e-95 < t < 1.35000000000000007e123Initial program 99.5%
Taylor expanded in y around inf 75.9%
Final simplification73.1%
(FPCore (x y z t) :precision binary64 (if (<= t 1.05e+167) (/ x y) (/ x (* z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1.05e+167) {
tmp = x / y;
} else {
tmp = x / (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 (t <= 1.05d+167) then
tmp = x / y
else
tmp = x / (z * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1.05e+167) {
tmp = x / y;
} else {
tmp = x / (z * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 1.05e+167: tmp = x / y else: tmp = x / (z * t) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 1.05e+167) tmp = Float64(x / y); else tmp = Float64(x / Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 1.05e+167) tmp = x / y; else tmp = x / (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 1.05e+167], N[(x / y), $MachinePrecision], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 1.05 \cdot 10^{+167}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z \cdot t}\\
\end{array}
\end{array}
if t < 1.05e167Initial program 96.6%
Taylor expanded in y around inf 60.1%
if 1.05e167 < t Initial program 90.0%
Taylor expanded in y around 0 86.2%
associate-*r/86.2%
neg-mul-186.2%
Simplified86.2%
neg-mul-186.2%
times-frac92.5%
Applied egg-rr92.5%
frac-times86.2%
neg-mul-186.2%
add-sqr-sqrt35.9%
sqrt-unprod64.0%
sqr-neg64.0%
sqrt-unprod35.4%
add-sqr-sqrt63.9%
expm1-log1p-u63.8%
expm1-udef64.1%
Applied egg-rr64.1%
expm1-def63.8%
expm1-log1p63.9%
Simplified63.9%
Final simplification60.5%
(FPCore (x y z t) :precision binary64 (if (<= t 9.6e+166) (/ x y) (/ (/ x t) z)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 9.6e+166) {
tmp = x / y;
} else {
tmp = (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 (t <= 9.6d+166) then
tmp = x / y
else
tmp = (x / t) / z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 9.6e+166) {
tmp = x / y;
} else {
tmp = (x / t) / z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 9.6e+166: tmp = x / y else: tmp = (x / t) / z return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 9.6e+166) tmp = Float64(x / y); else tmp = Float64(Float64(x / t) / z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 9.6e+166) tmp = x / y; else tmp = (x / t) / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 9.6e+166], N[(x / y), $MachinePrecision], N[(N[(x / t), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 9.6 \cdot 10^{+166}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{t}}{z}\\
\end{array}
\end{array}
if t < 9.59999999999999969e166Initial program 96.6%
Taylor expanded in y around inf 60.1%
if 9.59999999999999969e166 < t Initial program 90.0%
Taylor expanded in y around 0 86.2%
associate-*r/86.2%
neg-mul-186.2%
Simplified86.2%
neg-mul-186.2%
times-frac92.5%
Applied egg-rr92.5%
frac-times86.2%
neg-mul-186.2%
add-sqr-sqrt35.9%
sqrt-unprod64.0%
sqr-neg64.0%
sqrt-unprod35.4%
add-sqr-sqrt63.9%
associate-/r*63.9%
Applied egg-rr63.9%
Final simplification60.5%
(FPCore (x y z t) :precision binary64 (/ x y))
double code(double x, double y, double z, double t) {
return x / y;
}
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
public static double code(double x, double y, double z, double t) {
return x / y;
}
def code(x, y, z, t): return x / y
function code(x, y, z, t) return Float64(x / y) end
function tmp = code(x, y, z, t) tmp = x / y; end
code[x_, y_, z_, t_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y}
\end{array}
Initial program 95.9%
Taylor expanded in y around inf 56.5%
Final simplification56.5%
(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 2023309
(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))))