(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (/ y z) (/ t (- 1.0 z))))
(t_2 (- (/ (* y x) z) (/ (* t x) (- 1.0 z)))))
(if (<= t_1 -1e+195) t_2 (if (<= t_1 2e+193) (* t_1 x) t_2))))double code(double x, double y, double z, double t) {
return x * ((y / z) - (t / (1.0 - z)));
}
double code(double x, double y, double z, double t) {
double t_1 = (y / z) - (t / (1.0 - z));
double t_2 = ((y * x) / z) - ((t * x) / (1.0 - z));
double tmp;
if (t_1 <= -1e+195) {
tmp = t_2;
} else if (t_1 <= 2e+193) {
tmp = t_1 * x;
} else {
tmp = t_2;
}
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 / (1.0d0 - z)))
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (y / z) - (t / (1.0d0 - z))
t_2 = ((y * x) / z) - ((t * x) / (1.0d0 - z))
if (t_1 <= (-1d+195)) then
tmp = t_2
else if (t_1 <= 2d+193) then
tmp = t_1 * x
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x * ((y / z) - (t / (1.0 - z)));
}
public static double code(double x, double y, double z, double t) {
double t_1 = (y / z) - (t / (1.0 - z));
double t_2 = ((y * x) / z) - ((t * x) / (1.0 - z));
double tmp;
if (t_1 <= -1e+195) {
tmp = t_2;
} else if (t_1 <= 2e+193) {
tmp = t_1 * x;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): return x * ((y / z) - (t / (1.0 - z)))
def code(x, y, z, t): t_1 = (y / z) - (t / (1.0 - z)) t_2 = ((y * x) / z) - ((t * x) / (1.0 - z)) tmp = 0 if t_1 <= -1e+195: tmp = t_2 elif t_1 <= 2e+193: tmp = t_1 * x else: tmp = t_2 return tmp
function code(x, y, z, t) return Float64(x * Float64(Float64(y / z) - Float64(t / Float64(1.0 - z)))) end
function code(x, y, z, t) t_1 = Float64(Float64(y / z) - Float64(t / Float64(1.0 - z))) t_2 = Float64(Float64(Float64(y * x) / z) - Float64(Float64(t * x) / Float64(1.0 - z))) tmp = 0.0 if (t_1 <= -1e+195) tmp = t_2; elseif (t_1 <= 2e+193) tmp = Float64(t_1 * x); else tmp = t_2; end return tmp end
function tmp = code(x, y, z, t) tmp = x * ((y / z) - (t / (1.0 - z))); end
function tmp_2 = code(x, y, z, t) t_1 = (y / z) - (t / (1.0 - z)); t_2 = ((y * x) / z) - ((t * x) / (1.0 - z)); tmp = 0.0; if (t_1 <= -1e+195) tmp = t_2; elseif (t_1 <= 2e+193) tmp = t_1 * x; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x * N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision] - N[(N[(t * x), $MachinePrecision] / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+195], t$95$2, If[LessEqual[t$95$1, 2e+193], N[(t$95$1 * x), $MachinePrecision], t$95$2]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{y}{z} - \frac{t}{1 - z}\\
t_2 := \frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+195}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+193}:\\
\;\;\;\;t_1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
Results
| Original | 4.7 |
|---|---|
| Target | 4.3 |
| Herbie | 1.6 |
if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -9.99999999999999977e194 or 2.00000000000000013e193 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) Initial program 17.4
Applied egg-rr17.4
Applied egg-rr17.8
Taylor expanded in t around 0 1.5
if -9.99999999999999977e194 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 2.00000000000000013e193Initial program 1.7
Final simplification1.6
herbie shell --seed 2022210
(FPCore (x y z t)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"
:precision binary64
:herbie-target
(if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))
(* x (- (/ y z) (/ t (- 1.0 z)))))