
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -12600.0) (not (<= y 55000.0))) (+ 1.0 (/ (- 1.0 x) y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -12600.0) || !(y <= 55000.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-12600.0d0)) .or. (.not. (y <= 55000.0d0))) then
tmp = 1.0d0 + ((1.0d0 - x) / y)
else
tmp = x / (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -12600.0) || !(y <= 55000.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -12600.0) or not (y <= 55000.0): tmp = 1.0 + ((1.0 - x) / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -12600.0) || !(y <= 55000.0)) tmp = Float64(1.0 + Float64(Float64(1.0 - x) / y)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -12600.0) || ~((y <= 55000.0))) tmp = 1.0 + ((1.0 - x) / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -12600.0], N[Not[LessEqual[y, 55000.0]], $MachinePrecision]], N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -12600 \lor \neg \left(y \leq 55000\right):\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -12600 or 55000 < y Initial program 99.9%
Taylor expanded in y around inf 98.9%
+-commutative98.9%
associate-+r+98.9%
mul-1-neg98.9%
unsub-neg98.9%
div-sub98.9%
unsub-neg98.9%
mul-1-neg98.9%
+-commutative98.9%
metadata-eval98.9%
distribute-lft-in98.9%
metadata-eval98.9%
sub-neg98.9%
associate-*r/98.9%
+-commutative98.9%
associate-*r/98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-lft-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
Simplified98.9%
if -12600 < y < 55000Initial program 100.0%
Taylor expanded in x around inf 76.3%
Final simplification89.4%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5e-7) (not (<= y 1.0))) (- 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -2.5e-7) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.5d-7)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.5e-7) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5e-7) or not (y <= 1.0): tmp = 1.0 - (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5e-7) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.5e-7) || ~((y <= 1.0))) tmp = 1.0 - (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.5e-7], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-7} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.49999999999999989e-7 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 96.2%
+-commutative96.2%
associate-+r+96.2%
mul-1-neg96.2%
unsub-neg96.2%
div-sub96.2%
unsub-neg96.2%
mul-1-neg96.2%
+-commutative96.2%
metadata-eval96.2%
distribute-lft-in96.2%
metadata-eval96.2%
sub-neg96.2%
associate-*r/96.2%
+-commutative96.2%
associate-*r/96.2%
sub-neg96.2%
metadata-eval96.2%
distribute-lft-in96.2%
metadata-eval96.2%
+-commutative96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
Taylor expanded in x around inf 95.6%
neg-mul-195.6%
distribute-neg-frac95.6%
Simplified95.6%
Taylor expanded in x around 0 95.6%
mul-1-neg95.6%
sub-neg95.6%
Simplified95.6%
if -2.49999999999999989e-7 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.5%
Final simplification88.4%
(FPCore (x y) :precision binary64 (if (or (<= y -280000000.0) (not (<= y 140000.0))) (- 1.0 (/ x y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -280000000.0) || !(y <= 140000.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-280000000.0d0)) .or. (.not. (y <= 140000.0d0))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -280000000.0) || !(y <= 140000.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -280000000.0) or not (y <= 140000.0): tmp = 1.0 - (x / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -280000000.0) || !(y <= 140000.0)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -280000000.0) || ~((y <= 140000.0))) tmp = 1.0 - (x / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -280000000.0], N[Not[LessEqual[y, 140000.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -280000000 \lor \neg \left(y \leq 140000\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -2.8e8 or 1.4e5 < y Initial program 99.9%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
associate-+r+99.8%
mul-1-neg99.8%
unsub-neg99.8%
div-sub99.8%
unsub-neg99.8%
mul-1-neg99.8%
+-commutative99.8%
metadata-eval99.8%
distribute-lft-in99.8%
metadata-eval99.8%
sub-neg99.8%
associate-*r/99.8%
+-commutative99.8%
associate-*r/99.8%
sub-neg99.8%
metadata-eval99.8%
distribute-lft-in99.8%
metadata-eval99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 99.5%
neg-mul-199.5%
distribute-neg-frac99.5%
Simplified99.5%
Taylor expanded in x around 0 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
if -2.8e8 < y < 1.4e5Initial program 100.0%
Taylor expanded in x around inf 75.4%
Final simplification89.0%
(FPCore (x y) :precision binary64 (if (<= y -2150.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2150.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2150.0d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2150.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2150.0: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2150.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2150.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2150.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2150:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2150 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 72.9%
if -2150 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification73.8%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 44.3%
Final simplification44.3%
herbie shell --seed 2023279
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))