(FPCore (x y z t a) :precision binary64 (/ (- x (* y z)) (- t (* a z))))
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (- t (* z a))) (t_2 (/ x t_1)) (t_3 (- t_2 (/ y (- (/ t z) a))))) (if (<= z -1e-104) t_3 (if (<= z 1e-196) (- t_2 (/ (* z y) t_1)) t_3))))
double code(double x, double y, double z, double t, double a) {
return (x - (y * z)) / (t - (a * z));
}
double code(double x, double y, double z, double t, double a) {
double t_1 = t - (z * a);
double t_2 = x / t_1;
double t_3 = t_2 - (y / ((t / z) - a));
double tmp;
if (z <= -1e-104) {
tmp = t_3;
} else if (z <= 1e-196) {
tmp = t_2 - ((z * y) / t_1);
} else {
tmp = t_3;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x - (y * z)) / (t - (a * z))
end function
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = t - (z * a)
t_2 = x / t_1
t_3 = t_2 - (y / ((t / z) - a))
if (z <= (-1d-104)) then
tmp = t_3
else if (z <= 1d-196) then
tmp = t_2 - ((z * y) / t_1)
else
tmp = t_3
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return (x - (y * z)) / (t - (a * z));
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = t - (z * a);
double t_2 = x / t_1;
double t_3 = t_2 - (y / ((t / z) - a));
double tmp;
if (z <= -1e-104) {
tmp = t_3;
} else if (z <= 1e-196) {
tmp = t_2 - ((z * y) / t_1);
} else {
tmp = t_3;
}
return tmp;
}
def code(x, y, z, t, a): return (x - (y * z)) / (t - (a * z))
def code(x, y, z, t, a): t_1 = t - (z * a) t_2 = x / t_1 t_3 = t_2 - (y / ((t / z) - a)) tmp = 0 if z <= -1e-104: tmp = t_3 elif z <= 1e-196: tmp = t_2 - ((z * y) / t_1) else: tmp = t_3 return tmp
function code(x, y, z, t, a) return Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(a * z))) end
function code(x, y, z, t, a) t_1 = Float64(t - Float64(z * a)) t_2 = Float64(x / t_1) t_3 = Float64(t_2 - Float64(y / Float64(Float64(t / z) - a))) tmp = 0.0 if (z <= -1e-104) tmp = t_3; elseif (z <= 1e-196) tmp = Float64(t_2 - Float64(Float64(z * y) / t_1)); else tmp = t_3; end return tmp end
function tmp = code(x, y, z, t, a) tmp = (x - (y * z)) / (t - (a * z)); end
function tmp_2 = code(x, y, z, t, a) t_1 = t - (z * a); t_2 = x / t_1; t_3 = t_2 - (y / ((t / z) - a)); tmp = 0.0; if (z <= -1e-104) tmp = t_3; elseif (z <= 1e-196) tmp = t_2 - ((z * y) / t_1); else tmp = t_3; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 - N[(y / N[(N[(t / z), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e-104], t$95$3, If[LessEqual[z, 1e-196], N[(t$95$2 - N[(N[(z * y), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x}{t_1}\\
t_3 := t_2 - \frac{y}{\frac{t}{z} - a}\\
\mathbf{if}\;z \leq -1 \cdot 10^{-104}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;z \leq 10^{-196}:\\
\;\;\;\;t_2 - \frac{z \cdot y}{t_1}\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}
Results
| Original | 10.6 |
|---|---|
| Target | 1.6 |
| Herbie | 2.1 |
if z < -9.99999999999999927e-105 or 1e-196 < z Initial program 14.3
Taylor expanded in x around 0 14.3
Simplified9.6
Taylor expanded in t around 0 2.8
Simplified2.8
if -9.99999999999999927e-105 < z < 1e-196Initial program 0.1
Taylor expanded in x around 0 0.1
Simplified3.8
Taylor expanded in y around 0 0.1
Final simplification2.1
herbie shell --seed 2022185
(FPCore (x y z t a)
:name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, A"
:precision binary64
:herbie-target
(if (< z -32113435955957344.0) (- (/ x (- t (* a z))) (/ y (- (/ t z) a))) (if (< z 3.5139522372978296e-86) (* (- x (* y z)) (/ 1.0 (- t (* a z)))) (- (/ x (- t (* a z))) (/ y (- (/ t z) a)))))
(/ (- x (* y z)) (- t (* a z))))