
(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 (if (or (<= y -0.84) (not (<= y 1.0))) (- 1.0 (/ x y)) (+ x (* y (- -1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -0.84) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x + (y * (-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 <= (-0.84d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - (x / y)
else
tmp = x + (y * ((-1.0d0) - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.84) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x + (y * (-1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.84) or not (y <= 1.0): tmp = 1.0 - (x / y) else: tmp = x + (y * (-1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.84) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x + Float64(y * Float64(-1.0 - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.84) || ~((y <= 1.0))) tmp = 1.0 - (x / y); else tmp = x + (y * (-1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.84], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(-1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.84 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(-1 - y\right)\\
\end{array}
\end{array}
if y < -0.839999999999999969 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
div-sub99.1%
unsub-neg99.1%
mul-1-neg99.1%
+-commutative99.1%
metadata-eval99.1%
distribute-lft-in99.1%
metadata-eval99.1%
sub-neg99.1%
associate-*r/99.1%
mul-1-neg99.1%
unsub-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in x around inf 98.6%
if -0.839999999999999969 < y < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
distribute-lft-out100.0%
mul-1-neg100.0%
distribute-rgt-out100.0%
*-rgt-identity100.0%
unpow2100.0%
distribute-lft-in100.0%
+-commutative100.0%
distribute-rgt-neg-in100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
+-commutative100.0%
associate--r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
*-commutative99.3%
associate-*l*99.3%
+-commutative99.3%
distribute-rgt1-in99.3%
*-commutative99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (- 1.0 (/ (+ x -1.0) y)) (+ x (* y (- -1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} else {
tmp = x + (y * (-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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - ((x + (-1.0d0)) / y)
else
tmp = x + (y * ((-1.0d0) - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} else {
tmp = x + (y * (-1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 - ((x + -1.0) / y) else: tmp = x + (y * (-1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(Float64(x + -1.0) / y)); else tmp = Float64(x + Float64(y * Float64(-1.0 - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 - ((x + -1.0) / y); else tmp = x + (y * (-1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(-1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(-1 - y\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
div-sub99.1%
unsub-neg99.1%
mul-1-neg99.1%
+-commutative99.1%
metadata-eval99.1%
distribute-lft-in99.1%
metadata-eval99.1%
sub-neg99.1%
associate-*r/99.1%
mul-1-neg99.1%
unsub-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
distribute-lft-out100.0%
mul-1-neg100.0%
distribute-rgt-out100.0%
*-rgt-identity100.0%
unpow2100.0%
distribute-lft-in100.0%
+-commutative100.0%
distribute-rgt-neg-in100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
+-commutative100.0%
associate--r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
*-commutative99.3%
associate-*l*99.3%
+-commutative99.3%
distribute-rgt1-in99.3%
*-commutative99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= y -3.1e+56) 1.0 (if (<= y -340.0) (/ (- x) y) (if (<= y 1.0) (- x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -3.1e+56) {
tmp = 1.0;
} else if (y <= -340.0) {
tmp = -x / y;
} else if (y <= 1.0) {
tmp = x - 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 <= (-3.1d+56)) then
tmp = 1.0d0
else if (y <= (-340.0d0)) then
tmp = -x / y
else if (y <= 1.0d0) then
tmp = x - y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.1e+56) {
tmp = 1.0;
} else if (y <= -340.0) {
tmp = -x / y;
} else if (y <= 1.0) {
tmp = x - y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.1e+56: tmp = 1.0 elif y <= -340.0: tmp = -x / y elif y <= 1.0: tmp = x - y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.1e+56) tmp = 1.0; elseif (y <= -340.0) tmp = Float64(Float64(-x) / y); elseif (y <= 1.0) tmp = Float64(x - y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.1e+56) tmp = 1.0; elseif (y <= -340.0) tmp = -x / y; elseif (y <= 1.0) tmp = x - y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.1e+56], 1.0, If[LessEqual[y, -340.0], N[((-x) / y), $MachinePrecision], If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+56}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -340:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.10000000000000005e56 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 78.3%
if -3.10000000000000005e56 < y < -340Initial program 100.0%
Taylor expanded in x around inf 76.7%
Taylor expanded in y around inf 76.7%
associate-*r/76.7%
neg-mul-176.7%
Simplified76.7%
if -340 < y < 1Initial program 100.0%
Taylor expanded in y around 0 98.5%
mul-1-neg98.5%
*-commutative98.5%
distribute-lft-neg-in98.5%
cancel-sign-sub98.5%
+-commutative98.5%
metadata-eval98.5%
distribute-lft-in98.5%
metadata-eval98.5%
sub-neg98.5%
mul-1-neg98.5%
remove-double-neg98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
distribute-neg-in98.5%
metadata-eval98.5%
mul-1-neg98.5%
*-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Taylor expanded in x around 0 98.0%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (- 1.0 (/ x y)) (- x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - (x / y)
else
tmp = x - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 - (x / y) else: tmp = x - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 - (x / y); else tmp = x - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
div-sub99.1%
unsub-neg99.1%
mul-1-neg99.1%
+-commutative99.1%
metadata-eval99.1%
distribute-lft-in99.1%
metadata-eval99.1%
sub-neg99.1%
associate-*r/99.1%
mul-1-neg99.1%
unsub-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in x around inf 98.6%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
cancel-sign-sub99.2%
+-commutative99.2%
metadata-eval99.2%
distribute-lft-in99.2%
metadata-eval99.2%
sub-neg99.2%
mul-1-neg99.2%
remove-double-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
distribute-neg-in99.2%
metadata-eval99.2%
mul-1-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 98.6%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (<= y -16.0) 1.0 (if (<= y 1.0) (- x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -16.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x - 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 <= (-16.0d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x - y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -16.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x - y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -16.0: tmp = 1.0 elif y <= 1.0: tmp = x - y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -16.0) tmp = 1.0; elseif (y <= 1.0) tmp = Float64(x - y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -16.0) tmp = 1.0; elseif (y <= 1.0) tmp = x - y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -16.0], 1.0, If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -16 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 74.3%
if -16 < y < 1Initial program 100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
cancel-sign-sub99.2%
+-commutative99.2%
metadata-eval99.2%
distribute-lft-in99.2%
metadata-eval99.2%
sub-neg99.2%
mul-1-neg99.2%
remove-double-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
distribute-neg-in99.2%
metadata-eval99.2%
mul-1-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 98.6%
Final simplification87.0%
(FPCore (x y) :precision binary64 (if (<= y -1.65e-12) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.65e-12) {
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.65d-12)) 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.65e-12) {
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.65e-12: 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.65e-12) 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.65e-12) 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.65e-12], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-12}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.65e-12 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 72.8%
if -1.65e-12 < y < 1Initial program 100.0%
Taylor expanded in y around 0 71.0%
Final simplification71.9%
(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 37.4%
Final simplification37.4%
herbie shell --seed 2023332
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))