
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma y (+ x -1.0) 1.0))
double code(double x, double y) {
return fma(y, (x + -1.0), 1.0);
}
function code(x, y) return fma(y, Float64(x + -1.0), 1.0) end
code[x_, y_] := N[(y * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + -1, 1\right)
\end{array}
Initial program 81.2%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
cancel-sign-sub-invN/A
associate--r+N/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
sub-negN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= x -76000.0) (fma y x 1.0) (if (<= x 9.2e-8) (- 1.0 y) (fma y x 1.0))))
double code(double x, double y) {
double tmp;
if (x <= -76000.0) {
tmp = fma(y, x, 1.0);
} else if (x <= 9.2e-8) {
tmp = 1.0 - y;
} else {
tmp = fma(y, x, 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -76000.0) tmp = fma(y, x, 1.0); elseif (x <= 9.2e-8) tmp = Float64(1.0 - y); else tmp = fma(y, x, 1.0); end return tmp end
code[x_, y_] := If[LessEqual[x, -76000.0], N[(y * x + 1.0), $MachinePrecision], If[LessEqual[x, 9.2e-8], N[(1.0 - y), $MachinePrecision], N[(y * x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -76000:\\
\;\;\;\;\mathsf{fma}\left(y, x, 1\right)\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-8}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, 1\right)\\
\end{array}
\end{array}
if x < -76000 or 9.2000000000000003e-8 < x Initial program 62.0%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
cancel-sign-sub-invN/A
associate--r+N/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
sub-negN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
Simplified100.0%
Taylor expanded in x around inf
Simplified99.2%
if -76000 < x < 9.2000000000000003e-8Initial program 100.0%
Taylor expanded in x around 0
--lowering--.f6499.8%
Simplified99.8%
(FPCore (x y) :precision binary64 (if (<= x -3.45e+21) (* y x) (if (<= x 1660000000000.0) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -3.45e+21) {
tmp = y * x;
} else if (x <= 1660000000000.0) {
tmp = 1.0 - 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 <= (-3.45d+21)) then
tmp = y * x
else if (x <= 1660000000000.0d0) then
tmp = 1.0d0 - y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.45e+21) {
tmp = y * x;
} else if (x <= 1660000000000.0) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.45e+21: tmp = y * x elif x <= 1660000000000.0: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -3.45e+21) tmp = Float64(y * x); elseif (x <= 1660000000000.0) tmp = Float64(1.0 - y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.45e+21) tmp = y * x; elseif (x <= 1660000000000.0) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.45e+21], N[(y * x), $MachinePrecision], If[LessEqual[x, 1660000000000.0], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.45 \cdot 10^{+21}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1660000000000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.45e21 or 1.66e12 < x Initial program 60.3%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-outN/A
+-rgt-identityN/A
*-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
accelerator-lowering-fma.f6483.1%
Simplified83.1%
+-rgt-identityN/A
*-lowering-*.f6483.1%
Applied egg-rr83.1%
if -3.45e21 < x < 1.66e12Initial program 99.3%
Taylor expanded in x around 0
--lowering--.f6498.5%
Simplified98.5%
(FPCore (x y) :precision binary64 (if (<= y -8600000.0) (- 0.0 y) (if (<= y 1.0) 1.0 (- 0.0 y))))
double code(double x, double y) {
double tmp;
if (y <= -8600000.0) {
tmp = 0.0 - y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = 0.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-8600000.0d0)) then
tmp = 0.0d0 - y
else if (y <= 1.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -8600000.0) {
tmp = 0.0 - y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = 0.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8600000.0: tmp = 0.0 - y elif y <= 1.0: tmp = 1.0 else: tmp = 0.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= -8600000.0) tmp = Float64(0.0 - y); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(0.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8600000.0) tmp = 0.0 - y; elseif (y <= 1.0) tmp = 1.0; else tmp = 0.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8600000.0], N[(0.0 - y), $MachinePrecision], If[LessEqual[y, 1.0], 1.0, N[(0.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8600000:\\
\;\;\;\;0 - y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0 - y\\
\end{array}
\end{array}
if y < -8.6e6 or 1 < y Initial program 100.0%
Taylor expanded in x around 0
--lowering--.f6448.7%
Simplified48.7%
Taylor expanded in y around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f6448.2%
Simplified48.2%
sub0-negN/A
neg-lowering-neg.f6448.2%
Applied egg-rr48.2%
if -8.6e6 < y < 1Initial program 61.7%
Taylor expanded in y around 0
Simplified73.7%
Final simplification60.7%
(FPCore (x y) :precision binary64 (- 1.0 y))
double code(double x, double y) {
return 1.0 - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - y
end function
public static double code(double x, double y) {
return 1.0 - y;
}
def code(x, y): return 1.0 - y
function code(x, y) return Float64(1.0 - y) end
function tmp = code(x, y) tmp = 1.0 - y; end
code[x_, y_] := N[(1.0 - y), $MachinePrecision]
\begin{array}{l}
\\
1 - y
\end{array}
Initial program 81.2%
Taylor expanded in x around 0
--lowering--.f6461.5%
Simplified61.5%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 81.2%
Taylor expanded in y around 0
Simplified37.6%
(FPCore (x y) :precision binary64 (- (* y x) (- y 1.0)))
double code(double x, double y) {
return (y * x) - (y - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * x) - (y - 1.0d0)
end function
public static double code(double x, double y) {
return (y * x) - (y - 1.0);
}
def code(x, y): return (y * x) - (y - 1.0)
function code(x, y) return Float64(Float64(y * x) - Float64(y - 1.0)) end
function tmp = code(x, y) tmp = (y * x) - (y - 1.0); end
code[x_, y_] := N[(N[(y * x), $MachinePrecision] - N[(y - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x - \left(y - 1\right)
\end{array}
herbie shell --seed 2024193
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (- (* y x) (- y 1)))
(+ x (* (- 1.0 x) (- 1.0 y))))