
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -1.6e-13) (not (<= x 5e-150))) (/ (* (/ x (+ 1.0 x)) (+ y x)) y) (fma (fma (/ -1.0 y) (- x) (- x)) x x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.6e-13) || !(x <= 5e-150)) {
tmp = ((x / (1.0 + x)) * (y + x)) / y;
} else {
tmp = fma(fma((-1.0 / y), -x, -x), x, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.6e-13) || !(x <= 5e-150)) tmp = Float64(Float64(Float64(x / Float64(1.0 + x)) * Float64(y + x)) / y); else tmp = fma(fma(Float64(-1.0 / y), Float64(-x), Float64(-x)), x, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.6e-13], N[Not[LessEqual[x, 5e-150]], $MachinePrecision]], N[(N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(-1.0 / y), $MachinePrecision] * (-x) + (-x)), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-13} \lor \neg \left(x \leq 5 \cdot 10^{-150}\right):\\
\;\;\;\;\frac{\frac{x}{1 + x} \cdot \left(y + x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{y}, -x, -x\right), x, x\right)\\
\end{array}
\end{array}
if x < -1.6e-13 or 4.9999999999999999e-150 < x Initial program 83.2%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
if -1.6e-13 < x < 4.9999999999999999e-150Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
distribute-lft-out--N/A
associate-*r/N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (or (<= t_0 -500000000000.0) (not (<= t_0 2.0)))
(* (pow y -1.0) x)
(/ x (+ 1.0 x)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -500000000000.0) || !(t_0 <= 2.0)) {
tmp = pow(y, -1.0) * x;
} else {
tmp = x / (1.0 + x);
}
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 * ((x / y) + 1.0d0)) / (x + 1.0d0)
if ((t_0 <= (-500000000000.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (y ** (-1.0d0)) * x
else
tmp = x / (1.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -500000000000.0) || !(t_0 <= 2.0)) {
tmp = Math.pow(y, -1.0) * x;
} else {
tmp = x / (1.0 + x);
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if (t_0 <= -500000000000.0) or not (t_0 <= 2.0): tmp = math.pow(y, -1.0) * x else: tmp = x / (1.0 + x) return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if ((t_0 <= -500000000000.0) || !(t_0 <= 2.0)) tmp = Float64((y ^ -1.0) * x); else tmp = Float64(x / Float64(1.0 + x)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x + 1.0); tmp = 0.0; if ((t_0 <= -500000000000.0) || ~((t_0 <= 2.0))) tmp = (y ^ -1.0) * x; else tmp = x / (1.0 + x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -500000000000.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[Power[y, -1.0], $MachinePrecision] * x), $MachinePrecision], N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -500000000000 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;{y}^{-1} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 + x}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -5e11 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 75.8%
Taylor expanded in y around 0
unpow2N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6481.4
Applied rewrites81.4%
Taylor expanded in x around inf
Applied rewrites84.4%
if -5e11 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6487.8
Applied rewrites87.8%
Final simplification86.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 0.01)
(- x (* x x))
(if (<= t_0 1e+185) (- 1.0 (pow x -1.0)) (* (fma (- x 1.0) x 1.0) x)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= 0.01) {
tmp = x - (x * x);
} else if (t_0 <= 1e+185) {
tmp = 1.0 - pow(x, -1.0);
} else {
tmp = fma((x - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if (t_0 <= 0.01) tmp = Float64(x - Float64(x * x)); elseif (t_0 <= 1e+185) tmp = Float64(1.0 - (x ^ -1.0)); else tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.01], N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+185], N[(1.0 - N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq 0.01:\\
\;\;\;\;x - x \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{+185}:\\
\;\;\;\;1 - {x}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.0100000000000000002Initial program 91.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6459.1
Applied rewrites59.1%
Taylor expanded in x around 0
Applied rewrites66.4%
Applied rewrites66.4%
if 0.0100000000000000002 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 9.9999999999999998e184Initial program 99.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6454.1
Applied rewrites54.1%
Taylor expanded in x around inf
Applied rewrites53.7%
if 9.9999999999999998e184 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 62.4%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f643.8
Applied rewrites3.8%
Taylor expanded in x around 0
Applied rewrites24.1%
Final simplification57.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (+ y x) (pow y -1.0))) (t_1 (* (+ y x) (/ x y))))
(if (<= x -1.0)
t_0
(if (<= x -2.4e-97)
t_1
(if (<= x 5.7e-182) (* (- 1.0 x) x) (if (<= x 1.0) t_1 t_0))))))
double code(double x, double y) {
double t_0 = (y + x) * pow(y, -1.0);
double t_1 = (y + x) * (x / y);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= -2.4e-97) {
tmp = t_1;
} else if (x <= 5.7e-182) {
tmp = (1.0 - x) * x;
} else if (x <= 1.0) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = (y + x) * (y ** (-1.0d0))
t_1 = (y + x) * (x / y)
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= (-2.4d-97)) then
tmp = t_1
else if (x <= 5.7d-182) then
tmp = (1.0d0 - x) * x
else if (x <= 1.0d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y + x) * Math.pow(y, -1.0);
double t_1 = (y + x) * (x / y);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= -2.4e-97) {
tmp = t_1;
} else if (x <= 5.7e-182) {
tmp = (1.0 - x) * x;
} else if (x <= 1.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y + x) * math.pow(y, -1.0) t_1 = (y + x) * (x / y) tmp = 0 if x <= -1.0: tmp = t_0 elif x <= -2.4e-97: tmp = t_1 elif x <= 5.7e-182: tmp = (1.0 - x) * x elif x <= 1.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(y + x) * (y ^ -1.0)) t_1 = Float64(Float64(y + x) * Float64(x / y)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= -2.4e-97) tmp = t_1; elseif (x <= 5.7e-182) tmp = Float64(Float64(1.0 - x) * x); elseif (x <= 1.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (y + x) * (y ^ -1.0); t_1 = (y + x) * (x / y); tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= -2.4e-97) tmp = t_1; elseif (x <= 5.7e-182) tmp = (1.0 - x) * x; elseif (x <= 1.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] * N[Power[y, -1.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y + x), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, -2.4e-97], t$95$1, If[LessEqual[x, 5.7e-182], N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + x\right) \cdot {y}^{-1}\\
t_1 := \left(y + x\right) \cdot \frac{x}{y}\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-97}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 5.7 \cdot 10^{-182}:\\
\;\;\;\;\left(1 - x\right) \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 79.0%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites70.5%
Taylor expanded in x around inf
Applied rewrites97.7%
if -1 < x < -2.4e-97 or 5.6999999999999998e-182 < x < 1Initial program 99.7%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6493.3
Applied rewrites93.3%
Applied rewrites87.3%
Taylor expanded in x around inf
Applied rewrites4.5%
Taylor expanded in x around 0
Applied rewrites82.8%
if -2.4e-97 < x < 5.6999999999999998e-182Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6494.4
Applied rewrites94.4%
Taylor expanded in x around 0
Applied rewrites94.4%
Applied rewrites94.4%
Final simplification93.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (fma (pow y -1.0) (- x 1.0) 1.0) (fma (- (/ x y) x) x x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = fma(pow(y, -1.0), (x - 1.0), 1.0);
} else {
tmp = fma(((x / y) - x), x, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = fma((y ^ -1.0), Float64(x - 1.0), 1.0); else tmp = fma(Float64(Float64(x / y) - x), x, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[Power[y, -1.0], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\mathsf{fma}\left({y}^{-1}, x - 1, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 79.0%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6498.1
Applied rewrites98.1%
if -1 < x < 1Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
distribute-lft-out--N/A
associate-*r/N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.85))) (* (+ y x) (pow y -1.0)) (fma (- (/ x y) x) x x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.85)) {
tmp = (y + x) * pow(y, -1.0);
} else {
tmp = fma(((x / y) - x), x, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.85)) tmp = Float64(Float64(y + x) * (y ^ -1.0)); else tmp = fma(Float64(Float64(x / y) - x), x, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.85]], $MachinePrecision]], N[(N[(y + x), $MachinePrecision] * N[Power[y, -1.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.85\right):\\
\;\;\;\;\left(y + x\right) \cdot {y}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\end{array}
\end{array}
if x < -1 or 0.849999999999999978 < x Initial program 79.0%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites70.5%
Taylor expanded in x around inf
Applied rewrites97.7%
if -1 < x < 0.849999999999999978Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
distribute-lft-out--N/A
associate-*r/N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
Final simplification98.1%
(FPCore (x y) :precision binary64 (if (or (<= x -3200000000.0) (not (<= x 6000.0))) (* (+ y x) (pow y -1.0)) (/ x (+ 1.0 x))))
double code(double x, double y) {
double tmp;
if ((x <= -3200000000.0) || !(x <= 6000.0)) {
tmp = (y + x) * pow(y, -1.0);
} else {
tmp = x / (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 ((x <= (-3200000000.0d0)) .or. (.not. (x <= 6000.0d0))) then
tmp = (y + x) * (y ** (-1.0d0))
else
tmp = x / (1.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3200000000.0) || !(x <= 6000.0)) {
tmp = (y + x) * Math.pow(y, -1.0);
} else {
tmp = x / (1.0 + x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3200000000.0) or not (x <= 6000.0): tmp = (y + x) * math.pow(y, -1.0) else: tmp = x / (1.0 + x) return tmp
function code(x, y) tmp = 0.0 if ((x <= -3200000000.0) || !(x <= 6000.0)) tmp = Float64(Float64(y + x) * (y ^ -1.0)); else tmp = Float64(x / Float64(1.0 + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3200000000.0) || ~((x <= 6000.0))) tmp = (y + x) * (y ^ -1.0); else tmp = x / (1.0 + x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3200000000.0], N[Not[LessEqual[x, 6000.0]], $MachinePrecision]], N[(N[(y + x), $MachinePrecision] * N[Power[y, -1.0], $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3200000000 \lor \neg \left(x \leq 6000\right):\\
\;\;\;\;\left(y + x\right) \cdot {y}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 + x}\\
\end{array}
\end{array}
if x < -3.2e9 or 6e3 < x Initial program 78.5%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites69.9%
Taylor expanded in x around inf
Applied rewrites99.0%
if -3.2e9 < x < 6e3Initial program 99.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6475.2
Applied rewrites75.2%
Final simplification87.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (or (<= t_0 -1e+19) (not (<= t_0 1e+41)))
(/ x (+ (/ y x) y))
(/ (fma (/ x y) x x) (+ x 1.0)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -1e+19) || !(t_0 <= 1e+41)) {
tmp = x / ((y / x) + y);
} else {
tmp = fma((x / y), x, x) / (x + 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if ((t_0 <= -1e+19) || !(t_0 <= 1e+41)) tmp = Float64(x / Float64(Float64(y / x) + y)); else tmp = Float64(fma(Float64(x / y), x, x) / Float64(x + 1.0)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+19], N[Not[LessEqual[t$95$0, 1e+41]], $MachinePrecision]], N[(x / N[(N[(y / x), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+19} \lor \neg \left(t\_0 \leq 10^{+41}\right):\\
\;\;\;\;\frac{x}{\frac{y}{x} + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x + 1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e19 or 1.00000000000000001e41 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 73.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6483.8
Applied rewrites83.8%
Taylor expanded in x around 0
Applied rewrites99.9%
if -1e19 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1.00000000000000001e41Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -500000000000.0)
(* (- x) x)
(if (<= t_0 5e+181) (/ x (+ 1.0 x)) (* (fma (- x 1.0) x 1.0) x)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= -500000000000.0) {
tmp = -x * x;
} else if (t_0 <= 5e+181) {
tmp = x / (1.0 + x);
} else {
tmp = fma((x - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if (t_0 <= -500000000000.0) tmp = Float64(Float64(-x) * x); elseif (t_0 <= 5e+181) tmp = Float64(x / Float64(1.0 + x)); else tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -500000000000.0], N[((-x) * x), $MachinePrecision], If[LessEqual[t$95$0, 5e+181], N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -500000000000:\\
\;\;\;\;\left(-x\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+181}:\\
\;\;\;\;\frac{x}{1 + x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -5e11Initial program 72.3%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f641.3
Applied rewrites1.3%
Taylor expanded in x around 0
Applied rewrites26.1%
Taylor expanded in x around inf
Applied rewrites26.1%
if -5e11 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 5.0000000000000003e181Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6475.1
Applied rewrites75.1%
if 5.0000000000000003e181 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 63.4%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f643.7
Applied rewrites3.7%
Taylor expanded in x around 0
Applied rewrites23.5%
(FPCore (x y) :precision binary64 (* (/ x (+ 1.0 x)) (+ 1.0 (/ x y))))
double code(double x, double y) {
return (x / (1.0 + x)) * (1.0 + (x / y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (1.0d0 + x)) * (1.0d0 + (x / y))
end function
public static double code(double x, double y) {
return (x / (1.0 + x)) * (1.0 + (x / y));
}
def code(x, y): return (x / (1.0 + x)) * (1.0 + (x / y))
function code(x, y) return Float64(Float64(x / Float64(1.0 + x)) * Float64(1.0 + Float64(x / y))) end
function tmp = code(x, y) tmp = (x / (1.0 + x)) * (1.0 + (x / y)); end
code[x_, y_] := N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + x} \cdot \left(1 + \frac{x}{y}\right)
\end{array}
Initial program 89.2%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (if (<= y -5e-310) (* (- 1.0 x) x) (* (fma (- x 1.0) x 1.0) x)))
double code(double x, double y) {
double tmp;
if (y <= -5e-310) {
tmp = (1.0 - x) * x;
} else {
tmp = fma((x - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -5e-310) tmp = Float64(Float64(1.0 - x) * x); else tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); end return tmp end
code[x_, y_] := If[LessEqual[y, -5e-310], N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 - x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if y < -4.999999999999985e-310Initial program 87.6%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6450.9
Applied rewrites50.9%
Taylor expanded in x around 0
Applied rewrites41.4%
Applied rewrites41.4%
if -4.999999999999985e-310 < y Initial program 91.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6449.7
Applied rewrites49.7%
Taylor expanded in x around 0
Applied rewrites51.3%
(FPCore (x y) :precision binary64 (- x (* x x)))
double code(double x, double y) {
return x - (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (x * x)
end function
public static double code(double x, double y) {
return x - (x * x);
}
def code(x, y): return x - (x * x)
function code(x, y) return Float64(x - Float64(x * x)) end
function tmp = code(x, y) tmp = x - (x * x); end
code[x_, y_] := N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - x \cdot x
\end{array}
Initial program 89.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6450.4
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites42.1%
Applied rewrites42.1%
(FPCore (x y) :precision binary64 (* (- 1.0 x) x))
double code(double x, double y) {
return (1.0 - x) * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) * x
end function
public static double code(double x, double y) {
return (1.0 - x) * x;
}
def code(x, y): return (1.0 - x) * x
function code(x, y) return Float64(Float64(1.0 - x) * x) end
function tmp = code(x, y) tmp = (1.0 - x) * x; end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot x
\end{array}
Initial program 89.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6450.4
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites42.1%
Applied rewrites42.1%
(FPCore (x y) :precision binary64 (* (- x) x))
double code(double x, double y) {
return -x * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x * x
end function
public static double code(double x, double y) {
return -x * x;
}
def code(x, y): return -x * x
function code(x, y) return Float64(Float64(-x) * x) end
function tmp = code(x, y) tmp = -x * x; end
code[x_, y_] := N[((-x) * x), $MachinePrecision]
\begin{array}{l}
\\
\left(-x\right) \cdot x
\end{array}
Initial program 89.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6450.4
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites42.1%
Taylor expanded in x around inf
Applied rewrites8.1%
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
herbie shell --seed 2024318
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(! :herbie-platform default (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1))))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))