
(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 8 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 74.9%
+-commutative74.9%
sub-neg74.9%
+-commutative74.9%
distribute-rgt-in75.0%
*-lft-identity75.0%
associate-+l+88.8%
neg-mul-188.8%
*-commutative88.8%
associate-*l*88.8%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
fma-def100.0%
mul-1-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.3e+121)
(- y)
(if (<= y -3e-108)
(* y x)
(if (<= y 2e-130)
1.0
(if (<= y 5.1e-54)
(* y x)
(if (<= y 1.7e-38)
1.0
(if (or (<= y 1.08e+113) (not (<= y 2.7e+172))) (* y x) (- y))))))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e+121) {
tmp = -y;
} else if (y <= -3e-108) {
tmp = y * x;
} else if (y <= 2e-130) {
tmp = 1.0;
} else if (y <= 5.1e-54) {
tmp = y * x;
} else if (y <= 1.7e-38) {
tmp = 1.0;
} else if ((y <= 1.08e+113) || !(y <= 2.7e+172)) {
tmp = y * 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 <= (-2.3d+121)) then
tmp = -y
else if (y <= (-3d-108)) then
tmp = y * x
else if (y <= 2d-130) then
tmp = 1.0d0
else if (y <= 5.1d-54) then
tmp = y * x
else if (y <= 1.7d-38) then
tmp = 1.0d0
else if ((y <= 1.08d+113) .or. (.not. (y <= 2.7d+172))) then
tmp = y * x
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.3e+121) {
tmp = -y;
} else if (y <= -3e-108) {
tmp = y * x;
} else if (y <= 2e-130) {
tmp = 1.0;
} else if (y <= 5.1e-54) {
tmp = y * x;
} else if (y <= 1.7e-38) {
tmp = 1.0;
} else if ((y <= 1.08e+113) || !(y <= 2.7e+172)) {
tmp = y * x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e+121: tmp = -y elif y <= -3e-108: tmp = y * x elif y <= 2e-130: tmp = 1.0 elif y <= 5.1e-54: tmp = y * x elif y <= 1.7e-38: tmp = 1.0 elif (y <= 1.08e+113) or not (y <= 2.7e+172): tmp = y * x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e+121) tmp = Float64(-y); elseif (y <= -3e-108) tmp = Float64(y * x); elseif (y <= 2e-130) tmp = 1.0; elseif (y <= 5.1e-54) tmp = Float64(y * x); elseif (y <= 1.7e-38) tmp = 1.0; elseif ((y <= 1.08e+113) || !(y <= 2.7e+172)) tmp = Float64(y * x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e+121) tmp = -y; elseif (y <= -3e-108) tmp = y * x; elseif (y <= 2e-130) tmp = 1.0; elseif (y <= 5.1e-54) tmp = y * x; elseif (y <= 1.7e-38) tmp = 1.0; elseif ((y <= 1.08e+113) || ~((y <= 2.7e+172))) tmp = y * x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e+121], (-y), If[LessEqual[y, -3e-108], N[(y * x), $MachinePrecision], If[LessEqual[y, 2e-130], 1.0, If[LessEqual[y, 5.1e-54], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.7e-38], 1.0, If[Or[LessEqual[y, 1.08e+113], N[Not[LessEqual[y, 2.7e+172]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-y)]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+121}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-108}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-130}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-54}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-38}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.08 \cdot 10^{+113} \lor \neg \left(y \leq 2.7 \cdot 10^{+172}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -2.2999999999999999e121 or 1.08e113 < y < 2.7e172Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 68.2%
neg-mul-168.2%
Simplified68.2%
if -2.2999999999999999e121 < y < -2.99999999999999993e-108 or 2.0000000000000002e-130 < y < 5.1000000000000001e-54 or 1.7000000000000001e-38 < y < 1.08e113 or 2.7e172 < y Initial program 75.3%
+-commutative75.3%
sub-neg75.3%
distribute-rgt-in75.3%
*-lft-identity75.3%
associate-+l+75.3%
+-commutative75.3%
distribute-lft-neg-out75.3%
sub-neg75.3%
associate--l+97.9%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 68.2%
*-commutative68.2%
Simplified68.2%
if -2.99999999999999993e-108 < y < 2.0000000000000002e-130 or 5.1000000000000001e-54 < y < 1.7000000000000001e-38Initial program 62.4%
+-commutative62.4%
sub-neg62.4%
distribute-rgt-in62.4%
*-lft-identity62.4%
associate-+l+62.4%
+-commutative62.4%
distribute-lft-neg-out62.4%
sub-neg62.4%
associate--l+72.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 88.6%
Final simplification75.8%
(FPCore (x y) :precision binary64 (if (or (<= x -620000000000.0) (not (<= x 1.0))) (+ 1.0 (* y x)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -620000000000.0) || !(x <= 1.0)) {
tmp = 1.0 + (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 <= (-620000000000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 1.0d0 + (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 <= -620000000000.0) || !(x <= 1.0)) {
tmp = 1.0 + (y * x);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -620000000000.0) or not (x <= 1.0): tmp = 1.0 + (y * x) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -620000000000.0) || !(x <= 1.0)) tmp = Float64(1.0 + Float64(y * x)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -620000000000.0) || ~((x <= 1.0))) tmp = 1.0 + (y * x); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -620000000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -620000000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -6.2e11 or 1 < x Initial program 51.8%
+-commutative51.8%
sub-neg51.8%
distribute-rgt-in51.8%
*-lft-identity51.8%
associate-+l+51.8%
+-commutative51.8%
distribute-lft-neg-out51.8%
sub-neg51.8%
associate--l+78.4%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
distribute-lft-neg-out99.8%
*-commutative99.8%
Simplified99.8%
*-commutative99.8%
cancel-sign-sub99.8%
*-commutative99.8%
+-commutative99.8%
Applied egg-rr99.8%
if -6.2e11 < x < 1Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
Final simplification99.5%
(FPCore (x y) :precision binary64 (if (or (<= x -1.42e+26) (not (<= x 2.75e+20))) (* y x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.42e+26) || !(x <= 2.75e+20)) {
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 <= (-1.42d+26)) .or. (.not. (x <= 2.75d+20))) 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 <= -1.42e+26) || !(x <= 2.75e+20)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.42e+26) or not (x <= 2.75e+20): tmp = y * x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.42e+26) || !(x <= 2.75e+20)) 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 <= -1.42e+26) || ~((x <= 2.75e+20))) tmp = y * x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.42e+26], N[Not[LessEqual[x, 2.75e+20]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.42 \cdot 10^{+26} \lor \neg \left(x \leq 2.75 \cdot 10^{+20}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.42e26 or 2.75e20 < x Initial program 52.4%
+-commutative52.4%
sub-neg52.4%
distribute-rgt-in52.5%
*-lft-identity52.5%
associate-+l+52.5%
+-commutative52.5%
distribute-lft-neg-out52.5%
sub-neg52.5%
associate--l+80.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 80.3%
*-commutative80.3%
Simplified80.3%
if -1.42e26 < x < 2.75e20Initial program 97.1%
+-commutative97.1%
sub-neg97.1%
distribute-rgt-in97.1%
*-lft-identity97.1%
associate-+l+97.1%
+-commutative97.1%
distribute-lft-neg-out97.1%
sub-neg97.1%
associate--l+97.1%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.5%
Final simplification89.4%
(FPCore (x y) :precision binary64 (- 1.0 (* y (- 1.0 x))))
double code(double x, double y) {
return 1.0 - (y * (1.0 - x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - (y * (1.0d0 - x))
end function
public static double code(double x, double y) {
return 1.0 - (y * (1.0 - x));
}
def code(x, y): return 1.0 - (y * (1.0 - x))
function code(x, y) return Float64(1.0 - Float64(y * Float64(1.0 - x))) end
function tmp = code(x, y) tmp = 1.0 - (y * (1.0 - x)); end
code[x_, y_] := N[(1.0 - N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - y \cdot \left(1 - x\right)
\end{array}
Initial program 74.9%
+-commutative74.9%
sub-neg74.9%
distribute-rgt-in75.0%
*-lft-identity75.0%
associate-+l+75.0%
+-commutative75.0%
distribute-lft-neg-out75.0%
sub-neg75.0%
associate--l+88.8%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (- (+ 1.0 (* y x)) y))
double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (y * x)) - y
end function
public static double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
def code(x, y): return (1.0 + (y * x)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(y * x)) - y) end
function tmp = code(x, y) tmp = (1.0 + (y * x)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + y \cdot x\right) - y
\end{array}
Initial program 74.9%
+-commutative74.9%
sub-neg74.9%
distribute-rgt-in75.0%
*-lft-identity75.0%
associate-+l+75.0%
+-commutative75.0%
distribute-lft-neg-out75.0%
sub-neg75.0%
associate--l+88.8%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 125.0))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 125.0)) {
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 ((y <= (-1.0d0)) .or. (.not. (y <= 125.0d0))) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 125.0)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 125.0): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 125.0)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 125.0))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 125.0]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 125\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 125 < y Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 98.8%
Taylor expanded in x around 0 48.0%
neg-mul-148.0%
Simplified48.0%
if -1 < y < 125Initial program 53.5%
+-commutative53.5%
sub-neg53.5%
distribute-rgt-in53.6%
*-lft-identity53.6%
associate-+l+53.6%
+-commutative53.6%
distribute-lft-neg-out53.6%
sub-neg53.6%
associate--l+79.2%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 68.8%
Final simplification59.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 74.9%
+-commutative74.9%
sub-neg74.9%
distribute-rgt-in75.0%
*-lft-identity75.0%
associate-+l+75.0%
+-commutative75.0%
distribute-lft-neg-out75.0%
sub-neg75.0%
associate--l+88.8%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 38.3%
Final simplification38.3%
(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 2023318
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))