
(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 9 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%
(FPCore (x y)
:precision binary64
(if (<= y -3e+20)
1.0
(if (<= y -1.28e-5)
(/ x (- 1.0 y))
(if (<= y 4.2e-6) (- x y) (/ y (+ y -1.0))))))
double code(double x, double y) {
double tmp;
if (y <= -3e+20) {
tmp = 1.0;
} else if (y <= -1.28e-5) {
tmp = x / (1.0 - y);
} else if (y <= 4.2e-6) {
tmp = x - 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 (y <= (-3d+20)) then
tmp = 1.0d0
else if (y <= (-1.28d-5)) then
tmp = x / (1.0d0 - y)
else if (y <= 4.2d-6) then
tmp = x - y
else
tmp = y / (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3e+20) {
tmp = 1.0;
} else if (y <= -1.28e-5) {
tmp = x / (1.0 - y);
} else if (y <= 4.2e-6) {
tmp = x - y;
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+20: tmp = 1.0 elif y <= -1.28e-5: tmp = x / (1.0 - y) elif y <= 4.2e-6: tmp = x - y else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+20) tmp = 1.0; elseif (y <= -1.28e-5) tmp = Float64(x / Float64(1.0 - y)); elseif (y <= 4.2e-6) tmp = Float64(x - y); else tmp = Float64(y / Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+20) tmp = 1.0; elseif (y <= -1.28e-5) tmp = x / (1.0 - y); elseif (y <= 4.2e-6) tmp = x - y; else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+20], 1.0, If[LessEqual[y, -1.28e-5], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.2e-6], N[(x - y), $MachinePrecision], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+20}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.28 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-6}:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if y < -3e20Initial program 100.0%
Taylor expanded in y around inf 90.1%
if -3e20 < y < -1.2799999999999999e-5Initial program 99.8%
Taylor expanded in x around inf 87.5%
if -1.2799999999999999e-5 < y < 4.1999999999999996e-6Initial program 99.9%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
mul-1-neg100.0%
associate-*r*100.0%
neg-mul-1100.0%
mul-1-neg100.0%
sub-neg100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
Taylor expanded in y around 0 97.8%
neg-mul-197.8%
unsub-neg97.8%
Simplified97.8%
if 4.1999999999999996e-6 < y Initial program 100.0%
Taylor expanded in x around 0 73.2%
neg-mul-173.2%
distribute-neg-frac273.2%
neg-sub073.2%
associate--r-73.2%
metadata-eval73.2%
Simplified73.2%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= y -3.6e+20) 1.0 (if (<= y -1.4e-6) (/ x (- 1.0 y)) (if (<= y 1.0) (- x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -3.6e+20) {
tmp = 1.0;
} else if (y <= -1.4e-6) {
tmp = x / (1.0 - 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.6d+20)) then
tmp = 1.0d0
else if (y <= (-1.4d-6)) then
tmp = x / (1.0d0 - 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.6e+20) {
tmp = 1.0;
} else if (y <= -1.4e-6) {
tmp = x / (1.0 - y);
} else if (y <= 1.0) {
tmp = x - y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.6e+20: tmp = 1.0 elif y <= -1.4e-6: tmp = x / (1.0 - y) elif y <= 1.0: tmp = x - y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.6e+20) tmp = 1.0; elseif (y <= -1.4e-6) tmp = Float64(x / Float64(1.0 - 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.6e+20) tmp = 1.0; elseif (y <= -1.4e-6) tmp = x / (1.0 - y); elseif (y <= 1.0) tmp = x - y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.6e+20], 1.0, If[LessEqual[y, -1.4e-6], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+20}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.6e20 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 79.7%
if -3.6e20 < y < -1.39999999999999994e-6Initial program 99.8%
Taylor expanded in x around inf 87.5%
if -1.39999999999999994e-6 < y < 1Initial program 99.9%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
mul-1-neg100.0%
associate-*r*100.0%
neg-mul-1100.0%
mul-1-neg100.0%
sub-neg100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
Taylor expanded in y around 0 97.8%
neg-mul-197.8%
unsub-neg97.8%
Simplified97.8%
(FPCore (x y) :precision binary64 (if (or (<= y -0.8) (not (<= y 1.0))) (/ (- y x) y) (+ x (* y (- -1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -0.8) || !(y <= 1.0)) {
tmp = (y - 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.8d0)) .or. (.not. (y <= 1.0d0))) then
tmp = (y - 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.8) || !(y <= 1.0)) {
tmp = (y - x) / y;
} else {
tmp = x + (y * (-1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.8) or not (y <= 1.0): tmp = (y - x) / y else: tmp = x + (y * (-1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.8) || !(y <= 1.0)) tmp = Float64(Float64(y - 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.8) || ~((y <= 1.0))) tmp = (y - x) / y; else tmp = x + (y * (-1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.8], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision], N[(x + N[(y * N[(-1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.8 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{y - x}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(-1 - y\right)\\
\end{array}
\end{array}
if y < -0.80000000000000004 or 1 < y Initial program 100.0%
expm1-log1p-u40.5%
Applied egg-rr40.5%
expm1-undefine40.5%
sub-neg40.5%
log1p-undefine40.5%
rem-exp-log100.0%
associate-+r-100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
Simplified98.4%
Taylor expanded in y around 0 98.4%
neg-mul-198.4%
unsub-neg98.4%
Simplified98.4%
if -0.80000000000000004 < y < 1Initial program 99.9%
Taylor expanded in y around 0 99.1%
mul-1-neg99.1%
associate-*r*99.1%
neg-mul-199.1%
mul-1-neg99.1%
sub-neg99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in x around 0 98.0%
sub-neg98.0%
mul-1-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
distribute-neg-in98.0%
metadata-eval98.0%
sub-neg98.0%
Simplified98.0%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (<= y -0.000235) 1.0 (if (<= y -2.9e-82) (- y) (if (<= y 1.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -0.000235) {
tmp = 1.0;
} else if (y <= -2.9e-82) {
tmp = -y;
} 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 <= (-0.000235d0)) then
tmp = 1.0d0
else if (y <= (-2.9d-82)) then
tmp = -y
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 <= -0.000235) {
tmp = 1.0;
} else if (y <= -2.9e-82) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.000235: tmp = 1.0 elif y <= -2.9e-82: tmp = -y elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.000235) tmp = 1.0; elseif (y <= -2.9e-82) tmp = Float64(-y); 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 <= -0.000235) tmp = 1.0; elseif (y <= -2.9e-82) tmp = -y; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.000235], 1.0, If[LessEqual[y, -2.9e-82], (-y), If[LessEqual[y, 1.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000235:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{-82}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.34999999999999993e-4 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 75.9%
if -2.34999999999999993e-4 < y < -2.89999999999999977e-82Initial program 99.8%
Taylor expanded in x around 0 69.4%
neg-mul-169.4%
distribute-neg-frac269.4%
neg-sub069.4%
associate--r-69.4%
metadata-eval69.4%
Simplified69.4%
Taylor expanded in y around 0 62.3%
neg-mul-162.3%
Simplified62.3%
if -2.89999999999999977e-82 < y < 1Initial program 100.0%
Taylor expanded in y around 0 80.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (/ (- y x) y) (- x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = (y - 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 = (y - 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 = (y - x) / y;
} else {
tmp = x - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = (y - x) / y else: tmp = x - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(Float64(y - 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 = (y - 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[(N[(y - x), $MachinePrecision] / y), $MachinePrecision], N[(x - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{y - x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
expm1-log1p-u40.5%
Applied egg-rr40.5%
expm1-undefine40.5%
sub-neg40.5%
log1p-undefine40.5%
rem-exp-log100.0%
associate-+r-100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
Simplified98.4%
Taylor expanded in y around 0 98.4%
neg-mul-198.4%
unsub-neg98.4%
Simplified98.4%
if -1 < y < 1Initial program 99.9%
Taylor expanded in y around 0 99.4%
mul-1-neg99.4%
mul-1-neg99.4%
associate-*r*99.4%
neg-mul-199.4%
mul-1-neg99.4%
sub-neg99.4%
sub-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in x around 0 98.2%
Taylor expanded in y around 0 96.7%
neg-mul-196.7%
unsub-neg96.7%
Simplified96.7%
Final simplification97.6%
(FPCore (x y) :precision binary64 (if (<= y -1200000.0) 1.0 (if (<= y 1.0) (- x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1200000.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 <= (-1200000.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 <= -1200000.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 <= -1200000.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 <= -1200000.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 <= -1200000.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, -1200000.0], 1.0, If[LessEqual[y, 1.0], N[(x - y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.2e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 78.1%
if -1.2e6 < y < 1Initial program 99.9%
Taylor expanded in y around 0 97.8%
mul-1-neg97.8%
mul-1-neg97.8%
associate-*r*97.8%
neg-mul-197.8%
mul-1-neg97.8%
sub-neg97.8%
sub-neg97.8%
sub-neg97.8%
Simplified97.8%
Taylor expanded in x around 0 96.8%
Taylor expanded in y around 0 95.3%
neg-mul-195.3%
unsub-neg95.3%
Simplified95.3%
(FPCore (x y) :precision binary64 (if (<= y -1200000.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1200000.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 <= (-1200000.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 <= -1200000.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 <= -1200000.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 <= -1200000.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 <= -1200000.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, -1200000.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.2e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 78.1%
if -1.2e6 < y < 1Initial program 99.9%
Taylor expanded in y around 0 70.5%
(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 43.1%
herbie shell --seed 2024177
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))