
(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 (+ 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 74.2%
+-commutative74.2%
remove-double-neg74.2%
unsub-neg74.2%
sub-neg74.2%
+-commutative74.2%
distribute-rgt-in74.2%
*-lft-identity74.2%
associate-+r-74.2%
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%
(FPCore (x y) :precision binary64 (if (or (<= x -1.45e+38) (not (<= x 1.62e-16))) (+ 1.0 (* y x)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.45e+38) || !(x <= 1.62e-16)) {
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 <= (-1.45d+38)) .or. (.not. (x <= 1.62d-16))) 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 <= -1.45e+38) || !(x <= 1.62e-16)) {
tmp = 1.0 + (y * x);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.45e+38) or not (x <= 1.62e-16): tmp = 1.0 + (y * x) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.45e+38) || !(x <= 1.62e-16)) 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 <= -1.45e+38) || ~((x <= 1.62e-16))) tmp = 1.0 + (y * x); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.45e+38], N[Not[LessEqual[x, 1.62e-16]], $MachinePrecision]], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{+38} \lor \neg \left(x \leq 1.62 \cdot 10^{-16}\right):\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.45000000000000003e38 or 1.61999999999999995e-16 < x Initial program 46.5%
+-commutative46.5%
remove-double-neg46.5%
unsub-neg46.5%
sub-neg46.5%
+-commutative46.5%
distribute-rgt-in46.6%
*-lft-identity46.6%
associate-+r-46.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 98.8%
*-commutative98.8%
Simplified98.8%
if -1.45000000000000003e38 < x < 1.61999999999999995e-16Initial program 98.6%
+-commutative98.6%
remove-double-neg98.6%
unsub-neg98.6%
sub-neg98.6%
+-commutative98.6%
distribute-rgt-in98.6%
*-lft-identity98.6%
associate-+r-98.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 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.3e-14))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.3e-14)) {
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 <= 1.3d-14))) 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 <= 1.3e-14)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.3e-14): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.3e-14)) 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 <= 1.3e-14))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.3e-14]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.3 \cdot 10^{-14}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.29999999999999998e-14 < y Initial program 99.0%
+-commutative99.0%
remove-double-neg99.0%
unsub-neg99.0%
sub-neg99.0%
+-commutative99.0%
distribute-rgt-in99.0%
*-lft-identity99.0%
associate-+r-99.0%
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 55.6%
neg-mul-155.6%
unsub-neg55.6%
Simplified55.6%
Taylor expanded in y around inf 53.8%
neg-mul-153.8%
Simplified53.8%
if -1 < y < 1.29999999999999998e-14Initial program 54.9%
+-commutative54.9%
remove-double-neg54.9%
unsub-neg54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-in54.9%
*-lft-identity54.9%
associate-+r-54.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 75.6%
Final simplification66.0%
(FPCore (x y) :precision binary64 (- 1.0 y))
double code(double x, double y) {
return 1.0 - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - y
end function
public static double code(double x, double y) {
return 1.0 - y;
}
def code(x, y): return 1.0 - y
function code(x, y) return Float64(1.0 - y) end
function tmp = code(x, y) tmp = 1.0 - y; end
code[x_, y_] := N[(1.0 - y), $MachinePrecision]
\begin{array}{l}
\\
1 - y
\end{array}
Initial program 74.2%
+-commutative74.2%
remove-double-neg74.2%
unsub-neg74.2%
sub-neg74.2%
+-commutative74.2%
distribute-rgt-in74.2%
*-lft-identity74.2%
associate-+r-74.2%
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 67.5%
neg-mul-167.5%
unsub-neg67.5%
Simplified67.5%
(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.2%
+-commutative74.2%
remove-double-neg74.2%
unsub-neg74.2%
sub-neg74.2%
+-commutative74.2%
distribute-rgt-in74.2%
*-lft-identity74.2%
associate-+r-74.2%
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 43.7%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 74.2%
+-commutative74.2%
remove-double-neg74.2%
unsub-neg74.2%
sub-neg74.2%
+-commutative74.2%
distribute-rgt-in74.2%
*-lft-identity74.2%
associate-+r-74.2%
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 67.5%
neg-mul-167.5%
unsub-neg67.5%
Simplified67.5%
Taylor expanded in y around inf 25.6%
neg-mul-125.6%
Simplified25.6%
add-sqr-sqrt12.6%
sqrt-unprod13.0%
sqr-neg13.0%
sqrt-unprod1.5%
add-log-exp4.4%
add-sqr-sqrt9.1%
add-sqr-sqrt9.1%
sqrt-unprod9.1%
add-sqr-sqrt4.4%
sqrt-unprod5.4%
sqr-neg5.4%
sqrt-unprod1.0%
add-sqr-sqrt1.7%
exp-neg1.7%
rgt-mult-inverse2.6%
metadata-eval2.6%
metadata-eval2.6%
Applied egg-rr2.6%
(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 2024170
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (- (* y x) (- y 1)))
(+ x (* (- 1.0 x) (- 1.0 y))))