
(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 7 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 (* (- 1.0 x) y)))
double code(double x, double y) {
return 1.0 - ((1.0 - x) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - ((1.0d0 - x) * y)
end function
public static double code(double x, double y) {
return 1.0 - ((1.0 - x) * y);
}
def code(x, y): return 1.0 - ((1.0 - x) * y)
function code(x, y) return Float64(1.0 - Float64(Float64(1.0 - x) * y)) end
function tmp = code(x, y) tmp = 1.0 - ((1.0 - x) * y); end
code[x_, y_] := N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(1 - x\right) \cdot y
\end{array}
Initial program 77.6%
+-commutative77.6%
sub-neg77.6%
distribute-rgt-in77.6%
*-lft-identity77.6%
associate-+l+77.6%
+-commutative77.6%
distribute-lft-neg-out77.6%
sub-neg77.6%
associate--l+88.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= (- 1.0 y) -5000000000.0) (not (<= (- 1.0 y) 1.0))) (* y (+ x -1.0)) (+ 1.0 (* x y))))
double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -5000000000.0) || !((1.0 - y) <= 1.0)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 + (x * y);
}
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) <= (-5000000000.0d0)) .or. (.not. ((1.0d0 - y) <= 1.0d0))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -5000000000.0) || !((1.0 - y) <= 1.0)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - y) <= -5000000000.0) or not ((1.0 - y) <= 1.0): tmp = y * (x + -1.0) else: tmp = 1.0 + (x * y) return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - y) <= -5000000000.0) || !(Float64(1.0 - y) <= 1.0)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - y) <= -5000000000.0) || ~(((1.0 - y) <= 1.0))) tmp = y * (x + -1.0); else tmp = 1.0 + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - y), $MachinePrecision], -5000000000.0], N[Not[LessEqual[N[(1.0 - y), $MachinePrecision], 1.0]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -5000000000 \lor \neg \left(1 - y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot y\\
\end{array}
\end{array}
if (-.f64 1 y) < -5e9 or 1 < (-.f64 1 y) Initial program 99.0%
+-commutative99.0%
sub-neg99.0%
distribute-rgt-in99.0%
*-lft-identity99.0%
associate-+l+99.0%
+-commutative99.0%
distribute-lft-neg-out99.0%
sub-neg99.0%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 99.7%
if -5e9 < (-.f64 1 y) < 1Initial program 55.9%
+-commutative55.9%
sub-neg55.9%
distribute-rgt-in56.0%
*-lft-identity56.0%
associate-+l+56.0%
+-commutative56.0%
distribute-lft-neg-out56.0%
sub-neg56.0%
associate--l+76.5%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 98.5%
mul-1-neg98.5%
distribute-rgt-neg-in98.5%
Simplified98.5%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e-51) (not (<= y 0.00018))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-51) || !(y <= 0.00018)) {
tmp = y * (x + -1.0);
} 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 ((y <= (-7.5d-51)) .or. (.not. (y <= 0.00018d0))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.5e-51) || !(y <= 0.00018)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e-51) or not (y <= 0.00018): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e-51) || !(y <= 0.00018)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e-51) || ~((y <= 0.00018))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-51], N[Not[LessEqual[y, 0.00018]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-51} \lor \neg \left(y \leq 0.00018\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -7.49999999999999976e-51 or 1.80000000000000011e-4 < y Initial program 96.8%
+-commutative96.8%
sub-neg96.8%
distribute-rgt-in96.8%
*-lft-identity96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-neg-out96.8%
sub-neg96.8%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 97.1%
if -7.49999999999999976e-51 < y < 1.80000000000000011e-4Initial program 54.8%
+-commutative54.8%
sub-neg54.8%
distribute-rgt-in54.9%
*-lft-identity54.9%
associate-+l+54.9%
+-commutative54.9%
distribute-lft-neg-out54.9%
sub-neg54.9%
associate--l+74.5%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 78.8%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (or (<= y -2.9e-44) (not (<= y 6.3e-18))) (* x y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -2.9e-44) || !(y <= 6.3e-18)) {
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 <= (-2.9d-44)) .or. (.not. (y <= 6.3d-18))) 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 <= -2.9e-44) || !(y <= 6.3e-18)) {
tmp = x * y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.9e-44) or not (y <= 6.3e-18): tmp = x * y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.9e-44) || !(y <= 6.3e-18)) tmp = Float64(x * y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.9e-44) || ~((y <= 6.3e-18))) tmp = x * y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.9e-44], N[Not[LessEqual[y, 6.3e-18]], $MachinePrecision]], N[(x * y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-44} \lor \neg \left(y \leq 6.3 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.9000000000000001e-44 or 6.3000000000000004e-18 < y Initial program 96.6%
+-commutative96.6%
sub-neg96.6%
distribute-rgt-in96.6%
*-lft-identity96.6%
associate-+l+96.6%
+-commutative96.6%
distribute-lft-neg-out96.6%
sub-neg96.6%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 55.7%
*-commutative55.7%
Simplified55.7%
if -2.9000000000000001e-44 < y < 6.3000000000000004e-18Initial program 54.4%
+-commutative54.4%
sub-neg54.4%
distribute-rgt-in54.4%
*-lft-identity54.4%
associate-+l+54.4%
+-commutative54.4%
distribute-lft-neg-out54.4%
sub-neg54.4%
associate--l+74.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 79.3%
Final simplification66.3%
(FPCore (x y) :precision binary64 (if (or (<= x -5.4e+48) (not (<= x 2.7e+48))) (* x y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -5.4e+48) || !(x <= 2.7e+48)) {
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 <= (-5.4d+48)) .or. (.not. (x <= 2.7d+48))) 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 <= -5.4e+48) || !(x <= 2.7e+48)) {
tmp = x * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.4e+48) or not (x <= 2.7e+48): tmp = x * y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.4e+48) || !(x <= 2.7e+48)) 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 <= -5.4e+48) || ~((x <= 2.7e+48))) tmp = x * y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.4e+48], N[Not[LessEqual[x, 2.7e+48]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+48} \lor \neg \left(x \leq 2.7 \cdot 10^{+48}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -5.40000000000000007e48 or 2.70000000000000004e48 < x Initial program 57.5%
+-commutative57.5%
sub-neg57.5%
distribute-rgt-in57.5%
*-lft-identity57.5%
associate-+l+57.5%
+-commutative57.5%
distribute-lft-neg-out57.5%
sub-neg57.5%
associate--l+80.1%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 80.1%
*-commutative80.1%
Simplified80.1%
if -5.40000000000000007e48 < x < 2.70000000000000004e48Initial program 95.6%
+-commutative95.6%
sub-neg95.6%
distribute-rgt-in95.6%
*-lft-identity95.6%
associate-+l+95.6%
+-commutative95.6%
distribute-lft-neg-out95.6%
sub-neg95.6%
associate--l+95.7%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 94.6%
Final simplification87.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e-5) (not (<= y 1600000000.0))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e-5) || !(y <= 1600000000.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.4d-5)) .or. (.not. (y <= 1600000000.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.4e-5) || !(y <= 1600000000.0)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e-5) or not (y <= 1600000000.0): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e-5) || !(y <= 1600000000.0)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e-5) || ~((y <= 1600000000.0))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e-5], N[Not[LessEqual[y, 1600000000.0]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-5} \lor \neg \left(y \leq 1600000000\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.39999999999999998e-5 or 1.6e9 < y Initial program 99.8%
+-commutative99.8%
sub-neg99.8%
distribute-rgt-in99.8%
*-lft-identity99.8%
associate-+l+99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
sub-neg99.8%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around 0 46.2%
neg-mul-146.2%
Simplified46.2%
if -1.39999999999999998e-5 < y < 1.6e9Initial program 55.8%
+-commutative55.8%
sub-neg55.8%
distribute-rgt-in55.8%
*-lft-identity55.8%
associate-+l+55.8%
+-commutative55.8%
distribute-lft-neg-out55.8%
sub-neg55.8%
associate--l+76.9%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 73.3%
Final simplification59.9%
(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 77.6%
+-commutative77.6%
sub-neg77.6%
distribute-rgt-in77.6%
*-lft-identity77.6%
associate-+l+77.6%
+-commutative77.6%
distribute-lft-neg-out77.6%
sub-neg77.6%
associate--l+88.3%
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 2023314
(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))))