
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
(FPCore (x y) :precision binary64 (fma (- y 1.0) x (fma -0.5 y 0.918938533204673)))
double code(double x, double y) {
return fma((y - 1.0), x, fma(-0.5, y, 0.918938533204673));
}
function code(x, y) return fma(Float64(y - 1.0), x, fma(-0.5, y, 0.918938533204673)) end
code[x_, y_] := N[(N[(y - 1.0), $MachinePrecision] * x + N[(-0.5 * y + 0.918938533204673), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - 1, x, \mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
neg-sub0N/A
associate-+l-N/A
neg-sub0N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2e+15)
(* (- x 0.5) y)
(if (<= y 31500000.0)
(fma -0.5 y (- 0.918938533204673 x))
(fma y x (* -0.5 y)))))
double code(double x, double y) {
double tmp;
if (y <= -2e+15) {
tmp = (x - 0.5) * y;
} else if (y <= 31500000.0) {
tmp = fma(-0.5, y, (0.918938533204673 - x));
} else {
tmp = fma(y, x, (-0.5 * y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2e+15) tmp = Float64(Float64(x - 0.5) * y); elseif (y <= 31500000.0) tmp = fma(-0.5, y, Float64(0.918938533204673 - x)); else tmp = fma(y, x, Float64(-0.5 * y)); end return tmp end
code[x_, y_] := If[LessEqual[y, -2e+15], N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 31500000.0], N[(-0.5 * y + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+15}:\\
\;\;\;\;\left(x - 0.5\right) \cdot y\\
\mathbf{elif}\;y \leq 31500000:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot y\right)\\
\end{array}
\end{array}
if y < -2e15Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
if -2e15 < y < 3.15e7Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6497.0
Applied rewrites97.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
if 3.15e7 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6498.9
Applied rewrites98.9%
Applied rewrites98.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (- x 0.5) y)))
(if (<= y -2e+15)
t_0
(if (<= y 31500000.0) (fma -0.5 y (- 0.918938533204673 x)) t_0))))
double code(double x, double y) {
double t_0 = (x - 0.5) * y;
double tmp;
if (y <= -2e+15) {
tmp = t_0;
} else if (y <= 31500000.0) {
tmp = fma(-0.5, y, (0.918938533204673 - x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x - 0.5) * y) tmp = 0.0 if (y <= -2e+15) tmp = t_0; elseif (y <= 31500000.0) tmp = fma(-0.5, y, Float64(0.918938533204673 - x)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2e+15], t$95$0, If[LessEqual[y, 31500000.0], N[(-0.5 * y + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 0.5\right) \cdot y\\
\mathbf{if}\;y \leq -2 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 31500000:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673 - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2e15 or 3.15e7 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6499.5
Applied rewrites99.5%
if -2e15 < y < 3.15e7Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6497.0
Applied rewrites97.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- x 0.5) y))) (if (<= y -1.42) t_0 (if (<= y 1.3) (- 0.918938533204673 x) t_0))))
double code(double x, double y) {
double t_0 = (x - 0.5) * y;
double tmp;
if (y <= -1.42) {
tmp = t_0;
} else if (y <= 1.3) {
tmp = 0.918938533204673 - x;
} 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 - 0.5d0) * y
if (y <= (-1.42d0)) then
tmp = t_0
else if (y <= 1.3d0) then
tmp = 0.918938533204673d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - 0.5) * y;
double tmp;
if (y <= -1.42) {
tmp = t_0;
} else if (y <= 1.3) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x - 0.5) * y tmp = 0 if y <= -1.42: tmp = t_0 elif y <= 1.3: tmp = 0.918938533204673 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x - 0.5) * y) tmp = 0.0 if (y <= -1.42) tmp = t_0; elseif (y <= 1.3) tmp = Float64(0.918938533204673 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - 0.5) * y; tmp = 0.0; if (y <= -1.42) tmp = t_0; elseif (y <= 1.3) tmp = 0.918938533204673 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.42], t$95$0, If[LessEqual[y, 1.3], N[(0.918938533204673 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 0.5\right) \cdot y\\
\mathbf{if}\;y \leq -1.42:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.4199999999999999 or 1.30000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6498.6
Applied rewrites98.6%
if -1.4199999999999999 < y < 1.30000000000000004Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6499.1
Applied rewrites99.1%
(FPCore (x y) :precision binary64 (if (<= y -2e+15) (* x y) (if (<= y 1.3) (- 0.918938533204673 x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -2e+15) {
tmp = x * y;
} else if (y <= 1.3) {
tmp = 0.918938533204673 - x;
} 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 <= (-2d+15)) then
tmp = x * y
else if (y <= 1.3d0) then
tmp = 0.918938533204673d0 - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e+15) {
tmp = x * y;
} else if (y <= 1.3) {
tmp = 0.918938533204673 - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e+15: tmp = x * y elif y <= 1.3: tmp = 0.918938533204673 - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -2e+15) tmp = Float64(x * y); elseif (y <= 1.3) tmp = Float64(0.918938533204673 - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e+15) tmp = x * y; elseif (y <= 1.3) tmp = 0.918938533204673 - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e+15], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.3], N[(0.918938533204673 - x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.3:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2e15 or 1.30000000000000004 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6459.0
Applied rewrites59.0%
Taylor expanded in y around inf
Applied rewrites58.5%
if -2e15 < y < 1.30000000000000004Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6497.7
Applied rewrites97.7%
Final simplification78.6%
(FPCore (x y) :precision binary64 (if (<= x -1.18e-5) (- x) (if (<= x 0.9) 0.918938533204673 (- x))))
double code(double x, double y) {
double tmp;
if (x <= -1.18e-5) {
tmp = -x;
} else if (x <= 0.9) {
tmp = 0.918938533204673;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.18d-5)) then
tmp = -x
else if (x <= 0.9d0) then
tmp = 0.918938533204673d0
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.18e-5) {
tmp = -x;
} else if (x <= 0.9) {
tmp = 0.918938533204673;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.18e-5: tmp = -x elif x <= 0.9: tmp = 0.918938533204673 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.18e-5) tmp = Float64(-x); elseif (x <= 0.9) tmp = 0.918938533204673; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.18e-5) tmp = -x; elseif (x <= 0.9) tmp = 0.918938533204673; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.18e-5], (-x), If[LessEqual[x, 0.9], 0.918938533204673, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.18 \cdot 10^{-5}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 0.9:\\
\;\;\;\;0.918938533204673\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -1.18000000000000005e-5 or 0.900000000000000022 < x Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6447.0
Applied rewrites47.0%
Taylor expanded in x around inf
Applied rewrites46.4%
if -1.18000000000000005e-5 < x < 0.900000000000000022Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6456.9
Applied rewrites56.9%
Taylor expanded in x around 0
Applied rewrites55.9%
(FPCore (x y) :precision binary64 (- 0.918938533204673 (fma (- 0.5 x) y x)))
double code(double x, double y) {
return 0.918938533204673 - fma((0.5 - x), y, x);
}
function code(x, y) return Float64(0.918938533204673 - fma(Float64(0.5 - x), y, x)) end
code[x_, y_] := N[(0.918938533204673 - N[(N[(0.5 - x), $MachinePrecision] * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - \mathsf{fma}\left(0.5 - x, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
*-commutativeN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
sub0-negN/A
associate-+l-N/A
neg-sub0N/A
mul-1-negN/A
+-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
associate-+r+N/A
lower--.f64N/A
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (- 0.918938533204673 x))
double code(double x, double y) {
return 0.918938533204673 - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0 - x
end function
public static double code(double x, double y) {
return 0.918938533204673 - x;
}
def code(x, y): return 0.918938533204673 - x
function code(x, y) return Float64(0.918938533204673 - x) end
function tmp = code(x, y) tmp = 0.918938533204673 - x; end
code[x_, y_] := N[(0.918938533204673 - x), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6451.5
Applied rewrites51.5%
(FPCore (x y) :precision binary64 0.918938533204673)
double code(double x, double y) {
return 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0
end function
public static double code(double x, double y) {
return 0.918938533204673;
}
def code(x, y): return 0.918938533204673
function code(x, y) return 0.918938533204673 end
function tmp = code(x, y) tmp = 0.918938533204673; end
code[x_, y_] := 0.918938533204673
\begin{array}{l}
\\
0.918938533204673
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6451.5
Applied rewrites51.5%
Taylor expanded in x around 0
Applied rewrites27.1%
herbie shell --seed 2024270
(FPCore (x y)
:name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
:precision binary64
(+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))