
(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 (+ x -1.0) y 1.0))
double code(double x, double y) {
return fma((x + -1.0), y, 1.0);
}
function code(x, y) return fma(Float64(x + -1.0), y, 1.0) end
code[x_, y_] := N[(N[(x + -1.0), $MachinePrecision] * y + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + -1, y, 1\right)
\end{array}
Initial program 76.7%
+-commutative76.7%
remove-double-neg76.7%
unsub-neg76.7%
sub-neg76.7%
+-commutative76.7%
distribute-rgt-in76.8%
*-lft-identity76.8%
associate--l+87.8%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
+-commutative100.0%
*-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -4e-21) (not (<= y 1.4e-14))) (* (+ x -1.0) y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -4e-21) || !(y <= 1.4e-14)) {
tmp = (x + -1.0) * 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 <= (-4d-21)) .or. (.not. (y <= 1.4d-14))) then
tmp = (x + (-1.0d0)) * y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4e-21) || !(y <= 1.4e-14)) {
tmp = (x + -1.0) * y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4e-21) or not (y <= 1.4e-14): tmp = (x + -1.0) * y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4e-21) || !(y <= 1.4e-14)) tmp = Float64(Float64(x + -1.0) * y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4e-21) || ~((y <= 1.4e-14))) tmp = (x + -1.0) * y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4e-21], N[Not[LessEqual[y, 1.4e-14]], $MachinePrecision]], N[(N[(x + -1.0), $MachinePrecision] * y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-21} \lor \neg \left(y \leq 1.4 \cdot 10^{-14}\right):\\
\;\;\;\;\left(x + -1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.99999999999999963e-21 or 1.4e-14 < y Initial program 98.4%
+-commutative98.4%
remove-double-neg98.4%
unsub-neg98.4%
sub-neg98.4%
+-commutative98.4%
distribute-rgt-in98.5%
*-lft-identity98.5%
associate--l+100.0%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 97.7%
if -3.99999999999999963e-21 < y < 1.4e-14Initial program 50.6%
+-commutative50.6%
remove-double-neg50.6%
unsub-neg50.6%
sub-neg50.6%
+-commutative50.6%
distribute-rgt-in50.6%
*-lft-identity50.6%
associate--l+73.2%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 75.3%
Final simplification87.5%
(FPCore (x y) :precision binary64 (if (or (<= y -3.7e-22) (not (<= y 2.4e-13))) (* x y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -3.7e-22) || !(y <= 2.4e-13)) {
tmp = x * 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 <= (-3.7d-22)) .or. (.not. (y <= 2.4d-13))) then
tmp = x * y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.7e-22) || !(y <= 2.4e-13)) {
tmp = x * y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.7e-22) or not (y <= 2.4e-13): tmp = x * y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.7e-22) || !(y <= 2.4e-13)) tmp = Float64(x * y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.7e-22) || ~((y <= 2.4e-13))) tmp = x * y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.7e-22], N[Not[LessEqual[y, 2.4e-13]], $MachinePrecision]], N[(x * y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-22} \lor \neg \left(y \leq 2.4 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.7e-22 or 2.3999999999999999e-13 < y Initial program 98.4%
+-commutative98.4%
remove-double-neg98.4%
unsub-neg98.4%
sub-neg98.4%
+-commutative98.4%
distribute-rgt-in98.5%
*-lft-identity98.5%
associate--l+100.0%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 60.7%
*-commutative60.7%
Simplified60.7%
if -3.7e-22 < y < 2.3999999999999999e-13Initial program 50.6%
+-commutative50.6%
remove-double-neg50.6%
unsub-neg50.6%
sub-neg50.6%
+-commutative50.6%
distribute-rgt-in50.6%
*-lft-identity50.6%
associate--l+73.2%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 75.3%
Final simplification67.3%
(FPCore (x y) :precision binary64 (if (or (<= x -5200.0) (not (<= x 3.1e+60))) (* x y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -5200.0) || !(x <= 3.1e+60)) {
tmp = x * y;
} 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 <= (-5200.0d0)) .or. (.not. (x <= 3.1d+60))) then
tmp = x * y
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5200.0) || !(x <= 3.1e+60)) {
tmp = x * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5200.0) or not (x <= 3.1e+60): tmp = x * y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -5200.0) || !(x <= 3.1e+60)) tmp = Float64(x * y); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5200.0) || ~((x <= 3.1e+60))) tmp = x * y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5200.0], N[Not[LessEqual[x, 3.1e+60]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5200 \lor \neg \left(x \leq 3.1 \cdot 10^{+60}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -5200 or 3.1000000000000001e60 < x Initial program 58.9%
+-commutative58.9%
remove-double-neg58.9%
unsub-neg58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-in59.0%
*-lft-identity59.0%
associate--l+80.2%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 79.3%
*-commutative79.3%
Simplified79.3%
if -5200 < x < 3.1000000000000001e60Initial program 96.0%
+-commutative96.0%
remove-double-neg96.0%
unsub-neg96.0%
sub-neg96.0%
+-commutative96.0%
distribute-rgt-in96.0%
*-lft-identity96.0%
associate--l+96.1%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 94.6%
mul-1-neg94.6%
unsub-neg94.6%
Simplified94.6%
Final simplification86.6%
(FPCore (x y) :precision binary64 (+ 1.0 (* (+ x -1.0) y)))
double code(double x, double y) {
return 1.0 + ((x + -1.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((x + (-1.0d0)) * y)
end function
public static double code(double x, double y) {
return 1.0 + ((x + -1.0) * y);
}
def code(x, y): return 1.0 + ((x + -1.0) * y)
function code(x, y) return Float64(1.0 + Float64(Float64(x + -1.0) * y)) end
function tmp = code(x, y) tmp = 1.0 + ((x + -1.0) * y); end
code[x_, y_] := N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(x + -1\right) \cdot y
\end{array}
Initial program 76.7%
+-commutative76.7%
remove-double-neg76.7%
unsub-neg76.7%
sub-neg76.7%
+-commutative76.7%
distribute-rgt-in76.8%
*-lft-identity76.8%
associate--l+87.8%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(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 76.7%
+-commutative76.7%
remove-double-neg76.7%
unsub-neg76.7%
sub-neg76.7%
+-commutative76.7%
distribute-rgt-in76.8%
*-lft-identity76.8%
associate--l+87.8%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 35.7%
Final simplification35.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 2024079
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))