(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 (* y z)) t_1)))
(if (<= t_2 -4e-314)
(- (/ x t_1) (/ y (/ t_1 z)))
(if (<= t_2 0.0)
(+ (/ y a) (/ (- (* t (/ y (* a a))) (/ x a)) z))
(if (<= t_2 2e+305) t_2 (/ (- y (/ x z)) a))))))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 - (y * z)) / t_1;
double tmp;
if (t_2 <= -4e-314) {
tmp = (x / t_1) - (y / (t_1 / z));
} else if (t_2 <= 0.0) {
tmp = (y / a) + (((t * (y / (a * a))) - (x / a)) / z);
} else if (t_2 <= 2e+305) {
tmp = t_2;
} else {
tmp = (y - (x / z)) / a;
}
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) :: tmp
t_1 = t - (z * a)
t_2 = (x - (y * z)) / t_1
if (t_2 <= (-4d-314)) then
tmp = (x / t_1) - (y / (t_1 / z))
else if (t_2 <= 0.0d0) then
tmp = (y / a) + (((t * (y / (a * a))) - (x / a)) / z)
else if (t_2 <= 2d+305) then
tmp = t_2
else
tmp = (y - (x / z)) / a
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 - (y * z)) / t_1;
double tmp;
if (t_2 <= -4e-314) {
tmp = (x / t_1) - (y / (t_1 / z));
} else if (t_2 <= 0.0) {
tmp = (y / a) + (((t * (y / (a * a))) - (x / a)) / z);
} else if (t_2 <= 2e+305) {
tmp = t_2;
} else {
tmp = (y - (x / z)) / a;
}
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 - (y * z)) / t_1 tmp = 0 if t_2 <= -4e-314: tmp = (x / t_1) - (y / (t_1 / z)) elif t_2 <= 0.0: tmp = (y / a) + (((t * (y / (a * a))) - (x / a)) / z) elif t_2 <= 2e+305: tmp = t_2 else: tmp = (y - (x / z)) / a 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(Float64(x - Float64(y * z)) / t_1) tmp = 0.0 if (t_2 <= -4e-314) tmp = Float64(Float64(x / t_1) - Float64(y / Float64(t_1 / z))); elseif (t_2 <= 0.0) tmp = Float64(Float64(y / a) + Float64(Float64(Float64(t * Float64(y / Float64(a * a))) - Float64(x / a)) / z)); elseif (t_2 <= 2e+305) tmp = t_2; else tmp = Float64(Float64(y - Float64(x / z)) / a); 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 - (y * z)) / t_1; tmp = 0.0; if (t_2 <= -4e-314) tmp = (x / t_1) - (y / (t_1 / z)); elseif (t_2 <= 0.0) tmp = (y / a) + (((t * (y / (a * a))) - (x / a)) / z); elseif (t_2 <= 2e+305) tmp = t_2; else tmp = (y - (x / z)) / a; 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[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -4e-314], N[(N[(x / t$95$1), $MachinePrecision] - N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], N[(N[(y / a), $MachinePrecision] + N[(N[(N[(t * N[(y / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / a), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+305], t$95$2, N[(N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x - y \cdot z}{t_1}\\
\mathbf{if}\;t_2 \leq -4 \cdot 10^{-314}:\\
\;\;\;\;\frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{y}{a} + \frac{t \cdot \frac{y}{a \cdot a} - \frac{x}{a}}{z}\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+305}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\frac{y - \frac{x}{z}}{a}\\
\end{array}
Results
| Original | 10.0 |
|---|---|
| Target | 1.6 |
| Herbie | 4.1 |
if (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -3.9999999999e-314Initial program 4.8
Taylor expanded in x around 0 4.8
Simplified4.3
Applied egg-rr1.9
if -3.9999999999e-314 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -0.0Initial program 23.0
Taylor expanded in z around inf 28.2
Simplified16.8
if -0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 1.9999999999999999e305Initial program 0.2
Taylor expanded in x around 0 0.2
Simplified4.2
Applied egg-rr0.2
if 1.9999999999999999e305 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) Initial program 63.4
Taylor expanded in x around 0 63.4
Simplified38.2
Applied egg-rr38.0
Taylor expanded in t around 0 10.6
Simplified10.6
Final simplification4.1
herbie shell --seed 2022211
(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))))