
(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 (/ (- x) y)))
(if (<= y -3.5e+72)
1.0
(if (<= y -12000000000000.0)
t_0
(if (<= y 1.0) (- x y) (if (<= y 1.75e+41) t_0 1.0))))))
double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (y <= -3.5e+72) {
tmp = 1.0;
} else if (y <= -12000000000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = x - y;
} else if (y <= 1.75e+41) {
tmp = t_0;
} else {
tmp = 1.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 = -x / y
if (y <= (-3.5d+72)) then
tmp = 1.0d0
else if (y <= (-12000000000000.0d0)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = x - y
else if (y <= 1.75d+41) then
tmp = t_0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (y <= -3.5e+72) {
tmp = 1.0;
} else if (y <= -12000000000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = x - y;
} else if (y <= 1.75e+41) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = -x / y tmp = 0 if y <= -3.5e+72: tmp = 1.0 elif y <= -12000000000000.0: tmp = t_0 elif y <= 1.0: tmp = x - y elif y <= 1.75e+41: tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(Float64(-x) / y) tmp = 0.0 if (y <= -3.5e+72) tmp = 1.0; elseif (y <= -12000000000000.0) tmp = t_0; elseif (y <= 1.0) tmp = Float64(x - y); elseif (y <= 1.75e+41) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = -x / y; tmp = 0.0; if (y <= -3.5e+72) tmp = 1.0; elseif (y <= -12000000000000.0) tmp = t_0; elseif (y <= 1.0) tmp = x - y; elseif (y <= 1.75e+41) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[((-x) / y), $MachinePrecision]}, If[LessEqual[y, -3.5e+72], 1.0, If[LessEqual[y, -12000000000000.0], t$95$0, If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], If[LessEqual[y, 1.75e+41], t$95$0, 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{y}\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+72}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -12000000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+41}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.5000000000000001e72 or 1.75e41 < y Initial program 100.0%
Taylor expanded in y around inf 75.2%
if -3.5000000000000001e72 < y < -1.2e13 or 1 < y < 1.75e41Initial program 100.0%
Taylor expanded in x around inf 75.7%
Taylor expanded in y around inf 71.6%
neg-mul-171.6%
distribute-neg-frac71.6%
Simplified71.6%
if -1.2e13 < y < 1Initial program 100.0%
Taylor expanded in y around 0 92.7%
+-commutative92.7%
mul-1-neg92.7%
*-commutative92.7%
distribute-lft-neg-in92.7%
cancel-sign-sub92.7%
+-commutative92.7%
metadata-eval92.7%
distribute-lft-in92.7%
metadata-eval92.7%
sub-neg92.7%
mul-1-neg92.7%
remove-double-neg92.7%
sub-neg92.7%
metadata-eval92.7%
+-commutative92.7%
distribute-neg-in92.7%
metadata-eval92.7%
mul-1-neg92.7%
*-commutative92.7%
mul-1-neg92.7%
unsub-neg92.7%
Simplified92.7%
Taylor expanded in x around 0 92.4%
Final simplification83.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (+ 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 + ((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 + ((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 + ((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 + ((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(Float64(1.0 - 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 + ((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[(N[(1.0 - x), $MachinePrecision] / 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{1 - 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 96.6%
+-commutative96.6%
associate-+r+96.6%
mul-1-neg96.6%
unsub-neg96.6%
div-sub96.6%
unsub-neg96.6%
mul-1-neg96.6%
+-commutative96.6%
metadata-eval96.6%
distribute-lft-in96.6%
metadata-eval96.6%
sub-neg96.6%
associate-*r/96.6%
+-commutative96.6%
associate-*r/96.6%
sub-neg96.6%
metadata-eval96.6%
distribute-lft-in96.6%
metadata-eval96.6%
+-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
*-commutative96.6%
distribute-lft-neg-in96.6%
cancel-sign-sub96.6%
+-commutative96.6%
metadata-eval96.6%
distribute-lft-in96.6%
metadata-eval96.6%
sub-neg96.6%
mul-1-neg96.6%
remove-double-neg96.6%
sub-neg96.6%
metadata-eval96.6%
+-commutative96.6%
distribute-neg-in96.6%
metadata-eval96.6%
mul-1-neg96.6%
*-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Taylor expanded in x around 0 96.0%
Final simplification96.3%
(FPCore (x y) :precision binary64 (if (or (<= y -0.95) (not (<= y 1.0))) (+ 1.0 (/ (- 1.0 x) y)) (- x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y <= -0.95) || !(y <= 1.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x - (y * (1.0 - x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-0.95d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 + ((1.0d0 - x) / y)
else
tmp = x - (y * (1.0d0 - x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.95) || !(y <= 1.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x - (y * (1.0 - x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.95) or not (y <= 1.0): tmp = 1.0 + ((1.0 - x) / y) else: tmp = x - (y * (1.0 - x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.95) || !(y <= 1.0)) tmp = Float64(1.0 + Float64(Float64(1.0 - x) / y)); else tmp = Float64(x - Float64(y * Float64(1.0 - x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.95) || ~((y <= 1.0))) tmp = 1.0 + ((1.0 - x) / y); else tmp = x - (y * (1.0 - x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.95], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.95 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -0.94999999999999996 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 96.0%
+-commutative96.0%
associate-+r+96.0%
mul-1-neg96.0%
unsub-neg96.0%
div-sub96.0%
unsub-neg96.0%
mul-1-neg96.0%
+-commutative96.0%
metadata-eval96.0%
distribute-lft-in96.0%
metadata-eval96.0%
sub-neg96.0%
associate-*r/96.0%
+-commutative96.0%
associate-*r/96.0%
sub-neg96.0%
metadata-eval96.0%
distribute-lft-in96.0%
metadata-eval96.0%
+-commutative96.0%
mul-1-neg96.0%
unsub-neg96.0%
Simplified96.0%
if -0.94999999999999996 < y < 1Initial program 100.0%
Taylor expanded in y around 0 97.2%
+-commutative97.2%
mul-1-neg97.2%
*-commutative97.2%
distribute-lft-neg-in97.2%
cancel-sign-sub97.2%
+-commutative97.2%
metadata-eval97.2%
distribute-lft-in97.2%
metadata-eval97.2%
sub-neg97.2%
mul-1-neg97.2%
remove-double-neg97.2%
sub-neg97.2%
metadata-eval97.2%
+-commutative97.2%
distribute-neg-in97.2%
metadata-eval97.2%
mul-1-neg97.2%
*-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
Final simplification96.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%
flip--56.0%
associate-/r/55.8%
metadata-eval55.8%
+-commutative55.8%
Applied egg-rr55.8%
associate-*l/44.9%
associate-/l*56.0%
Simplified56.0%
Taylor expanded in y around inf 95.9%
neg-mul-195.9%
Simplified95.9%
Taylor expanded in x around 0 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
*-commutative96.6%
distribute-lft-neg-in96.6%
cancel-sign-sub96.6%
+-commutative96.6%
metadata-eval96.6%
distribute-lft-in96.6%
metadata-eval96.6%
sub-neg96.6%
mul-1-neg96.6%
remove-double-neg96.6%
sub-neg96.6%
metadata-eval96.6%
+-commutative96.6%
distribute-neg-in96.6%
metadata-eval96.6%
mul-1-neg96.6%
*-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Taylor expanded in x around 0 96.0%
Final simplification96.0%
(FPCore (x y) :precision binary64 (if (<= y -700.0) 1.0 (if (<= y 1.0) (- x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -700.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 <= (-700.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 <= -700.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 <= -700.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 <= -700.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 <= -700.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, -700.0], 1.0, If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -700:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -700 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 64.5%
if -700 < y < 1Initial program 100.0%
Taylor expanded in y around 0 94.6%
+-commutative94.6%
mul-1-neg94.6%
*-commutative94.6%
distribute-lft-neg-in94.6%
cancel-sign-sub94.6%
+-commutative94.6%
metadata-eval94.6%
distribute-lft-in94.6%
metadata-eval94.6%
sub-neg94.6%
mul-1-neg94.6%
remove-double-neg94.6%
sub-neg94.6%
metadata-eval94.6%
+-commutative94.6%
distribute-neg-in94.6%
metadata-eval94.6%
mul-1-neg94.6%
*-commutative94.6%
mul-1-neg94.6%
unsub-neg94.6%
Simplified94.6%
Taylor expanded in x around 0 94.2%
Final simplification79.7%
(FPCore (x y) :precision binary64 (if (<= y -66.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -66.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 <= (-66.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 <= -66.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 <= -66.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 <= -66.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 <= -66.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, -66.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -66:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -66 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 64.5%
if -66 < y < 1Initial program 100.0%
Taylor expanded in y around 0 67.6%
Final simplification66.1%
(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 33.2%
Final simplification33.2%
herbie shell --seed 2023268
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))