
(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) y))
double code(double x, double y) {
return fma(y, x, 1.0) - y;
}
function code(x, y) return Float64(fma(y, x, 1.0) - y) end
code[x_, y_] := N[(N[(y * x + 1.0), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, 1\right) - y
\end{array}
Initial program 78.3%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= x -2.45e+35) (* x y) (if (<= x 0.19) (- 1.0 y) (fma y x (- y)))))
double code(double x, double y) {
double tmp;
if (x <= -2.45e+35) {
tmp = x * y;
} else if (x <= 0.19) {
tmp = 1.0 - y;
} else {
tmp = fma(y, x, -y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -2.45e+35) tmp = Float64(x * y); elseif (x <= 0.19) tmp = Float64(1.0 - y); else tmp = fma(y, x, Float64(-y)); end return tmp end
code[x_, y_] := If[LessEqual[x, -2.45e+35], N[(x * y), $MachinePrecision], If[LessEqual[x, 0.19], N[(1.0 - y), $MachinePrecision], N[(y * x + (-y)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+35}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 0.19:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -y\right)\\
\end{array}
\end{array}
if x < -2.45000000000000013e35Initial program 54.5%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
lower-*.f6475.7
Applied rewrites75.7%
if -2.45000000000000013e35 < x < 0.19Initial program 97.4%
Taylor expanded in x around 0
lower--.f6497.9
Applied rewrites97.9%
if 0.19 < x Initial program 50.5%
Taylor expanded in y around inf
associate-*r*N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
lower--.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
remove-double-negN/A
lower-*.f6479.5
Applied rewrites79.5%
Applied rewrites79.7%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= x -2.45e+35) (* x y) (if (<= x 1.1e+29) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -2.45e+35) {
tmp = x * y;
} else if (x <= 1.1e+29) {
tmp = 1.0 - y;
} 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 (x <= (-2.45d+35)) then
tmp = x * y
else if (x <= 1.1d+29) then
tmp = 1.0d0 - y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.45e+35) {
tmp = x * y;
} else if (x <= 1.1e+29) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.45e+35: tmp = x * y elif x <= 1.1e+29: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.45e+35) tmp = Float64(x * y); elseif (x <= 1.1e+29) tmp = Float64(1.0 - y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.45e+35) tmp = x * y; elseif (x <= 1.1e+29) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.45e+35], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.1e+29], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+35}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+29}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.45000000000000013e35 or 1.1000000000000001e29 < x Initial program 51.3%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
lower-*.f6479.0
Applied rewrites79.0%
if -2.45000000000000013e35 < x < 1.1000000000000001e29Initial program 96.8%
Taylor expanded in x around 0
lower--.f6496.6
Applied rewrites96.6%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.0) {
tmp = 1.0;
} 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 <= (-1.0d0)) then
tmp = -y
else if (y <= 1.0d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
associate-*r*N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
lower--.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
remove-double-negN/A
lower-*.f6498.6
Applied rewrites98.6%
Taylor expanded in x around 0
Applied rewrites55.7%
if -1 < y < 1Initial program 57.0%
Taylor expanded in y around 0
Applied rewrites74.1%
(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 78.3%
Taylor expanded in x around 0
lower--.f6466.2
Applied rewrites66.2%
(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 78.3%
Taylor expanded in y around 0
Applied rewrites38.7%
(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 2024221
(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))))