
(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}
(FPCore (x y z t) :precision binary64 (if (<= (* z t) 2e+261) (/ x (fma z (- t) y)) (/ (/ (- x) t) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= 2e+261) {
tmp = x / fma(z, -t, y);
} else {
tmp = (-x / t) / z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= 2e+261) tmp = Float64(x / fma(z, Float64(-t), y)); else tmp = Float64(Float64(Float64(-x) / t) / z); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], 2e+261], N[(x / N[(z * (-t) + y), $MachinePrecision]), $MachinePrecision], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq 2 \cdot 10^{+261}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(z, -t, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\end{array}
\end{array}
if (*.f64 z t) < 1.9999999999999999e261Initial program 99.0%
cancel-sign-sub-inv99.0%
+-commutative99.0%
distribute-lft-neg-out99.0%
distribute-rgt-neg-out99.0%
fma-def99.1%
Simplified99.1%
if 1.9999999999999999e261 < (*.f64 z t) Initial program 53.7%
Taylor expanded in y around 0 53.7%
associate-*r/53.7%
neg-mul-153.7%
Simplified53.7%
neg-mul-153.7%
times-frac99.8%
Applied egg-rr99.8%
Taylor expanded in t around 0 53.7%
mul-1-neg53.7%
associate-/r*99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -5e+23) (not (<= (* z t) 1e-32))) (/ (/ (- x) t) z) (/ x y)))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -5e+23) || !((z * t) <= 1e-32)) {
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 (((z * t) <= (-5d+23)) .or. (.not. ((z * t) <= 1d-32))) 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 (((z * t) <= -5e+23) || !((z * t) <= 1e-32)) {
tmp = (-x / t) / z;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -5e+23) or not ((z * t) <= 1e-32): tmp = (-x / t) / z else: tmp = x / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -5e+23) || !(Float64(z * t) <= 1e-32)) tmp = Float64(Float64(Float64(-x) / t) / z); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * t) <= -5e+23) || ~(((z * t) <= 1e-32))) tmp = (-x / t) / z; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e+23], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e-32]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+23} \lor \neg \left(z \cdot t \leq 10^{-32}\right):\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (*.f64 z t) < -4.9999999999999999e23 or 1.00000000000000006e-32 < (*.f64 z t) Initial program 91.6%
Taylor expanded in y around 0 71.9%
associate-*r/71.9%
neg-mul-171.9%
Simplified71.9%
neg-mul-171.9%
times-frac77.5%
Applied egg-rr77.5%
Taylor expanded in t around 0 71.9%
mul-1-neg71.9%
associate-/r*77.7%
Simplified77.7%
if -4.9999999999999999e23 < (*.f64 z t) < 1.00000000000000006e-32Initial program 99.9%
Taylor expanded in y around inf 83.7%
Final simplification80.9%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -5e+23) (not (<= (* z t) 2e-18))) (/ (/ x z) (- t)) (/ x y)))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -5e+23) || !((z * t) <= 2e-18)) {
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 (((z * t) <= (-5d+23)) .or. (.not. ((z * t) <= 2d-18))) 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 (((z * t) <= -5e+23) || !((z * t) <= 2e-18)) {
tmp = (x / z) / -t;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -5e+23) or not ((z * t) <= 2e-18): tmp = (x / z) / -t else: tmp = x / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -5e+23) || !(Float64(z * t) <= 2e-18)) tmp = Float64(Float64(x / z) / Float64(-t)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * t) <= -5e+23) || ~(((z * t) <= 2e-18))) tmp = (x / z) / -t; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e+23], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e-18]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] / (-t)), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+23} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{\frac{x}{z}}{-t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (*.f64 z t) < -4.9999999999999999e23 or 2.0000000000000001e-18 < (*.f64 z t) Initial program 91.5%
sub-neg91.5%
+-commutative91.5%
distribute-rgt-neg-in91.5%
fma-udef91.5%
frac-2neg91.5%
div-inv91.4%
fma-udef91.4%
distribute-rgt-neg-in91.4%
distribute-neg-in91.4%
Applied egg-rr91.4%
Taylor expanded in z around inf 72.2%
*-commutative72.2%
associate-/r*73.0%
Simplified73.0%
associate-*r/78.1%
frac-2neg78.1%
add-sqr-sqrt41.6%
sqrt-unprod44.6%
sqr-neg44.6%
sqrt-unprod16.4%
add-sqr-sqrt35.8%
distribute-lft-neg-out35.8%
un-div-inv35.8%
add-sqr-sqrt19.5%
sqrt-unprod49.8%
sqr-neg49.8%
sqrt-unprod36.3%
add-sqr-sqrt78.1%
Applied egg-rr78.1%
if -4.9999999999999999e23 < (*.f64 z t) < 2.0000000000000001e-18Initial program 99.9%
Taylor expanded in y around inf 83.3%
Final simplification80.9%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z t) -4e+197) (not (<= (* z t) 4e+179))) (/ x (* z t)) (/ x y)))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * t) <= -4e+197) || !((z * t) <= 4e+179)) {
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 (((z * t) <= (-4d+197)) .or. (.not. ((z * t) <= 4d+179))) 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 (((z * t) <= -4e+197) || !((z * t) <= 4e+179)) {
tmp = x / (z * t);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * t) <= -4e+197) or not ((z * t) <= 4e+179): tmp = x / (z * t) else: tmp = x / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * t) <= -4e+197) || !(Float64(z * t) <= 4e+179)) tmp = Float64(x / Float64(z * t)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * t) <= -4e+197) || ~(((z * t) <= 4e+179))) tmp = x / (z * t); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -4e+197], N[Not[LessEqual[N[(z * t), $MachinePrecision], 4e+179]], $MachinePrecision]], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+197} \lor \neg \left(z \cdot t \leq 4 \cdot 10^{+179}\right):\\
\;\;\;\;\frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (*.f64 z t) < -3.9999999999999998e197 or 3.99999999999999992e179 < (*.f64 z t) Initial program 81.5%
sub-neg81.5%
+-commutative81.5%
distribute-rgt-neg-in81.5%
fma-udef81.5%
frac-2neg81.5%
div-inv81.4%
fma-udef81.4%
distribute-rgt-neg-in81.4%
distribute-neg-in81.4%
Applied egg-rr81.4%
Taylor expanded in z around inf 76.8%
*-commutative76.8%
associate-/r*78.6%
Simplified78.6%
associate-/l/76.8%
div-inv76.9%
add-sqr-sqrt38.2%
*-commutative38.2%
sqrt-unprod62.5%
sqr-neg62.5%
sqrt-unprod29.3%
add-sqr-sqrt57.9%
Applied egg-rr57.9%
if -3.9999999999999998e197 < (*.f64 z t) < 3.99999999999999992e179Initial program 99.8%
Taylor expanded in y around inf 69.1%
Final simplification66.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z t) 2e+261) (/ x (- y (* z t))) (/ (/ (- x) t) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= 2e+261) {
tmp = x / (y - (z * t));
} 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 ((z * t) <= 2d+261) then
tmp = x / (y - (z * t))
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 ((z * t) <= 2e+261) {
tmp = x / (y - (z * t));
} else {
tmp = (-x / t) / z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * t) <= 2e+261: tmp = x / (y - (z * t)) else: tmp = (-x / t) / z return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= 2e+261) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(Float64(Float64(-x) / t) / z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * t) <= 2e+261) tmp = x / (y - (z * t)); else tmp = (-x / t) / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], 2e+261], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq 2 \cdot 10^{+261}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\
\end{array}
\end{array}
if (*.f64 z t) < 1.9999999999999999e261Initial program 99.0%
if 1.9999999999999999e261 < (*.f64 z t) Initial program 53.7%
Taylor expanded in y around 0 53.7%
associate-*r/53.7%
neg-mul-153.7%
Simplified53.7%
neg-mul-153.7%
times-frac99.8%
Applied egg-rr99.8%
Taylor expanded in t around 0 53.7%
mul-1-neg53.7%
associate-/r*99.8%
Simplified99.8%
Final simplification99.1%
(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.0%
Taylor expanded in y around inf 57.9%
Final simplification57.9%
(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 2023271
(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))))