
(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 5 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 (+ 1.0 (* y (+ x -1.0))))
double code(double x, double y) {
return 1.0 + (y * (x + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (y * (x + (-1.0d0)))
end function
public static double code(double x, double y) {
return 1.0 + (y * (x + -1.0));
}
def code(x, y): return 1.0 + (y * (x + -1.0))
function code(x, y) return Float64(1.0 + Float64(y * Float64(x + -1.0))) end
function tmp = code(x, y) tmp = 1.0 + (y * (x + -1.0)); end
code[x_, y_] := N[(1.0 + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + y \cdot \left(x + -1\right)
\end{array}
Initial program 75.9%
+-commutative75.9%
remove-double-neg75.9%
unsub-neg75.9%
sub-neg75.9%
+-commutative75.9%
distribute-rgt-in75.9%
*-lft-identity75.9%
associate-+r-75.9%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 (if (<= x -4.4e+48) (* y x) (if (<= x 3.8e-7) (- 1.0 y) (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -4.4e+48) {
tmp = y * x;
} else if (x <= 3.8e-7) {
tmp = 1.0 - y;
} else {
tmp = y * (x + -1.0);
}
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+48)) then
tmp = y * x
else if (x <= 3.8d-7) then
tmp = 1.0d0 - y
else
tmp = y * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.4e+48) {
tmp = y * x;
} else if (x <= 3.8e-7) {
tmp = 1.0 - y;
} else {
tmp = y * (x + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.4e+48: tmp = y * x elif x <= 3.8e-7: tmp = 1.0 - y else: tmp = y * (x + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -4.4e+48) tmp = Float64(y * x); elseif (x <= 3.8e-7) tmp = Float64(1.0 - y); else tmp = Float64(y * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.4e+48) tmp = y * x; elseif (x <= 3.8e-7) tmp = 1.0 - y; else tmp = y * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.4e+48], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.8e-7], N[(1.0 - y), $MachinePrecision], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+48}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-7}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.3999999999999999e48Initial 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-+r-50.6%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 76.5%
*-commutative76.5%
Simplified76.5%
if -4.3999999999999999e48 < x < 3.80000000000000015e-7Initial program 95.7%
+-commutative95.7%
remove-double-neg95.7%
unsub-neg95.7%
sub-neg95.7%
+-commutative95.7%
distribute-rgt-in95.7%
*-lft-identity95.7%
associate-+r-95.7%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
if 3.80000000000000015e-7 < x Initial program 57.6%
+-commutative57.6%
remove-double-neg57.6%
unsub-neg57.6%
sub-neg57.6%
+-commutative57.6%
distribute-rgt-in57.7%
*-lft-identity57.7%
associate-+r-57.7%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 83.1%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= x -2.4e+48) (not (<= x 85000.0))) (* y x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2.4e+48) || !(x <= 85000.0)) {
tmp = y * x;
} 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 ((x <= (-2.4d+48)) .or. (.not. (x <= 85000.0d0))) then
tmp = y * x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.4e+48) || !(x <= 85000.0)) {
tmp = y * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.4e+48) or not (x <= 85000.0): tmp = y * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.4e+48) || !(x <= 85000.0)) tmp = Float64(y * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.4e+48) || ~((x <= 85000.0))) tmp = y * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.4e+48], N[Not[LessEqual[x, 85000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+48} \lor \neg \left(x \leq 85000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.4000000000000001e48 or 85000 < x Initial program 53.1%
+-commutative53.1%
remove-double-neg53.1%
unsub-neg53.1%
sub-neg53.1%
+-commutative53.1%
distribute-rgt-in53.1%
*-lft-identity53.1%
associate-+r-53.1%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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.1%
*-commutative79.1%
Simplified79.1%
if -2.4000000000000001e48 < x < 85000Initial program 95.7%
+-commutative95.7%
remove-double-neg95.7%
unsub-neg95.7%
sub-neg95.7%
+-commutative95.7%
distribute-rgt-in95.7%
*-lft-identity95.7%
associate-+r-95.7%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 48.3%
Final simplification62.6%
(FPCore (x y) :precision binary64 (if (or (<= x -2.4e+48) (not (<= x 85000.0))) (* y x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.4e+48) || !(x <= 85000.0)) {
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 <= (-2.4d+48)) .or. (.not. (x <= 85000.0d0))) 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 <= -2.4e+48) || !(x <= 85000.0)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.4e+48) or not (x <= 85000.0): tmp = y * x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.4e+48) || !(x <= 85000.0)) 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 <= -2.4e+48) || ~((x <= 85000.0))) tmp = y * x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.4e+48], N[Not[LessEqual[x, 85000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+48} \lor \neg \left(x \leq 85000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -2.4000000000000001e48 or 85000 < x Initial program 53.1%
+-commutative53.1%
remove-double-neg53.1%
unsub-neg53.1%
sub-neg53.1%
+-commutative53.1%
distribute-rgt-in53.1%
*-lft-identity53.1%
associate-+r-53.1%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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.1%
*-commutative79.1%
Simplified79.1%
if -2.4000000000000001e48 < x < 85000Initial program 95.7%
+-commutative95.7%
remove-double-neg95.7%
unsub-neg95.7%
sub-neg95.7%
+-commutative95.7%
distribute-rgt-in95.7%
*-lft-identity95.7%
associate-+r-95.7%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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 95.8%
mul-1-neg95.8%
unsub-neg95.8%
Simplified95.8%
Final simplification88.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 75.9%
+-commutative75.9%
remove-double-neg75.9%
unsub-neg75.9%
sub-neg75.9%
+-commutative75.9%
distribute-rgt-in75.9%
*-lft-identity75.9%
associate-+r-75.9%
associate--l-100.0%
sub-neg100.0%
+-inverses100.0%
--rgt-identity100.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.2%
Final simplification35.2%
(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 2024018
(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))))