
(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: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (* z t) 1e+271) (/ x (- y (* z t))) (/ 1.0 (* z (/ t (- x))))))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= 1e+271) {
tmp = x / (y - (z * t));
} else {
tmp = 1.0 / (z * (t / -x));
}
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 * t) <= 1d+271) then
tmp = x / (y - (z * t))
else
tmp = 1.0d0 / (z * (t / -x))
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 * t) <= 1e+271) {
tmp = x / (y - (z * t));
} else {
tmp = 1.0 / (z * (t / -x));
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if (z * t) <= 1e+271: tmp = x / (y - (z * t)) else: tmp = 1.0 / (z * (t / -x)) return tmp
z, t = sort([z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= 1e+271) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(1.0 / Float64(z * Float64(t / Float64(-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) <= 1e+271)
tmp = x / (y - (z * t));
else
tmp = 1.0 / (z * (t / -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], 1e+271], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(t / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq 10^{+271}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \frac{t}{-x}}\\
\end{array}
\end{array}
if (*.f64 z t) < 9.99999999999999953e270Initial program 98.3%
if 9.99999999999999953e270 < (*.f64 z t) Initial program 65.2%
clear-num65.2%
associate-/r/65.2%
Applied egg-rr65.2%
associate-/r/65.2%
Applied egg-rr65.2%
Taylor expanded in y around 0 65.2%
associate-*r/65.2%
*-commutative65.2%
neg-mul-165.2%
distribute-neg-frac65.2%
associate-*l/99.6%
distribute-rgt-neg-in99.6%
Simplified99.6%
associate-*l/65.2%
add-sqr-sqrt43.3%
sqrt-unprod60.1%
sqr-neg60.1%
sqrt-unprod16.7%
add-sqr-sqrt60.0%
add-sqr-sqrt16.7%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod43.3%
add-sqr-sqrt65.2%
add-sqr-sqrt26.9%
frac-times36.8%
clear-num36.8%
frac-2neg36.8%
frac-times36.8%
*-un-lft-identity36.8%
add-sqr-sqrt15.7%
sqrt-unprod31.6%
sqr-neg31.6%
sqrt-unprod15.9%
add-sqr-sqrt26.7%
Applied egg-rr36.8%
associate-*l/36.7%
associate-/l*26.9%
distribute-rgt-neg-out26.9%
rem-square-sqrt65.2%
associate-/l*99.6%
associate-/r/99.5%
Simplified99.5%
Final simplification98.4%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -6.5e-9) (/ x y) (if (<= y 3.8e-41) (- (/ x (* z t))) (/ x y))))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6.5e-9) {
tmp = x / y;
} else if (y <= 3.8e-41) {
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 <= (-6.5d-9)) then
tmp = x / y
else if (y <= 3.8d-41) 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 <= -6.5e-9) {
tmp = x / y;
} else if (y <= 3.8e-41) {
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 <= -6.5e-9: tmp = x / y elif y <= 3.8e-41: 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 <= -6.5e-9) tmp = Float64(x / y); elseif (y <= 3.8e-41) 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 <= -6.5e-9)
tmp = x / y;
elseif (y <= 3.8e-41)
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, -6.5e-9], N[(x / y), $MachinePrecision], If[LessEqual[y, 3.8e-41], (-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 -6.5 \cdot 10^{-9}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-41}:\\
\;\;\;\;-\frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -6.5000000000000003e-9 or 3.79999999999999979e-41 < y Initial program 96.5%
Taylor expanded in y around inf 77.3%
if -6.5000000000000003e-9 < y < 3.79999999999999979e-41Initial program 95.0%
Taylor expanded in y around 0 78.8%
associate-*r/78.8%
neg-mul-178.8%
Simplified78.8%
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 (<= t -8.5e-51) (not (<= t 1.35e+159))) (/ x (* z t)) (/ x y)))
assert(z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -8.5e-51) || !(t <= 1.35e+159)) {
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 ((t <= (-8.5d-51)) .or. (.not. (t <= 1.35d+159))) 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 ((t <= -8.5e-51) || !(t <= 1.35e+159)) {
tmp = x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
[z, t] = sort([z, t]) def code(x, y, z, t): tmp = 0 if (t <= -8.5e-51) or not (t <= 1.35e+159): 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 ((t <= -8.5e-51) || !(t <= 1.35e+159)) tmp = 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 ((t <= -8.5e-51) || ~((t <= 1.35e+159)))
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[Or[LessEqual[t, -8.5e-51], N[Not[LessEqual[t, 1.35e+159]], $MachinePrecision]], 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}\;t \leq -8.5 \cdot 10^{-51} \lor \neg \left(t \leq 1.35 \cdot 10^{+159}\right):\\
\;\;\;\;\frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if t < -8.50000000000000036e-51 or 1.35000000000000004e159 < t Initial program 93.7%
clear-num91.8%
associate-/r/93.6%
Applied egg-rr93.6%
associate-/r/91.8%
Applied egg-rr91.8%
Taylor expanded in y around 0 66.4%
associate-*r/66.4%
*-commutative66.4%
neg-mul-166.4%
distribute-neg-frac66.4%
associate-*l/66.2%
distribute-rgt-neg-in66.2%
Simplified66.2%
expm1-log1p-u61.6%
expm1-udef46.9%
*-commutative46.9%
add-sqr-sqrt27.3%
sqrt-unprod45.9%
sqr-neg45.9%
sqrt-unprod18.6%
add-sqr-sqrt40.7%
associate-*r/40.8%
Applied egg-rr40.8%
expm1-def36.5%
expm1-log1p36.7%
associate-/r/36.7%
associate-*l/36.7%
*-lft-identity36.7%
Simplified36.7%
if -8.50000000000000036e-51 < t < 1.35000000000000004e159Initial program 97.4%
Taylor expanded in y around inf 63.0%
Final simplification52.1%
NOTE: z and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
assert(z < t);
double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
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 - (z * t))
end function
assert z < t;
public static double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
[z, t] = sort([z, t]) def code(x, y, z, t): return x / (y - (z * t))
z, t = sort([z, t]) function code(x, y, z, t) return Float64(x / Float64(y - Float64(z * t))) end
z, t = num2cell(sort([z, t])){:}
function tmp = code(x, y, z, t)
tmp = x / (y - (z * t));
end
NOTE: z and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\\
\frac{x}{y - z \cdot t}
\end{array}
Initial program 95.8%
Final simplification95.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 95.8%
Taylor expanded in y around inf 52.3%
Final simplification52.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 2023240
(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))))