
(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 7 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 (- (+ (* y (+ x -0.5)) 0.918938533204673) x))
double code(double x, double y) {
return ((y * (x + -0.5)) + 0.918938533204673) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((y * (x + (-0.5d0))) + 0.918938533204673d0) - x
end function
public static double code(double x, double y) {
return ((y * (x + -0.5)) + 0.918938533204673) - x;
}
def code(x, y): return ((y * (x + -0.5)) + 0.918938533204673) - x
function code(x, y) return Float64(Float64(Float64(y * Float64(x + -0.5)) + 0.918938533204673) - x) end
function tmp = code(x, y) tmp = ((y * (x + -0.5)) + 0.918938533204673) - x; end
code[x_, y_] := N[(N[(N[(y * N[(x + -0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot \left(x + -0.5\right) + 0.918938533204673\right) - x
\end{array}
Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
associate-+l-100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out100.0%
fma-neg100.0%
+-commutative100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-undefine100.0%
associate-+r-100.0%
Applied egg-rr100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.1e+78)
(* y -0.5)
(if (<= y -1.35e+45)
(* y x)
(if (<= y -130.0)
(* y -0.5)
(if (<= y 1.85)
(- 0.918938533204673 x)
(if (<= y 2.15e+102) (* y -0.5) (* y x)))))))
double code(double x, double y) {
double tmp;
if (y <= -4.1e+78) {
tmp = y * -0.5;
} else if (y <= -1.35e+45) {
tmp = y * x;
} else if (y <= -130.0) {
tmp = y * -0.5;
} else if (y <= 1.85) {
tmp = 0.918938533204673 - x;
} else if (y <= 2.15e+102) {
tmp = y * -0.5;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-4.1d+78)) then
tmp = y * (-0.5d0)
else if (y <= (-1.35d+45)) then
tmp = y * x
else if (y <= (-130.0d0)) then
tmp = y * (-0.5d0)
else if (y <= 1.85d0) then
tmp = 0.918938533204673d0 - x
else if (y <= 2.15d+102) then
tmp = y * (-0.5d0)
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.1e+78) {
tmp = y * -0.5;
} else if (y <= -1.35e+45) {
tmp = y * x;
} else if (y <= -130.0) {
tmp = y * -0.5;
} else if (y <= 1.85) {
tmp = 0.918938533204673 - x;
} else if (y <= 2.15e+102) {
tmp = y * -0.5;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.1e+78: tmp = y * -0.5 elif y <= -1.35e+45: tmp = y * x elif y <= -130.0: tmp = y * -0.5 elif y <= 1.85: tmp = 0.918938533204673 - x elif y <= 2.15e+102: tmp = y * -0.5 else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -4.1e+78) tmp = Float64(y * -0.5); elseif (y <= -1.35e+45) tmp = Float64(y * x); elseif (y <= -130.0) tmp = Float64(y * -0.5); elseif (y <= 1.85) tmp = Float64(0.918938533204673 - x); elseif (y <= 2.15e+102) tmp = Float64(y * -0.5); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.1e+78) tmp = y * -0.5; elseif (y <= -1.35e+45) tmp = y * x; elseif (y <= -130.0) tmp = y * -0.5; elseif (y <= 1.85) tmp = 0.918938533204673 - x; elseif (y <= 2.15e+102) tmp = y * -0.5; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.1e+78], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, -1.35e+45], N[(y * x), $MachinePrecision], If[LessEqual[y, -130.0], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 1.85], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[y, 2.15e+102], N[(y * -0.5), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+78}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{+45}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -130:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;y \leq 1.85:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{+102}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.0999999999999997e78 or -1.34999999999999992e45 < y < -130 or 1.8500000000000001 < y < 2.15e102Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 95.0%
Taylor expanded in x around 0 67.6%
if -4.0999999999999997e78 < y < -1.34999999999999992e45 or 2.15e102 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 58.3%
if -130 < y < 1.8500000000000001Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
(FPCore (x y) :precision binary64 (if (<= x -7.6e+131) (* y x) (if (or (<= x -21.0) (not (<= x 0.5))) (- x) (* y -0.5))))
double code(double x, double y) {
double tmp;
if (x <= -7.6e+131) {
tmp = y * x;
} else if ((x <= -21.0) || !(x <= 0.5)) {
tmp = -x;
} else {
tmp = y * -0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.6d+131)) then
tmp = y * x
else if ((x <= (-21.0d0)) .or. (.not. (x <= 0.5d0))) then
tmp = -x
else
tmp = y * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.6e+131) {
tmp = y * x;
} else if ((x <= -21.0) || !(x <= 0.5)) {
tmp = -x;
} else {
tmp = y * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.6e+131: tmp = y * x elif (x <= -21.0) or not (x <= 0.5): tmp = -x else: tmp = y * -0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -7.6e+131) tmp = Float64(y * x); elseif ((x <= -21.0) || !(x <= 0.5)) tmp = Float64(-x); else tmp = Float64(y * -0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.6e+131) tmp = y * x; elseif ((x <= -21.0) || ~((x <= 0.5))) tmp = -x; else tmp = y * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.6e+131], N[(y * x), $MachinePrecision], If[Or[LessEqual[x, -21.0], N[Not[LessEqual[x, 0.5]], $MachinePrecision]], (-x), N[(y * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+131}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -21 \lor \neg \left(x \leq 0.5\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\
\end{array}
\end{array}
if x < -7.6000000000000007e131Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 62.8%
Taylor expanded in x around inf 62.8%
if -7.6000000000000007e131 < x < -21 or 0.5 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 62.8%
neg-mul-162.8%
sub-neg62.8%
Simplified62.8%
Taylor expanded in x around inf 59.8%
neg-mul-159.8%
Simplified59.8%
if -21 < x < 0.5Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 57.8%
Taylor expanded in x around 0 55.7%
Final simplification58.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.26) (not (<= y 1.2))) (* y (- x 0.5)) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.26) || !(y <= 1.2)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.26d0)) .or. (.not. (y <= 1.2d0))) then
tmp = y * (x - 0.5d0)
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.26) || !(y <= 1.2)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.26) or not (y <= 1.2): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.26) || !(y <= 1.2)) tmp = Float64(y * Float64(x - 0.5)); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.26) || ~((y <= 1.2))) tmp = y * (x - 0.5); else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.26], N[Not[LessEqual[y, 1.2]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \lor \neg \left(y \leq 1.2\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
if y < -1.26000000000000001 or 1.19999999999999996 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.2%
if -1.26000000000000001 < y < 1.19999999999999996Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.3%
neg-mul-199.3%
sub-neg99.3%
Simplified99.3%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (or (<= x -102.0) (not (<= x 0.52))) (- x) (* y -0.5)))
double code(double x, double y) {
double tmp;
if ((x <= -102.0) || !(x <= 0.52)) {
tmp = -x;
} else {
tmp = y * -0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-102.0d0)) .or. (.not. (x <= 0.52d0))) then
tmp = -x
else
tmp = y * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -102.0) || !(x <= 0.52)) {
tmp = -x;
} else {
tmp = y * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -102.0) or not (x <= 0.52): tmp = -x else: tmp = y * -0.5 return tmp
function code(x, y) tmp = 0.0 if ((x <= -102.0) || !(x <= 0.52)) tmp = Float64(-x); else tmp = Float64(y * -0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -102.0) || ~((x <= 0.52))) tmp = -x; else tmp = y * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -102.0], N[Not[LessEqual[x, 0.52]], $MachinePrecision]], (-x), N[(y * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -102 \lor \neg \left(x \leq 0.52\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\
\end{array}
\end{array}
if x < -102 or 0.52000000000000002 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 55.5%
neg-mul-155.5%
sub-neg55.5%
Simplified55.5%
Taylor expanded in x around inf 53.4%
neg-mul-153.4%
Simplified53.4%
if -102 < x < 0.52000000000000002Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 57.8%
Taylor expanded in x around 0 55.7%
Final simplification54.6%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 49.1%
neg-mul-149.1%
sub-neg49.1%
Simplified49.1%
Taylor expanded in x around inf 27.3%
neg-mul-127.3%
Simplified27.3%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 49.1%
neg-mul-149.1%
sub-neg49.1%
Simplified49.1%
Taylor expanded in x around inf 27.3%
neg-mul-127.3%
Simplified27.3%
neg-sub027.3%
sub-neg27.3%
add-sqr-sqrt14.0%
sqrt-unprod15.8%
sqr-neg15.8%
sqrt-unprod1.5%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024111
(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))