
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return 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 * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return 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 * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return 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 * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
Initial program 99.9%
(FPCore (x y)
:precision binary64
(if (or (<= y -0.42)
(not
(or (<= y -1.45e-149)
(and (not (<= y -3.2e-169)) (<= y 1.42e-121)))))
(* x (* x (- y)))
x))
double code(double x, double y) {
double tmp;
if ((y <= -0.42) || !((y <= -1.45e-149) || (!(y <= -3.2e-169) && (y <= 1.42e-121)))) {
tmp = x * (x * -y);
} 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 ((y <= (-0.42d0)) .or. (.not. (y <= (-1.45d-149)) .or. (.not. (y <= (-3.2d-169))) .and. (y <= 1.42d-121))) then
tmp = x * (x * -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.42) || !((y <= -1.45e-149) || (!(y <= -3.2e-169) && (y <= 1.42e-121)))) {
tmp = x * (x * -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.42) or not ((y <= -1.45e-149) or (not (y <= -3.2e-169) and (y <= 1.42e-121))): tmp = x * (x * -y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.42) || !((y <= -1.45e-149) || (!(y <= -3.2e-169) && (y <= 1.42e-121)))) tmp = Float64(x * Float64(x * Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.42) || ~(((y <= -1.45e-149) || (~((y <= -3.2e-169)) && (y <= 1.42e-121))))) tmp = x * (x * -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.42], N[Not[Or[LessEqual[y, -1.45e-149], And[N[Not[LessEqual[y, -3.2e-169]], $MachinePrecision], LessEqual[y, 1.42e-121]]]], $MachinePrecision]], N[(x * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.42 \lor \neg \left(y \leq -1.45 \cdot 10^{-149} \lor \neg \left(y \leq -3.2 \cdot 10^{-169}\right) \land y \leq 1.42 \cdot 10^{-121}\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.419999999999999984 or -1.45e-149 < y < -3.19999999999999995e-169 or 1.41999999999999991e-121 < y Initial program 99.9%
flip--62.9%
associate-*r/60.0%
metadata-eval60.0%
pow260.0%
+-commutative60.0%
fma-define60.0%
Applied egg-rr60.0%
*-commutative60.0%
associate-/l*62.8%
Simplified62.8%
unpow-prod-down42.8%
unpow242.8%
associate-*l*44.5%
Applied egg-rr44.5%
cancel-sign-sub-inv44.5%
unpow244.5%
associate-*l*58.6%
cancel-sign-sub-inv58.6%
*-commutative58.6%
associate-*r/55.8%
clear-num55.7%
associate-*l*59.9%
*-commutative59.9%
unpow259.9%
*-commutative59.9%
Applied egg-rr59.9%
Taylor expanded in x around inf 69.1%
*-commutative69.1%
associate-/r*69.1%
Simplified69.1%
associate-/r/69.1%
clear-num69.1%
unpow269.1%
associate-*r*76.4%
clear-num76.4%
frac-2neg76.4%
metadata-eval76.4%
remove-double-div76.4%
distribute-lft-neg-in76.4%
*-commutative76.4%
distribute-rgt-neg-in76.4%
Applied egg-rr76.4%
if -0.419999999999999984 < y < -1.45e-149 or -3.19999999999999995e-169 < y < 1.41999999999999991e-121Initial program 100.0%
Taylor expanded in x around 0 79.9%
Final simplification77.7%
(FPCore (x y)
:precision binary64
(if (or (<= x -1.5e-14)
(not (or (<= x 2.1e-128) (and (not (<= x 118.0)) (<= x 2.75e+19)))))
(* y (* x (- x)))
x))
double code(double x, double y) {
double tmp;
if ((x <= -1.5e-14) || !((x <= 2.1e-128) || (!(x <= 118.0) && (x <= 2.75e+19)))) {
tmp = y * (x * -x);
} 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.5d-14)) .or. (.not. (x <= 2.1d-128) .or. (.not. (x <= 118.0d0)) .and. (x <= 2.75d+19))) then
tmp = y * (x * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.5e-14) || !((x <= 2.1e-128) || (!(x <= 118.0) && (x <= 2.75e+19)))) {
tmp = y * (x * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.5e-14) or not ((x <= 2.1e-128) or (not (x <= 118.0) and (x <= 2.75e+19))): tmp = y * (x * -x) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.5e-14) || !((x <= 2.1e-128) || (!(x <= 118.0) && (x <= 2.75e+19)))) tmp = Float64(y * Float64(x * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.5e-14) || ~(((x <= 2.1e-128) || (~((x <= 118.0)) && (x <= 2.75e+19))))) tmp = y * (x * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.5e-14], N[Not[Or[LessEqual[x, 2.1e-128], And[N[Not[LessEqual[x, 118.0]], $MachinePrecision], LessEqual[x, 2.75e+19]]]], $MachinePrecision]], N[(y * N[(x * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-14} \lor \neg \left(x \leq 2.1 \cdot 10^{-128} \lor \neg \left(x \leq 118\right) \land x \leq 2.75 \cdot 10^{+19}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.4999999999999999e-14 or 2.1000000000000001e-128 < x < 118 or 2.75e19 < x Initial program 99.9%
flip--60.9%
associate-*r/57.2%
metadata-eval57.2%
pow257.2%
+-commutative57.2%
fma-define57.2%
Applied egg-rr57.2%
*-commutative57.2%
associate-/l*60.9%
Simplified60.9%
unpow-prod-down45.0%
unpow245.0%
associate-*l*53.6%
Applied egg-rr53.6%
cancel-sign-sub-inv53.6%
unpow253.6%
associate-*l*60.2%
cancel-sign-sub-inv60.2%
*-commutative60.2%
associate-*r/56.6%
clear-num56.5%
associate-*l*57.1%
*-commutative57.1%
unpow257.1%
*-commutative57.1%
Applied egg-rr57.1%
Taylor expanded in x around inf 73.7%
*-commutative73.7%
associate-/r*73.7%
Simplified73.7%
*-un-lft-identity73.7%
unpow273.7%
times-frac78.4%
Applied egg-rr78.4%
frac-times73.7%
*-un-lft-identity73.7%
clear-num73.8%
associate-*r/78.5%
associate-/r/78.5%
associate-*r*73.8%
div-inv73.8%
metadata-eval73.8%
Applied egg-rr73.8%
*-commutative73.8%
associate-*r*78.5%
metadata-eval78.5%
div-inv78.5%
associate-/r/78.5%
clear-num78.4%
div-inv78.4%
associate-/r*78.5%
associate-/r/78.5%
metadata-eval78.5%
associate-*l*78.5%
*-commutative78.5%
add-sqr-sqrt38.5%
sqrt-unprod35.7%
*-commutative35.7%
*-commutative35.7%
swap-sqr35.7%
metadata-eval35.7%
*-un-lft-identity35.7%
sqrt-unprod0.7%
add-sqr-sqrt1.1%
add-sqr-sqrt0.7%
sqrt-unprod35.7%
*-un-lft-identity35.7%
metadata-eval35.7%
swap-sqr35.7%
*-commutative35.7%
*-commutative35.7%
Applied egg-rr78.5%
div-inv78.5%
*-commutative78.5%
clear-num78.5%
associate-*l*73.8%
clear-num73.8%
frac-2neg73.8%
metadata-eval73.8%
remove-double-div73.8%
Applied egg-rr73.8%
if -1.4999999999999999e-14 < x < 2.1000000000000001e-128 or 118 < x < 2.75e19Initial program 99.9%
Taylor expanded in x around 0 77.7%
Final simplification75.4%
(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 99.9%
Taylor expanded in x around 0 45.9%
herbie shell --seed 2024107
(FPCore (x y)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
:precision binary64
(* x (- 1.0 (* x y))))