
(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 (<= y -2e+134) (/ (/ x (- 1.0 (/ t (/ y z)))) y) (/ x (- y (* t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2e+134) {
tmp = (x / (1.0 - (t / (y / z)))) / y;
} 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 (y <= (-2d+134)) then
tmp = (x / (1.0d0 - (t / (y / z)))) / y
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 (y <= -2e+134) {
tmp = (x / (1.0 - (t / (y / z)))) / y;
} else {
tmp = x / (y - (t * z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -2e+134: tmp = (x / (1.0 - (t / (y / z)))) / y else: tmp = x / (y - (t * z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -2e+134) tmp = Float64(Float64(x / Float64(1.0 - Float64(t / Float64(y / z)))) / y); 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 (y <= -2e+134) tmp = (x / (1.0 - (t / (y / z)))) / y; else tmp = x / (y - (t * z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -2e+134], N[(N[(x / N[(1.0 - N[(t / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(y - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+134}:\\
\;\;\;\;\frac{\frac{x}{1 - \frac{t}{\frac{y}{z}}}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y - t \cdot z}\\
\end{array}
\end{array}
if y < -1.99999999999999984e134Initial program 87.5%
Taylor expanded in y around inf 87.5%
mul-1-neg87.5%
unsub-neg87.5%
associate-/l*87.5%
Simplified87.5%
*-un-lft-identity87.5%
times-frac99.6%
clear-num99.6%
un-div-inv99.6%
Applied egg-rr99.6%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
if -1.99999999999999984e134 < y Initial program 98.6%
Final simplification98.8%
(FPCore (x y z t) :precision binary64 (if (<= (* t z) -5e+18) (/ x (* t (- z))) (if (<= (* t z) 5e+55) (/ x y) (/ (/ x z) (- t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t * z) <= -5e+18) {
tmp = x / (t * -z);
} else if ((t * z) <= 5e+55) {
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 * z) <= (-5d+18)) then
tmp = x / (t * -z)
else if ((t * z) <= 5d+55) 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 * z) <= -5e+18) {
tmp = x / (t * -z);
} else if ((t * z) <= 5e+55) {
tmp = x / y;
} else {
tmp = (x / z) / -t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t * z) <= -5e+18: tmp = x / (t * -z) elif (t * z) <= 5e+55: tmp = x / y else: tmp = (x / z) / -t return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(t * z) <= -5e+18) tmp = Float64(x / Float64(t * Float64(-z))); elseif (Float64(t * z) <= 5e+55) tmp = Float64(x / y); else tmp = Float64(Float64(x / z) / Float64(-t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t * z) <= -5e+18) tmp = x / (t * -z); elseif ((t * z) <= 5e+55) tmp = x / y; else tmp = (x / z) / -t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(t * z), $MachinePrecision], -5e+18], N[(x / N[(t * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 5e+55], N[(x / y), $MachinePrecision], N[(N[(x / z), $MachinePrecision] / (-t)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\frac{x}{t \cdot \left(-z\right)}\\
\mathbf{elif}\;t \cdot z \leq 5 \cdot 10^{+55}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z}}{-t}\\
\end{array}
\end{array}
if (*.f64 z t) < -5e18Initial program 91.7%
Taylor expanded in y around 0 80.9%
associate-*r/80.9%
neg-mul-180.9%
Simplified80.9%
if -5e18 < (*.f64 z t) < 5.00000000000000046e55Initial program 99.9%
Taylor expanded in y around inf 78.7%
if 5.00000000000000046e55 < (*.f64 z t) Initial program 93.5%
clear-num93.4%
associate-/r/93.3%
Applied egg-rr93.3%
Taylor expanded in t around inf 61.7%
distribute-lft-out61.7%
mul-1-neg61.7%
+-commutative61.7%
associate-/l*72.1%
fma-define72.1%
associate-/r*72.1%
Simplified72.1%
Taylor expanded in y around 0 77.3%
Final simplification78.8%
(FPCore (x y z t) :precision binary64 (if (<= (* t z) -5e+18) (/ (/ x t) (- z)) (if (<= (* t z) 5e+55) (/ x y) (/ (/ x z) (- t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t * z) <= -5e+18) {
tmp = (x / t) / -z;
} else if ((t * z) <= 5e+55) {
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 * z) <= (-5d+18)) then
tmp = (x / t) / -z
else if ((t * z) <= 5d+55) 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 * z) <= -5e+18) {
tmp = (x / t) / -z;
} else if ((t * z) <= 5e+55) {
tmp = x / y;
} else {
tmp = (x / z) / -t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t * z) <= -5e+18: tmp = (x / t) / -z elif (t * z) <= 5e+55: tmp = x / y else: tmp = (x / z) / -t return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(t * z) <= -5e+18) tmp = Float64(Float64(x / t) / Float64(-z)); elseif (Float64(t * z) <= 5e+55) tmp = Float64(x / y); else tmp = Float64(Float64(x / z) / Float64(-t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t * z) <= -5e+18) tmp = (x / t) / -z; elseif ((t * z) <= 5e+55) tmp = x / y; else tmp = (x / z) / -t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(t * z), $MachinePrecision], -5e+18], N[(N[(x / t), $MachinePrecision] / (-z)), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 5e+55], N[(x / y), $MachinePrecision], N[(N[(x / z), $MachinePrecision] / (-t)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\frac{\frac{x}{t}}{-z}\\
\mathbf{elif}\;t \cdot z \leq 5 \cdot 10^{+55}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z}}{-t}\\
\end{array}
\end{array}
if (*.f64 z t) < -5e18Initial program 91.7%
clear-num90.8%
associate-/r/91.9%
Applied egg-rr91.9%
Taylor expanded in y around 0 80.9%
mul-1-neg80.9%
associate-/r*84.1%
distribute-neg-frac284.1%
Simplified84.1%
if -5e18 < (*.f64 z t) < 5.00000000000000046e55Initial program 99.9%
Taylor expanded in y around inf 78.7%
if 5.00000000000000046e55 < (*.f64 z t) Initial program 93.5%
clear-num93.4%
associate-/r/93.3%
Applied egg-rr93.3%
Taylor expanded in t around inf 61.7%
distribute-lft-out61.7%
mul-1-neg61.7%
+-commutative61.7%
associate-/l*72.1%
fma-define72.1%
associate-/r*72.1%
Simplified72.1%
Taylor expanded in y around 0 77.3%
Final simplification79.4%
(FPCore (x y z t) :precision binary64 (if (or (<= (* t z) -2e+133) (not (<= (* t z) 5e+150))) (/ x (* t z)) (/ x y)))
double code(double x, double y, double z, double t) {
double tmp;
if (((t * z) <= -2e+133) || !((t * z) <= 5e+150)) {
tmp = x / (t * z);
} 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 * z) <= (-2d+133)) .or. (.not. ((t * z) <= 5d+150))) then
tmp = x / (t * z)
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 * z) <= -2e+133) || !((t * z) <= 5e+150)) {
tmp = x / (t * z);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((t * z) <= -2e+133) or not ((t * z) <= 5e+150): tmp = x / (t * z) else: tmp = x / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(t * z) <= -2e+133) || !(Float64(t * z) <= 5e+150)) tmp = Float64(x / Float64(t * z)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((t * z) <= -2e+133) || ~(((t * z) <= 5e+150))) tmp = x / (t * z); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(t * z), $MachinePrecision], -2e+133], N[Not[LessEqual[N[(t * z), $MachinePrecision], 5e+150]], $MachinePrecision]], N[(x / N[(t * z), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -2 \cdot 10^{+133} \lor \neg \left(t \cdot z \leq 5 \cdot 10^{+150}\right):\\
\;\;\;\;\frac{x}{t \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (*.f64 z t) < -2e133 or 5.00000000000000009e150 < (*.f64 z t) Initial program 89.0%
clear-num88.3%
associate-/r/89.0%
Applied egg-rr89.0%
Taylor expanded in y around 0 87.0%
associate-/r*89.1%
Simplified89.1%
*-commutative89.1%
associate-*r/95.7%
div-inv95.7%
mul-1-neg95.7%
distribute-rgt-neg-in95.7%
div-inv95.8%
distribute-frac-neg95.8%
distribute-frac-neg295.8%
associate-/l/86.9%
add-sqr-sqrt38.8%
sqrt-unprod67.9%
sqr-neg67.9%
sqrt-prod35.6%
add-sqr-sqrt59.5%
Applied egg-rr59.5%
if -2e133 < (*.f64 z t) < 5.00000000000000009e150Initial program 99.9%
Taylor expanded in y around inf 70.5%
Final simplification67.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.2e-48) (not (<= y 5.5e+22))) (/ x y) (/ x (* t (- z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.2e-48) || !(y <= 5.5e+22)) {
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 ((y <= (-2.2d-48)) .or. (.not. (y <= 5.5d+22))) 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 ((y <= -2.2e-48) || !(y <= 5.5e+22)) {
tmp = x / y;
} else {
tmp = x / (t * -z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.2e-48) or not (y <= 5.5e+22): tmp = x / y else: tmp = x / (t * -z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.2e-48) || !(y <= 5.5e+22)) tmp = Float64(x / y); else tmp = Float64(x / Float64(t * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.2e-48) || ~((y <= 5.5e+22))) tmp = x / y; else tmp = x / (t * -z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.2e-48], N[Not[LessEqual[y, 5.5e+22]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(t * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-48} \lor \neg \left(y \leq 5.5 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t \cdot \left(-z\right)}\\
\end{array}
\end{array}
if y < -2.20000000000000013e-48 or 5.50000000000000021e22 < y Initial program 95.2%
Taylor expanded in y around inf 78.2%
if -2.20000000000000013e-48 < y < 5.50000000000000021e22Initial program 99.0%
Taylor expanded in y around 0 81.3%
associate-*r/81.3%
neg-mul-181.3%
Simplified81.3%
Final simplification79.7%
(FPCore (x y z t) :precision binary64 (/ x (- y (* t z))))
double code(double x, double y, double z, double t) {
return x / (y - (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 - (t * z))
end function
public static double code(double x, double y, double z, double t) {
return x / (y - (t * z));
}
def code(x, y, z, t): return x / (y - (t * z))
function code(x, y, z, t) return Float64(x / Float64(y - Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = x / (y - (t * z)); end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y - t \cdot z}
\end{array}
Initial program 96.9%
Final simplification96.9%
(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 96.9%
Taylor expanded in y around inf 55.3%
Final simplification55.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 2024077
(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))))