
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.0)
t_0
(if (<= y 1.9e-36)
x
(if (<= y 3e+75)
y
(if (or (<= y 2.5e+135) (not (<= y 6.8e+255))) t_0 y))))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.9e-36) {
tmp = x;
} else if (y <= 3e+75) {
tmp = y;
} else if ((y <= 2.5e+135) || !(y <= 6.8e+255)) {
tmp = t_0;
} else {
tmp = y;
}
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 = y * -x
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.9d-36) then
tmp = x
else if (y <= 3d+75) then
tmp = y
else if ((y <= 2.5d+135) .or. (.not. (y <= 6.8d+255))) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.9e-36) {
tmp = x;
} else if (y <= 3e+75) {
tmp = y;
} else if ((y <= 2.5e+135) || !(y <= 6.8e+255)) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.9e-36: tmp = x elif y <= 3e+75: tmp = y elif (y <= 2.5e+135) or not (y <= 6.8e+255): tmp = t_0 else: tmp = y return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.9e-36) tmp = x; elseif (y <= 3e+75) tmp = y; elseif ((y <= 2.5e+135) || !(y <= 6.8e+255)) tmp = t_0; else tmp = y; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 1.9e-36) tmp = x; elseif (y <= 3e+75) tmp = y; elseif ((y <= 2.5e+135) || ~((y <= 6.8e+255))) tmp = t_0; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.9e-36], x, If[LessEqual[y, 3e+75], y, If[Or[LessEqual[y, 2.5e+135], N[Not[LessEqual[y, 6.8e+255]], $MachinePrecision]], t$95$0, y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+75}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+135} \lor \neg \left(y \leq 6.8 \cdot 10^{+255}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3e75 < y < 2.50000000000000015e135 or 6.7999999999999997e255 < y Initial program 100.0%
Taylor expanded in x around inf 50.7%
Taylor expanded in y around inf 50.7%
mul-1-neg50.7%
distribute-rgt-neg-out50.7%
Simplified50.7%
if -1 < y < 1.89999999999999985e-36Initial program 100.0%
Taylor expanded in y around 0 81.2%
if 1.89999999999999985e-36 < y < 3e75 or 2.50000000000000015e135 < y < 6.7999999999999997e255Initial program 100.0%
Taylor expanded in x around 0 57.1%
Final simplification65.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -2.45e-18)
t_0
(if (<= x -7.2e-46)
y
(if (<= x -4.5e-85) t_0 (if (<= x 1.0) y (* y (- x))))))))
double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -2.45e-18) {
tmp = t_0;
} else if (x <= -7.2e-46) {
tmp = y;
} else if (x <= -4.5e-85) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -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 * (1.0d0 - y)
if (x <= (-2.45d-18)) then
tmp = t_0
else if (x <= (-7.2d-46)) then
tmp = y
else if (x <= (-4.5d-85)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -2.45e-18) {
tmp = t_0;
} else if (x <= -7.2e-46) {
tmp = y;
} else if (x <= -4.5e-85) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - y) tmp = 0 if x <= -2.45e-18: tmp = t_0 elif x <= -7.2e-46: tmp = y elif x <= -4.5e-85: tmp = t_0 elif x <= 1.0: tmp = y else: tmp = y * -x return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -2.45e-18) tmp = t_0; elseif (x <= -7.2e-46) tmp = y; elseif (x <= -4.5e-85) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -2.45e-18) tmp = t_0; elseif (x <= -7.2e-46) tmp = y; elseif (x <= -4.5e-85) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.45e-18], t$95$0, If[LessEqual[x, -7.2e-46], y, If[LessEqual[x, -4.5e-85], t$95$0, If[LessEqual[x, 1.0], y, N[(y * (-x)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -2.45 \cdot 10^{-18}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{-46}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -4.5 \cdot 10^{-85}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -2.4500000000000001e-18 or -7.2e-46 < x < -4.50000000000000004e-85Initial program 100.0%
Taylor expanded in x around inf 92.5%
if -2.4500000000000001e-18 < x < -7.2e-46 or -4.50000000000000004e-85 < x < 1Initial program 100.0%
Taylor expanded in x around 0 80.1%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 97.7%
Taylor expanded in y around inf 61.2%
mul-1-neg61.2%
distribute-rgt-neg-out61.2%
Simplified61.2%
Final simplification79.7%
(FPCore (x y)
:precision binary64
(if (<= x -5.2e-23)
(- x (* x y))
(if (<= x -2.25e-45)
y
(if (<= x -9.6e-83) (* x (- 1.0 y)) (if (<= x 1.0) y (* y (- x)))))))
double code(double x, double y) {
double tmp;
if (x <= -5.2e-23) {
tmp = x - (x * y);
} else if (x <= -2.25e-45) {
tmp = y;
} else if (x <= -9.6e-83) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} 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 (x <= (-5.2d-23)) then
tmp = x - (x * y)
else if (x <= (-2.25d-45)) then
tmp = y
else if (x <= (-9.6d-83)) then
tmp = x * (1.0d0 - y)
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.2e-23) {
tmp = x - (x * y);
} else if (x <= -2.25e-45) {
tmp = y;
} else if (x <= -9.6e-83) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.2e-23: tmp = x - (x * y) elif x <= -2.25e-45: tmp = y elif x <= -9.6e-83: tmp = x * (1.0 - y) elif x <= 1.0: tmp = y else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.2e-23) tmp = Float64(x - Float64(x * y)); elseif (x <= -2.25e-45) tmp = y; elseif (x <= -9.6e-83) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.2e-23) tmp = x - (x * y); elseif (x <= -2.25e-45) tmp = y; elseif (x <= -9.6e-83) tmp = x * (1.0 - y); elseif (x <= 1.0) tmp = y; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.2e-23], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.25e-45], y, If[LessEqual[x, -9.6e-83], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * (-x)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-23}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq -2.25 \cdot 10^{-45}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -9.6 \cdot 10^{-83}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -5.2e-23Initial program 100.0%
Taylor expanded in x around inf 95.5%
*-commutative95.5%
distribute-rgt-out--95.5%
*-lft-identity95.5%
Simplified95.5%
if -5.2e-23 < x < -2.2499999999999999e-45 or -9.6000000000000003e-83 < x < 1Initial program 100.0%
Taylor expanded in x around 0 80.4%
if -2.2499999999999999e-45 < x < -9.6000000000000003e-83Initial program 100.0%
Taylor expanded in x around inf 58.6%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 97.7%
Taylor expanded in y around inf 61.2%
mul-1-neg61.2%
distribute-rgt-neg-out61.2%
Simplified61.2%
Final simplification79.6%
(FPCore (x y) :precision binary64 (if (<= x -4e-17) (- x (* x y)) (if (<= x -5.3e-45) y (if (<= x -1.35e-80) (* x (- 1.0 y)) (- y (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -4e-17) {
tmp = x - (x * y);
} else if (x <= -5.3e-45) {
tmp = y;
} else if (x <= -1.35e-80) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4d-17)) then
tmp = x - (x * y)
else if (x <= (-5.3d-45)) then
tmp = y
else if (x <= (-1.35d-80)) then
tmp = x * (1.0d0 - y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4e-17) {
tmp = x - (x * y);
} else if (x <= -5.3e-45) {
tmp = y;
} else if (x <= -1.35e-80) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e-17: tmp = x - (x * y) elif x <= -5.3e-45: tmp = y elif x <= -1.35e-80: tmp = x * (1.0 - y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (x <= -4e-17) tmp = Float64(x - Float64(x * y)); elseif (x <= -5.3e-45) tmp = y; elseif (x <= -1.35e-80) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4e-17) tmp = x - (x * y); elseif (x <= -5.3e-45) tmp = y; elseif (x <= -1.35e-80) tmp = x * (1.0 - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e-17], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -5.3e-45], y, If[LessEqual[x, -1.35e-80], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-17}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq -5.3 \cdot 10^{-45}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.35 \cdot 10^{-80}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if x < -4.00000000000000029e-17Initial program 100.0%
Taylor expanded in x around inf 96.6%
*-commutative96.6%
distribute-rgt-out--96.6%
*-lft-identity96.6%
Simplified96.6%
if -4.00000000000000029e-17 < x < -5.2999999999999997e-45Initial program 100.0%
Taylor expanded in x around 0 85.4%
if -5.2999999999999997e-45 < x < -1.3500000000000001e-80Initial program 100.0%
Taylor expanded in x around inf 65.1%
if -1.3500000000000001e-80 < x Initial program 100.0%
Taylor expanded in y around inf 74.5%
distribute-lft-out--74.5%
*-rgt-identity74.5%
Simplified74.5%
Final simplification80.9%
(FPCore (x y) :precision binary64 (if (<= y 4.5e-35) x y))
double code(double x, double y) {
double tmp;
if (y <= 4.5e-35) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4.5d-35) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.5e-35) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.5e-35: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 4.5e-35) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.5e-35) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.5e-35], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.5000000000000001e-35Initial program 100.0%
Taylor expanded in y around 0 51.5%
if 4.5000000000000001e-35 < y Initial program 100.0%
Taylor expanded in x around 0 48.1%
Final simplification50.5%
(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%
Taylor expanded in y around 0 37.1%
Final simplification37.1%
herbie shell --seed 2023195
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))