| Alternative 1 | |
|---|---|
| Error | 18.9 |
| Cost | 1044 |
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t) :precision binary64 (if (<= (* z t) -5e+242) (/ (/ (- x) z) t) (if (<= (* z t) 1e+284) (/ x (- y (* z t))) (* (/ -1.0 t) (/ x z)))))
double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -5e+242) {
tmp = (-x / z) / t;
} else if ((z * t) <= 1e+284) {
tmp = x / (y - (z * t));
} else {
tmp = (-1.0 / t) * (x / 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
code = x / (y - (z * t))
end 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+242)) then
tmp = (-x / z) / t
else if ((z * t) <= 1d+284) then
tmp = x / (y - (z * t))
else
tmp = ((-1.0d0) / t) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x / (y - (z * t));
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * t) <= -5e+242) {
tmp = (-x / z) / t;
} else if ((z * t) <= 1e+284) {
tmp = x / (y - (z * t));
} else {
tmp = (-1.0 / t) * (x / z);
}
return tmp;
}
def code(x, y, z, t): return x / (y - (z * t))
def code(x, y, z, t): tmp = 0 if (z * t) <= -5e+242: tmp = (-x / z) / t elif (z * t) <= 1e+284: tmp = x / (y - (z * t)) else: tmp = (-1.0 / t) * (x / z) return tmp
function code(x, y, z, t) return Float64(x / Float64(y - Float64(z * t))) end
function code(x, y, z, t) tmp = 0.0 if (Float64(z * t) <= -5e+242) tmp = Float64(Float64(Float64(-x) / z) / t); elseif (Float64(z * t) <= 1e+284) tmp = Float64(x / Float64(y - Float64(z * t))); else tmp = Float64(Float64(-1.0 / t) * Float64(x / z)); end return tmp end
function tmp = code(x, y, z, t) tmp = x / (y - (z * t)); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * t) <= -5e+242) tmp = (-x / z) / t; elseif ((z * t) <= 1e+284) tmp = x / (y - (z * t)); else tmp = (-1.0 / t) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], -5e+242], N[(N[((-x) / z), $MachinePrecision] / t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+284], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / t), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+242}:\\
\;\;\;\;\frac{\frac{-x}{z}}{t}\\
\mathbf{elif}\;z \cdot t \leq 10^{+284}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{t} \cdot \frac{x}{z}\\
\end{array}
Results
| Original | 2.9 |
|---|---|
| Target | 1.9 |
| Herbie | 0.2 |
if (*.f64 z t) < -5.0000000000000004e242Initial program 14.8
Applied egg-rr46.2
Simplified46.2
[Start]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \left(\mathsf{fma}\left(-t, z, z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right)}
\] |
|---|---|
associate-+r+ [=>]46.2 | \[ \frac{x}{\color{blue}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)}}
\] |
fma-udef [=>]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \color{blue}{\left(\left(-t\right) \cdot z + z \cdot t\right)}}
\] |
neg-mul-1 [=>]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \left(\color{blue}{\left(-1 \cdot t\right)} \cdot z + z \cdot t\right)}
\] |
associate-*r* [<=]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \left(\color{blue}{-1 \cdot \left(t \cdot z\right)} + z \cdot t\right)}
\] |
*-commutative [<=]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \left(-1 \cdot \color{blue}{\left(z \cdot t\right)} + z \cdot t\right)}
\] |
mul-1-neg [=>]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \left(\color{blue}{\left(-z \cdot t\right)} + z \cdot t\right)}
\] |
*-rgt-identity [<=]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \left(\color{blue}{\left(-z \cdot t\right) \cdot 1} + z \cdot t\right)}
\] |
fma-udef [<=]46.2 | \[ \frac{x}{\left(\left(y - z \cdot t\right) + \mathsf{fma}\left(-t, z, z \cdot t\right)\right) + \color{blue}{\mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)}}
\] |
associate-+r+ [<=]46.2 | \[ \frac{x}{\color{blue}{\left(y - z \cdot t\right) + \left(\mathsf{fma}\left(-t, z, z \cdot t\right) + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)}}
\] |
fma-udef [=>]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \left(\color{blue}{\left(\left(-t\right) \cdot z + z \cdot t\right)} + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)}
\] |
distribute-lft-neg-in [<=]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \left(\left(\color{blue}{\left(-t \cdot z\right)} + z \cdot t\right) + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)}
\] |
*-commutative [<=]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \left(\left(\left(-\color{blue}{z \cdot t}\right) + z \cdot t\right) + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)}
\] |
associate-+l+ [=>]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \color{blue}{\left(\left(-z \cdot t\right) + \left(z \cdot t + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)\right)}}
\] |
*-rgt-identity [<=]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \left(\color{blue}{\left(-z \cdot t\right) \cdot 1} + \left(z \cdot t + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)\right)}
\] |
associate-+l+ [<=]46.2 | \[ \frac{x}{\left(y - z \cdot t\right) + \color{blue}{\left(\left(\left(-z \cdot t\right) \cdot 1 + z \cdot t\right) + \mathsf{fma}\left(-z \cdot t, 1, z \cdot t\right)\right)}}
\] |
Taylor expanded in t around -inf 15.7
Simplified1.3
[Start]15.7 | \[ -1 \cdot \frac{x}{t \cdot \left(2 \cdot \left(-1 \cdot z + z\right) - -1 \cdot z\right)}
\] |
|---|---|
associate-*r/ [=>]15.7 | \[ \color{blue}{\frac{-1 \cdot x}{t \cdot \left(2 \cdot \left(-1 \cdot z + z\right) - -1 \cdot z\right)}}
\] |
neg-mul-1 [<=]15.7 | \[ \frac{\color{blue}{-x}}{t \cdot \left(2 \cdot \left(-1 \cdot z + z\right) - -1 \cdot z\right)}
\] |
*-commutative [=>]15.7 | \[ \frac{-x}{\color{blue}{\left(2 \cdot \left(-1 \cdot z + z\right) - -1 \cdot z\right) \cdot t}}
\] |
associate-/r* [=>]1.3 | \[ \color{blue}{\frac{\frac{-x}{2 \cdot \left(-1 \cdot z + z\right) - -1 \cdot z}}{t}}
\] |
distribute-lft1-in [=>]1.3 | \[ \frac{\frac{-x}{2 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot z\right)} - -1 \cdot z}}{t}
\] |
metadata-eval [=>]1.3 | \[ \frac{\frac{-x}{2 \cdot \left(\color{blue}{0} \cdot z\right) - -1 \cdot z}}{t}
\] |
mul0-lft [=>]1.3 | \[ \frac{\frac{-x}{2 \cdot \color{blue}{0} - -1 \cdot z}}{t}
\] |
metadata-eval [=>]1.3 | \[ \frac{\frac{-x}{\color{blue}{0} - -1 \cdot z}}{t}
\] |
neg-sub0 [<=]1.3 | \[ \frac{\frac{-x}{\color{blue}{--1 \cdot z}}}{t}
\] |
mul-1-neg [=>]1.3 | \[ \frac{\frac{-x}{-\color{blue}{\left(-z\right)}}}{t}
\] |
remove-double-neg [=>]1.3 | \[ \frac{\frac{-x}{\color{blue}{z}}}{t}
\] |
if -5.0000000000000004e242 < (*.f64 z t) < 1.00000000000000008e284Initial program 0.1
if 1.00000000000000008e284 < (*.f64 z t) Initial program 19.1
Taylor expanded in y around 0 19.3
Simplified19.3
[Start]19.3 | \[ -1 \cdot \frac{x}{t \cdot z}
\] |
|---|---|
*-commutative [<=]19.3 | \[ -1 \cdot \frac{x}{\color{blue}{z \cdot t}}
\] |
associate-*r/ [=>]19.3 | \[ \color{blue}{\frac{-1 \cdot x}{z \cdot t}}
\] |
neg-mul-1 [<=]19.3 | \[ \frac{\color{blue}{-x}}{z \cdot t}
\] |
*-commutative [=>]19.3 | \[ \frac{-x}{\color{blue}{t \cdot z}}
\] |
Applied egg-rr0.3
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 18.9 |
| Cost | 1044 |
| Alternative 2 | |
|---|---|
| Error | 18.5 |
| Cost | 912 |
| Alternative 3 | |
|---|---|
| Error | 17.5 |
| Cost | 648 |
| Alternative 4 | |
|---|---|
| Error | 27.5 |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Error | 30.5 |
| Cost | 192 |
herbie shell --seed 2023041
(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))))