
(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: 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) 5e+305) (/ x (fma z (- t) y)) (- (/ (/ 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) <= 5e+305) {
tmp = x / fma(z, -t, y);
} 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) <= 5e+305) tmp = Float64(x / fma(z, Float64(-t), y)); else tmp = Float64(-Float64(Float64(x / z) / t)); end return 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], 5e+305], N[(x / N[(z * (-t) + y), $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 5 \cdot 10^{+305}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(z, -t, y\right)}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\frac{x}{z}}{t}\\
\end{array}
\end{array}
if (*.f64 z t) < 5.00000000000000009e305Initial program 98.2%
cancel-sign-sub-inv98.2%
+-commutative98.2%
distribute-lft-neg-out98.2%
distribute-rgt-neg-out98.2%
fma-define98.2%
Simplified98.2%
if 5.00000000000000009e305 < (*.f64 z t) Initial program 75.5%
Taylor expanded in y around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
associate-*r/75.5%
associate-*r*75.5%
neg-mul-175.5%
*-commutative75.5%
unpow275.5%
unpow275.5%
swap-sqr75.5%
unpow275.5%
*-commutative75.5%
*-commutative75.5%
associate-/r*99.9%
Simplified99.9%
Taylor expanded in y around 0 75.5%
associate-*r/75.5%
times-frac99.9%
associate-*l/99.9%
mul-1-neg99.9%
Simplified99.9%
Final simplification98.4%
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 (<= y -7.4e-6) (not (<= y 1e-21))) (/ x y) (/ (- x) (* z t))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.4e-6) || !(y <= 1e-21)) {
tmp = x / y;
} 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 ((y <= (-7.4d-6)) .or. (.not. (y <= 1d-21))) then
tmp = x / y
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 ((y <= -7.4e-6) || !(y <= 1e-21)) {
tmp = x / y;
} 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 (y <= -7.4e-6) or not (y <= 1e-21): tmp = x / y 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 ((y <= -7.4e-6) || !(y <= 1e-21)) tmp = Float64(x / y); else tmp = Float64(Float64(-x) / Float64(z * 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 ((y <= -7.4e-6) || ~((y <= 1e-21)))
tmp = x / y;
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[Or[LessEqual[y, -7.4e-6], N[Not[LessEqual[y, 1e-21]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[((-x) / N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-6} \lor \neg \left(y \leq 10^{-21}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z \cdot t}\\
\end{array}
\end{array}
if y < -7.4000000000000003e-6 or 9.99999999999999908e-22 < y Initial program 96.9%
Taylor expanded in y around inf 81.5%
if -7.4000000000000003e-6 < y < 9.99999999999999908e-22Initial program 95.4%
Taylor expanded in y around 0 72.9%
associate-*r/72.9%
neg-mul-172.9%
Simplified72.9%
Final simplification77.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 -7.2e-35) (not (<= t 2.8e+47))) (- (/ (/ 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 <= -7.2e-35) || !(t <= 2.8e+47)) {
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 <= (-7.2d-35)) .or. (.not. (t <= 2.8d+47))) 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 <= -7.2e-35) || !(t <= 2.8e+47)) {
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 <= -7.2e-35) or not (t <= 2.8e+47): 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 <= -7.2e-35) || !(t <= 2.8e+47)) tmp = Float64(-Float64(Float64(x / 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 <= -7.2e-35) || ~((t <= 2.8e+47)))
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, -7.2e-35], N[Not[LessEqual[t, 2.8e+47]], $MachinePrecision]], (-N[(N[(x / z), $MachinePrecision] / t), $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 -7.2 \cdot 10^{-35} \lor \neg \left(t \leq 2.8 \cdot 10^{+47}\right):\\
\;\;\;\;-\frac{\frac{x}{z}}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if t < -7.20000000000000038e-35 or 2.79999999999999988e47 < t Initial program 92.0%
Taylor expanded in y around 0 52.1%
+-commutative52.1%
mul-1-neg52.1%
unsub-neg52.1%
associate-*r/52.1%
associate-*r*52.1%
neg-mul-152.1%
*-commutative52.1%
unpow252.1%
unpow252.1%
swap-sqr57.9%
unpow257.9%
*-commutative57.9%
*-commutative57.9%
associate-/r*63.0%
Simplified63.0%
Taylor expanded in y around 0 62.4%
associate-*r/62.4%
times-frac68.3%
associate-*l/68.3%
mul-1-neg68.3%
Simplified68.3%
if -7.20000000000000038e-35 < t < 2.79999999999999988e47Initial program 99.9%
Taylor expanded in y around inf 72.3%
Final simplification70.5%
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 -2.15e-35) (- (/ (/ x z) t)) (if (<= t 6.1e+34) (/ 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 <= -2.15e-35) {
tmp = -((x / z) / t);
} else if (t <= 6.1e+34) {
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 <= (-2.15d-35)) then
tmp = -((x / z) / t)
else if (t <= 6.1d+34) 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 <= -2.15e-35) {
tmp = -((x / z) / t);
} else if (t <= 6.1e+34) {
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 <= -2.15e-35: tmp = -((x / z) / t) elif t <= 6.1e+34: 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 <= -2.15e-35) tmp = Float64(-Float64(Float64(x / z) / t)); elseif (t <= 6.1e+34) tmp = Float64(x / y); else tmp = Float64(-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 <= -2.15e-35)
tmp = -((x / z) / t);
elseif (t <= 6.1e+34)
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, -2.15e-35], (-N[(N[(x / z), $MachinePrecision] / t), $MachinePrecision]), If[LessEqual[t, 6.1e+34], 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 -2.15 \cdot 10^{-35}:\\
\;\;\;\;-\frac{\frac{x}{z}}{t}\\
\mathbf{elif}\;t \leq 6.1 \cdot 10^{+34}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\frac{x}{t}}{z}\\
\end{array}
\end{array}
if t < -2.1500000000000001e-35Initial program 92.7%
Taylor expanded in y around 0 44.1%
+-commutative44.1%
mul-1-neg44.1%
unsub-neg44.1%
associate-*r/44.1%
associate-*r*44.1%
neg-mul-144.1%
*-commutative44.1%
unpow244.1%
unpow244.1%
swap-sqr47.3%
unpow247.3%
*-commutative47.3%
*-commutative47.3%
associate-/r*50.5%
Simplified50.5%
Taylor expanded in y around 0 54.3%
associate-*r/54.3%
times-frac59.4%
associate-*l/59.4%
mul-1-neg59.4%
Simplified59.4%
if -2.1500000000000001e-35 < t < 6.09999999999999996e34Initial program 99.9%
Taylor expanded in y around inf 73.2%
if 6.09999999999999996e34 < t Initial program 91.7%
Taylor expanded in y around 0 70.9%
associate-*r/70.9%
neg-mul-170.9%
associate-/r*82.8%
Simplified82.8%
Final simplification72.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 (<= (* z t) 5e+305) (/ 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) <= 5e+305) {
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) <= 5d+305) 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) <= 5e+305) {
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) <= 5e+305: 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) <= 5e+305) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(-Float64(Float64(x / z) / 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) <= 5e+305)
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], 5e+305], 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 5 \cdot 10^{+305}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\frac{x}{z}}{t}\\
\end{array}
\end{array}
if (*.f64 z t) < 5.00000000000000009e305Initial program 98.2%
if 5.00000000000000009e305 < (*.f64 z t) Initial program 75.5%
Taylor expanded in y around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
associate-*r/75.5%
associate-*r*75.5%
neg-mul-175.5%
*-commutative75.5%
unpow275.5%
unpow275.5%
swap-sqr75.5%
unpow275.5%
*-commutative75.5%
*-commutative75.5%
associate-/r*99.9%
Simplified99.9%
Taylor expanded in y around 0 75.5%
associate-*r/75.5%
times-frac99.9%
associate-*l/99.9%
mul-1-neg99.9%
Simplified99.9%
Final simplification98.4%
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 96.2%
Taylor expanded in y around inf 55.8%
Final simplification55.8%
(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 2024034
(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))))