
(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 fma(y, x, Float64(1.0 - y)) end
code[x_, y_] := N[(y * x + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, 1 - y\right)
\end{array}
Initial program 78.8%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (or (<= (- 1.0 y) -2000000.0) (not (<= (- 1.0 y) 1.00000002))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -2000000.0) || !((1.0 - y) <= 1.00000002)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((1.0d0 - y) <= (-2000000.0d0)) .or. (.not. ((1.0d0 - y) <= 1.00000002d0))) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -2000000.0) || !((1.0 - y) <= 1.00000002)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - y) <= -2000000.0) or not ((1.0 - y) <= 1.00000002): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - y) <= -2000000.0) || !(Float64(1.0 - y) <= 1.00000002)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - y) <= -2000000.0) || ~(((1.0 - y) <= 1.00000002))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - y), $MachinePrecision], -2000000.0], N[Not[LessEqual[N[(1.0 - y), $MachinePrecision], 1.00000002]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -2000000 \lor \neg \left(1 - y \leq 1.00000002\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -2e6 or 1.0000000200000001 < (-.f64 #s(literal 1 binary64) y) Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6498.5
Applied rewrites98.5%
Taylor expanded in x around 0
Applied rewrites49.3%
if -2e6 < (-.f64 #s(literal 1 binary64) y) < 1.0000000200000001Initial program 61.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-*.f6426.2
Applied rewrites26.2%
Taylor expanded in y around 0
Applied rewrites76.7%
Final simplification64.2%
(FPCore (x y) :precision binary64 (if (<= x -4.4e+28) (* y x) (if (<= x 1.4e+38) (- 1.0 y) (* (- x 1.0) y))))
double code(double x, double y) {
double tmp;
if (x <= -4.4e+28) {
tmp = y * x;
} else if (x <= 1.4e+38) {
tmp = 1.0 - y;
} else {
tmp = (x - 1.0) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.4d+28)) then
tmp = y * x
else if (x <= 1.4d+38) then
tmp = 1.0d0 - y
else
tmp = (x - 1.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.4e+28) {
tmp = y * x;
} else if (x <= 1.4e+38) {
tmp = 1.0 - y;
} else {
tmp = (x - 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.4e+28: tmp = y * x elif x <= 1.4e+38: tmp = 1.0 - y else: tmp = (x - 1.0) * y return tmp
function code(x, y) tmp = 0.0 if (x <= -4.4e+28) tmp = Float64(y * x); elseif (x <= 1.4e+38) tmp = Float64(1.0 - y); else tmp = Float64(Float64(x - 1.0) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.4e+28) tmp = y * x; elseif (x <= 1.4e+38) tmp = 1.0 - y; else tmp = (x - 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.4e+28], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.4e+38], N[(1.0 - y), $MachinePrecision], N[(N[(x - 1.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+28}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+38}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;\left(x - 1\right) \cdot y\\
\end{array}
\end{array}
if x < -4.39999999999999973e28Initial program 50.6%
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-*.f6477.9
Applied rewrites77.9%
if -4.39999999999999973e28 < x < 1.4e38Initial program 97.3%
Taylor expanded in x around 0
lower--.f6497.8
Applied rewrites97.8%
if 1.4e38 < x Initial program 58.3%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6483.5
Applied rewrites83.5%
(FPCore (x y) :precision binary64 (if (or (<= x -4.4e+28) (not (<= x 1.4e+38))) (* y x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -4.4e+28) || !(x <= 1.4e+38)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-4.4d+28)) .or. (.not. (x <= 1.4d+38))) then
tmp = y * x
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4.4e+28) || !(x <= 1.4e+38)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.4e+28) or not (x <= 1.4e+38): tmp = y * x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.4e+28) || !(x <= 1.4e+38)) tmp = Float64(y * x); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.4e+28) || ~((x <= 1.4e+38))) tmp = y * x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.4e+28], N[Not[LessEqual[x, 1.4e+38]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+28} \lor \neg \left(x \leq 1.4 \cdot 10^{+38}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -4.39999999999999973e28 or 1.4e38 < x Initial program 54.6%
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-*.f6480.8
Applied rewrites80.8%
if -4.39999999999999973e28 < x < 1.4e38Initial program 97.3%
Taylor expanded in x around 0
lower--.f6497.8
Applied rewrites97.8%
Final simplification90.4%
(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.8%
Taylor expanded in x around 0
lower--.f6465.1
Applied rewrites65.1%
(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.8%
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-*.f6437.5
Applied rewrites37.5%
Taylor expanded in y around 0
Applied rewrites43.0%
(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 2024318
(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))))