
(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 8 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
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -1.0)
t_0
(if (<= y 3.5e-50) x (if (<= y 21000.0) (/ y (+ y -1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.5e-50) {
tmp = x;
} else if (y <= 21000.0) {
tmp = y / (y + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((1.0d0 - x) / y)
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 3.5d-50) then
tmp = x
else if (y <= 21000.0d0) then
tmp = y / (y + (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.5e-50) {
tmp = x;
} else if (y <= 21000.0) {
tmp = y / (y + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((1.0 - x) / y) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 3.5e-50: tmp = x elif y <= 21000.0: tmp = y / (y + -1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(1.0 - x) / y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 3.5e-50) tmp = x; elseif (y <= 21000.0) tmp = Float64(y / Float64(y + -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((1.0 - x) / y); tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 3.5e-50) tmp = x; elseif (y <= 21000.0) tmp = y / (y + -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 3.5e-50], x, If[LessEqual[y, 21000.0], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 21000:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 21000 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
sub-neg98.7%
div-sub98.7%
Simplified98.7%
if -1 < y < 3.49999999999999997e-50Initial program 100.0%
Taylor expanded in y around 0 80.1%
if 3.49999999999999997e-50 < y < 21000Initial program 100.0%
Taylor expanded in x around 0 69.2%
neg-mul-169.2%
distribute-neg-frac269.2%
neg-sub069.2%
associate--r-69.2%
metadata-eval69.2%
Simplified69.2%
Final simplification89.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -0.031)
t_0
(if (<= y 2.9e-50) x (if (<= y 116000.0) (/ y (+ y -1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -0.031) {
tmp = t_0;
} else if (y <= 2.9e-50) {
tmp = x;
} else if (y <= 116000.0) {
tmp = y / (y + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (y <= (-0.031d0)) then
tmp = t_0
else if (y <= 2.9d-50) then
tmp = x
else if (y <= 116000.0d0) then
tmp = y / (y + (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -0.031) {
tmp = t_0;
} else if (y <= 2.9e-50) {
tmp = x;
} else if (y <= 116000.0) {
tmp = y / (y + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if y <= -0.031: tmp = t_0 elif y <= 2.9e-50: tmp = x elif y <= 116000.0: tmp = y / (y + -1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -0.031) tmp = t_0; elseif (y <= 2.9e-50) tmp = x; elseif (y <= 116000.0) tmp = Float64(y / Float64(y + -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -0.031) tmp = t_0; elseif (y <= 2.9e-50) tmp = x; elseif (y <= 116000.0) tmp = y / (y + -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.031], t$95$0, If[LessEqual[y, 2.9e-50], x, If[LessEqual[y, 116000.0], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -0.031:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 116000:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.031 or 116000 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
sub-neg98.7%
div-sub98.7%
Simplified98.7%
Taylor expanded in x around inf 97.5%
neg-mul-197.5%
distribute-neg-frac297.5%
Simplified97.5%
if -0.031 < y < 2.90000000000000008e-50Initial program 100.0%
Taylor expanded in y around 0 80.1%
if 2.90000000000000008e-50 < y < 116000Initial program 100.0%
Taylor expanded in x around 0 69.2%
neg-mul-169.2%
distribute-neg-frac269.2%
neg-sub069.2%
associate--r-69.2%
metadata-eval69.2%
Simplified69.2%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= y -58.0) 1.0 (if (<= y 2.95e-50) x (if (<= y 6200000.0) (- y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -58.0) {
tmp = 1.0;
} else if (y <= 2.95e-50) {
tmp = x;
} else if (y <= 6200000.0) {
tmp = -y;
} 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 <= (-58.0d0)) then
tmp = 1.0d0
else if (y <= 2.95d-50) then
tmp = x
else if (y <= 6200000.0d0) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -58.0) {
tmp = 1.0;
} else if (y <= 2.95e-50) {
tmp = x;
} else if (y <= 6200000.0) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -58.0: tmp = 1.0 elif y <= 2.95e-50: tmp = x elif y <= 6200000.0: tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -58.0) tmp = 1.0; elseif (y <= 2.95e-50) tmp = x; elseif (y <= 6200000.0) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -58.0) tmp = 1.0; elseif (y <= 2.95e-50) tmp = x; elseif (y <= 6200000.0) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -58.0], 1.0, If[LessEqual[y, 2.95e-50], x, If[LessEqual[y, 6200000.0], (-y), 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -58:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6200000:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -58 or 6.2e6 < y Initial program 100.0%
Taylor expanded in y around inf 71.6%
if -58 < y < 2.95e-50Initial program 100.0%
Taylor expanded in y around 0 80.1%
if 2.95e-50 < y < 6.2e6Initial program 100.0%
Taylor expanded in x around 0 62.9%
neg-mul-162.9%
distribute-neg-frac262.9%
neg-sub062.9%
associate--r-62.9%
metadata-eval62.9%
Simplified62.9%
Taylor expanded in y around 0 60.1%
neg-mul-160.1%
Simplified60.1%
Final simplification74.0%
(FPCore (x y) :precision binary64 (if (<= y -1.9e+18) 1.0 (if (<= y 3.5e-50) (/ x (- 1.0 y)) (if (<= y 6200000.0) (- y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.9e+18) {
tmp = 1.0;
} else if (y <= 3.5e-50) {
tmp = x / (1.0 - y);
} else if (y <= 6200000.0) {
tmp = -y;
} 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 <= (-1.9d+18)) then
tmp = 1.0d0
else if (y <= 3.5d-50) then
tmp = x / (1.0d0 - y)
else if (y <= 6200000.0d0) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.9e+18) {
tmp = 1.0;
} else if (y <= 3.5e-50) {
tmp = x / (1.0 - y);
} else if (y <= 6200000.0) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.9e+18: tmp = 1.0 elif y <= 3.5e-50: tmp = x / (1.0 - y) elif y <= 6200000.0: tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.9e+18) tmp = 1.0; elseif (y <= 3.5e-50) tmp = Float64(x / Float64(1.0 - y)); elseif (y <= 6200000.0) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.9e+18) tmp = 1.0; elseif (y <= 3.5e-50) tmp = x / (1.0 - y); elseif (y <= 6200000.0) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.9e+18], 1.0, If[LessEqual[y, 3.5e-50], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6200000.0], (-y), 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+18}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-50}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{elif}\;y \leq 6200000:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.9e18 or 6.2e6 < y Initial program 100.0%
Taylor expanded in y around inf 73.2%
if -1.9e18 < y < 3.49999999999999997e-50Initial program 100.0%
Taylor expanded in x around inf 78.5%
if 3.49999999999999997e-50 < y < 6.2e6Initial program 100.0%
Taylor expanded in x around 0 62.9%
neg-mul-162.9%
distribute-neg-frac262.9%
neg-sub062.9%
associate--r-62.9%
metadata-eval62.9%
Simplified62.9%
Taylor expanded in y around 0 60.1%
neg-mul-160.1%
Simplified60.1%
Final simplification74.4%
(FPCore (x y) :precision binary64 (if (or (<= x -2.05e-14) (not (<= x 4.1e+33))) (/ x (- 1.0 y)) (/ y (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -2.05e-14) || !(x <= 4.1e+33)) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.05d-14)) .or. (.not. (x <= 4.1d+33))) then
tmp = x / (1.0d0 - y)
else
tmp = y / (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.05e-14) || !(x <= 4.1e+33)) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.05e-14) or not (x <= 4.1e+33): tmp = x / (1.0 - y) else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.05e-14) || !(x <= 4.1e+33)) tmp = Float64(x / Float64(1.0 - y)); else tmp = Float64(y / Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.05e-14) || ~((x <= 4.1e+33))) tmp = x / (1.0 - y); else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.05e-14], N[Not[LessEqual[x, 4.1e+33]], $MachinePrecision]], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-14} \lor \neg \left(x \leq 4.1 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if x < -2.0500000000000001e-14 or 4.09999999999999995e33 < x Initial program 100.0%
Taylor expanded in x around inf 79.6%
if -2.0500000000000001e-14 < x < 4.09999999999999995e33Initial program 100.0%
Taylor expanded in x around 0 79.9%
neg-mul-179.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate--r-79.9%
metadata-eval79.9%
Simplified79.9%
Final simplification79.8%
(FPCore (x y) :precision binary64 (if (<= y -1.55) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.55) {
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 <= (-1.55d0)) 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 <= -1.55) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.55: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.55) 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 <= -1.55) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.55], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.55000000000000004 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 70.6%
if -1.55000000000000004 < y < 1Initial program 100.0%
Taylor expanded in y around 0 71.5%
Final simplification71.0%
(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 39.2%
Final simplification39.2%
herbie shell --seed 2024076
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))