
(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.8%
+-commutative76.8%
remove-double-neg76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
distribute-rgt-in76.9%
*-lft-identity76.9%
associate--l+87.7%
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 (<= x -1.0) (not (<= x 1.0))) (+ 1.0 (* x y)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = 1.0 + (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 <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 1.0d0 + (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 <= -1.0) || !(x <= 1.0)) {
tmp = 1.0 + (x * y);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = 1.0 + (x * y) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(1.0 + Float64(x * y)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = 1.0 + (x * y); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;1 + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 53.6%
+-commutative53.6%
remove-double-neg53.6%
unsub-neg53.6%
sub-neg53.6%
+-commutative53.6%
distribute-rgt-in53.7%
*-lft-identity53.7%
associate--l+75.3%
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 98.5%
*-commutative98.5%
Simplified98.5%
if -1 < x < 1Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
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 0 99.3%
neg-mul-199.3%
unsub-neg99.3%
Simplified99.3%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.15e-34) (not (<= y 1.25e-81))) (* x y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.15e-34) || !(y <= 1.25e-81)) {
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 <= (-1.15d-34)) .or. (.not. (y <= 1.25d-81))) 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 <= -1.15e-34) || !(y <= 1.25e-81)) {
tmp = x * y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.15e-34) or not (y <= 1.25e-81): tmp = x * y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.15e-34) || !(y <= 1.25e-81)) tmp = Float64(x * y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.15e-34) || ~((y <= 1.25e-81))) tmp = x * y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.15e-34], N[Not[LessEqual[y, 1.25e-81]], $MachinePrecision]], N[(x * y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-34} \lor \neg \left(y \leq 1.25 \cdot 10^{-81}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.15000000000000006e-34 or 1.24999999999999995e-81 < y Initial program 90.6%
+-commutative90.6%
remove-double-neg90.6%
unsub-neg90.6%
sub-neg90.6%
+-commutative90.6%
distribute-rgt-in90.8%
*-lft-identity90.8%
associate--l+99.3%
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 59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in y around inf 53.2%
if -1.15000000000000006e-34 < y < 1.24999999999999995e-81Initial program 58.1%
+-commutative58.1%
remove-double-neg58.1%
unsub-neg58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-in58.1%
*-lft-identity58.1%
associate--l+71.9%
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 84.7%
Final simplification66.7%
(FPCore (x y) :precision binary64 (if (or (<= x -2.1e+25) (not (<= x 1.35e+35))) (* x y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.1e+25) || !(x <= 1.35e+35)) {
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 <= (-2.1d+25)) .or. (.not. (x <= 1.35d+35))) 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 <= -2.1e+25) || !(x <= 1.35e+35)) {
tmp = x * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.1e+25) or not (x <= 1.35e+35): tmp = x * y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.1e+25) || !(x <= 1.35e+35)) 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 <= -2.1e+25) || ~((x <= 1.35e+35))) tmp = x * y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.1e+25], N[Not[LessEqual[x, 1.35e+35]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+25} \lor \neg \left(x \leq 1.35 \cdot 10^{+35}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -2.0999999999999999e25 or 1.35000000000000001e35 < x Initial program 54.3%
+-commutative54.3%
remove-double-neg54.3%
unsub-neg54.3%
sub-neg54.3%
+-commutative54.3%
distribute-rgt-in54.4%
*-lft-identity54.4%
associate--l+78.5%
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 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 78.5%
if -2.0999999999999999e25 < x < 1.35000000000000001e35Initial program 94.0%
+-commutative94.0%
remove-double-neg94.0%
unsub-neg94.0%
sub-neg94.0%
+-commutative94.0%
distribute-rgt-in94.1%
*-lft-identity94.1%
associate--l+94.7%
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.8%
neg-mul-194.8%
unsub-neg94.8%
Simplified94.8%
Final simplification87.7%
(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.8%
+-commutative76.8%
remove-double-neg76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
distribute-rgt-in76.9%
*-lft-identity76.9%
associate--l+87.7%
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.8%
+-commutative76.8%
remove-double-neg76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
distribute-rgt-in76.9%
*-lft-identity76.9%
associate--l+87.7%
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 41.1%
Final simplification41.1%
(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 2024053
(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))))