
(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 13 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 (let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (/ x (+ (/ y x) y)))) (if (<= t_0 -1e+162) t_1 (if (<= t_0 200000000.0) t_0 t_1))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = x / ((y / x) + y);
double tmp;
if (t_0 <= -1e+162) {
tmp = t_1;
} else if (t_0 <= 200000000.0) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = (((x / y) - (-1.0d0)) * x) / (x - (-1.0d0))
t_1 = x / ((y / x) + y)
if (t_0 <= (-1d+162)) then
tmp = t_1
else if (t_0 <= 200000000.0d0) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = x / ((y / x) + y);
double tmp;
if (t_0 <= -1e+162) {
tmp = t_1;
} else if (t_0 <= 200000000.0) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (((x / y) - -1.0) * x) / (x - -1.0) t_1 = x / ((y / x) + y) tmp = 0 if t_0 <= -1e+162: tmp = t_1 elif t_0 <= 200000000.0: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(x / Float64(Float64(y / x) + y)) tmp = 0.0 if (t_0 <= -1e+162) tmp = t_1; elseif (t_0 <= 200000000.0) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (((x / y) - -1.0) * x) / (x - -1.0); t_1 = x / ((y / x) + y); tmp = 0.0; if (t_0 <= -1e+162) tmp = t_1; elseif (t_0 <= 200000000.0) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(N[(y / x), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+162], t$95$1, If[LessEqual[t$95$0, 200000000.0], t$95$0, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{x}{\frac{y}{x} + y}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+162}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 200000000:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -9.9999999999999994e161 or 2e8 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 75.3%
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.f6491.1
Applied rewrites91.1%
Applied rewrites99.9%
if -9.9999999999999994e161 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2e8Initial program 99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (/ (- x 1.0) y)))
(if (<= t_0 -1000.0)
t_1
(if (<= t_0 0.5)
(* (fma (- x 1.0) x 1.0) x)
(if (<= t_0 2.0) (- 1.0 (/ 1.0 x)) t_1)))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 0.5) {
tmp = fma((x - 1.0), x, 1.0) * x;
} else if (t_0 <= 2.0) {
tmp = 1.0 - (1.0 / x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 0.5) tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); elseif (t_0 <= 2.0) tmp = Float64(1.0 - Float64(1.0 / x)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -1000.0], t$95$1, If[LessEqual[t$95$0, 0.5], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(1.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{x - 1}{y}\\
\mathbf{if}\;t\_0 \leq -1000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 - \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
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.f6487.0
Applied rewrites87.0%
Taylor expanded in x around inf
Applied rewrites81.8%
Taylor expanded in x around inf
Applied rewrites81.1%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.5Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Taylor expanded in y around inf
Applied rewrites86.0%
if 0.5 < (/.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
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6497.6
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites93.8%
Final simplification84.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (/ (- x 1.0) y)))
(if (<= t_0 -1000.0)
t_1
(if (<= t_0 0.5)
(fma (- x) x x)
(if (<= t_0 2.0) (- 1.0 (/ 1.0 x)) t_1)))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 0.5) {
tmp = fma(-x, x, x);
} else if (t_0 <= 2.0) {
tmp = 1.0 - (1.0 / x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 0.5) tmp = fma(Float64(-x), x, x); elseif (t_0 <= 2.0) tmp = Float64(1.0 - Float64(1.0 / x)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -1000.0], t$95$1, If[LessEqual[t$95$0, 0.5], N[((-x) * x + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(1.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{x - 1}{y}\\
\mathbf{if}\;t\_0 \leq -1000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(-x, x, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 - \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
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.f6487.0
Applied rewrites87.0%
Taylor expanded in x around inf
Applied rewrites81.8%
Taylor expanded in x around inf
Applied rewrites81.1%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.5Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6486.7
Applied rewrites86.7%
Taylor expanded in x around 0
Applied rewrites85.9%
if 0.5 < (/.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
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6497.6
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites93.8%
Final simplification84.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (/ x (+ (/ y x) y))))
(if (<= t_0 -1e+162)
t_1
(if (<= t_0 200000000.0) (/ (fma (/ x y) x x) (- x -1.0)) t_1))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = x / ((y / x) + y);
double tmp;
if (t_0 <= -1e+162) {
tmp = t_1;
} else if (t_0 <= 200000000.0) {
tmp = fma((x / y), x, x) / (x - -1.0);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(x / Float64(Float64(y / x) + y)) tmp = 0.0 if (t_0 <= -1e+162) tmp = t_1; elseif (t_0 <= 200000000.0) tmp = Float64(fma(Float64(x / y), x, x) / Float64(x - -1.0)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(N[(y / x), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+162], t$95$1, If[LessEqual[t$95$0, 200000000.0], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{x}{\frac{y}{x} + y}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+162}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 200000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -9.9999999999999994e161 or 2e8 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 75.3%
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.f6491.1
Applied rewrites91.1%
Applied rewrites99.9%
if -9.9999999999999994e161 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2e8Initial program 99.9%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (* (/ 1.0 y) x))) (if (<= t_0 -1000.0) t_1 (if (<= t_0 2.0) (/ x (- x -1.0)) t_1))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (1.0 / y) * x;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = t_1;
}
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 = (((x / y) - (-1.0d0)) * x) / (x - (-1.0d0))
t_1 = (1.0d0 / y) * x
if (t_0 <= (-1000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x / (x - (-1.0d0))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (1.0 / y) * x;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (((x / y) - -1.0) * x) / (x - -1.0) t_1 = (1.0 / y) * x tmp = 0 if t_0 <= -1000.0: tmp = t_1 elif t_0 <= 2.0: tmp = x / (x - -1.0) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(Float64(1.0 / y) * x) tmp = 0.0 if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (((x / y) - -1.0) * x) / (x - -1.0); t_1 = (1.0 / y) * x; tmp = 0.0; if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x / (x - -1.0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -1000.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{1}{y} \cdot x\\
\mathbf{if}\;t\_0 \leq -1000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
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.f6487.0
Applied rewrites87.0%
Taylor expanded in x around inf
Applied rewrites81.8%
if -1e3 < (/.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
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6489.0
Applied rewrites89.0%
Final simplification85.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- (/ x y) -1.0) x) (- x -1.0))) (t_1 (/ (- x 1.0) y))) (if (<= t_0 -1000.0) t_1 (if (<= t_0 2.0) (/ x (- x -1.0)) t_1))))
double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = t_1;
}
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 = (((x / y) - (-1.0d0)) * x) / (x - (-1.0d0))
t_1 = (x - 1.0d0) / y
if (t_0 <= (-1000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x / (x - (-1.0d0))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (((x / y) - -1.0) * x) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -1000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (((x / y) - -1.0) * x) / (x - -1.0) t_1 = (x - 1.0) / y tmp = 0 if t_0 <= -1000.0: tmp = t_1 elif t_0 <= 2.0: tmp = x / (x - -1.0) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) t_1 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (((x / y) - -1.0) * x) / (x - -1.0); t_1 = (x - 1.0) / y; tmp = 0.0; if (t_0 <= -1000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x / (x - -1.0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -1000.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1}\\
t_1 := \frac{x - 1}{y}\\
\mathbf{if}\;t\_0 \leq -1000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
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.f6487.0
Applied rewrites87.0%
Taylor expanded in x around inf
Applied rewrites81.8%
Taylor expanded in x around inf
Applied rewrites81.1%
if -1e3 < (/.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
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6489.0
Applied rewrites89.0%
Final simplification85.5%
(FPCore (x y) :precision binary64 (if (<= (/ (* (- (/ x y) -1.0) x) (- x -1.0)) -2e+44) (* (- x) x) (* 1.0 x)))
double code(double x, double y) {
double tmp;
if (((((x / y) - -1.0) * x) / (x - -1.0)) <= -2e+44) {
tmp = -x * x;
} else {
tmp = 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 / y) - (-1.0d0)) * x) / (x - (-1.0d0))) <= (-2d+44)) then
tmp = -x * x
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((((x / y) - -1.0) * x) / (x - -1.0)) <= -2e+44) {
tmp = -x * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((((x / y) - -1.0) * x) / (x - -1.0)) <= -2e+44: tmp = -x * x else: tmp = 1.0 * x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(Float64(x / y) - -1.0) * x) / Float64(x - -1.0)) <= -2e+44) tmp = Float64(Float64(-x) * x); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((((x / y) - -1.0) * x) / (x - -1.0)) <= -2e+44) tmp = -x * x; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], -2e+44], N[((-x) * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(\frac{x}{y} - -1\right) \cdot x}{x - -1} \leq -2 \cdot 10^{+44}:\\
\;\;\;\;\left(-x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2.0000000000000002e44Initial program 76.3%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f641.1
Applied rewrites1.1%
Taylor expanded in x around 0
Applied rewrites35.6%
Taylor expanded in x around inf
Applied rewrites35.7%
if -2.0000000000000002e44 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 94.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites59.0%
Taylor expanded in y around inf
Applied rewrites50.0%
Taylor expanded in x around 0
Applied rewrites47.5%
Final simplification45.5%
(FPCore (x y) :precision binary64 (/ (- -1.0 (/ x y)) (/ (- -1.0 x) x)))
double code(double x, double y) {
return (-1.0 - (x / y)) / ((-1.0 - x) / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((-1.0d0) - (x / y)) / (((-1.0d0) - x) / x)
end function
public static double code(double x, double y) {
return (-1.0 - (x / y)) / ((-1.0 - x) / x);
}
def code(x, y): return (-1.0 - (x / y)) / ((-1.0 - x) / x)
function code(x, y) return Float64(Float64(-1.0 - Float64(x / y)) / Float64(Float64(-1.0 - x) / x)) end
function tmp = code(x, y) tmp = (-1.0 - (x / y)) / ((-1.0 - x) / x); end
code[x_, y_] := N[(N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 - x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1 - \frac{x}{y}}{\frac{-1 - x}{x}}
\end{array}
Initial program 91.2%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/r*N/A
clear-num-revN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6499.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ (/ (- x 1.0) y) 1.0))) (if (<= x -1.0) t_0 (if (<= x 1.0) (fma (- (/ x y) x) x x) t_0))))
double code(double x, double y) {
double t_0 = ((x - 1.0) / y) + 1.0;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = fma(((x / y) - x), x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(x - 1.0) / y) + 1.0) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = fma(Float64(Float64(x / y) - x), x, x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - 1}{y} + 1\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 81.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/r*N/A
clear-num-revN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
unpow2N/A
distribute-lft-outN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6468.4
Applied rewrites68.4%
Taylor expanded in x around inf
associate--l+N/A
distribute-lft-inN/A
rgt-mult-inverseN/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
associate-*r/N/A
*-rgt-identityN/A
sub-negN/A
div-subN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6498.4
Applied rewrites98.4%
if -1 < x < 1Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
neg-mul-1N/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Final simplification98.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ (/ (- x 1.0) y) 1.0))) (if (<= x -5.4e+17) t_0 (if (<= x 5200000000000.0) (/ x (- x -1.0)) t_0))))
double code(double x, double y) {
double t_0 = ((x - 1.0) / y) + 1.0;
double tmp;
if (x <= -5.4e+17) {
tmp = t_0;
} else if (x <= 5200000000000.0) {
tmp = x / (x - -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 = ((x - 1.0d0) / y) + 1.0d0
if (x <= (-5.4d+17)) then
tmp = t_0
else if (x <= 5200000000000.0d0) then
tmp = x / (x - (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x - 1.0) / y) + 1.0;
double tmp;
if (x <= -5.4e+17) {
tmp = t_0;
} else if (x <= 5200000000000.0) {
tmp = x / (x - -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = ((x - 1.0) / y) + 1.0 tmp = 0 if x <= -5.4e+17: tmp = t_0 elif x <= 5200000000000.0: tmp = x / (x - -1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - 1.0) / y) + 1.0) tmp = 0.0 if (x <= -5.4e+17) tmp = t_0; elseif (x <= 5200000000000.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - 1.0) / y) + 1.0; tmp = 0.0; if (x <= -5.4e+17) tmp = t_0; elseif (x <= 5200000000000.0) tmp = x / (x - -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -5.4e+17], t$95$0, If[LessEqual[x, 5200000000000.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - 1}{y} + 1\\
\mathbf{if}\;x \leq -5.4 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5200000000000:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.4e17 or 5.2e12 < x Initial program 81.2%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/r*N/A
clear-num-revN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
unpow2N/A
distribute-lft-outN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6467.1
Applied rewrites67.1%
Taylor expanded in x around inf
associate--l+N/A
distribute-lft-inN/A
rgt-mult-inverseN/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
associate-*r/N/A
*-rgt-identityN/A
sub-negN/A
div-subN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -5.4e17 < x < 5.2e12Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6476.2
Applied rewrites76.2%
Final simplification87.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (- x 1.0) y))) (if (<= x -1.0) t_0 (if (<= x 1.0) (fma (- x) x x) t_0))))
double code(double x, double y) {
double t_0 = (x - 1.0) / y;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = fma(-x, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = fma(Float64(-x), x, x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[((-x) * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - 1}{y}\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(-x, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 81.9%
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.f6465.0
Applied rewrites65.0%
Taylor expanded in x around inf
Applied rewrites74.0%
Taylor expanded in x around inf
Applied rewrites74.1%
if -1 < x < 1Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6475.4
Applied rewrites75.4%
Taylor expanded in x around 0
Applied rewrites74.7%
(FPCore (x y) :precision binary64 (fma (- x) x x))
double code(double x, double y) {
return fma(-x, x, x);
}
function code(x, y) return fma(Float64(-x), x, x) end
code[x_, y_] := N[((-x) * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-x, x, x\right)
\end{array}
Initial program 91.2%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6451.4
Applied rewrites51.4%
Taylor expanded in x around 0
Applied rewrites44.8%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 91.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites51.7%
Taylor expanded in y around inf
Applied rewrites44.4%
Taylor expanded in x around 0
Applied rewrites39.9%
(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 2024298
(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)))