
(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 77.3%
+-commutative77.3%
remove-double-neg77.3%
unsub-neg77.3%
sub-neg77.3%
+-commutative77.3%
distribute-rgt-in77.3%
*-lft-identity77.3%
associate--l+88.6%
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%
(FPCore (x y) :precision binary64 (if (or (<= x -68.0) (not (<= x 1.0))) (+ 1.0 (* y x)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -68.0) || !(x <= 1.0)) {
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 <= (-68.0d0)) .or. (.not. (x <= 1.0d0))) 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 <= -68.0) || !(x <= 1.0)) {
tmp = 1.0 + (y * x);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -68.0) or not (x <= 1.0): tmp = 1.0 + (y * x) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -68.0) || !(x <= 1.0)) 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 <= -68.0) || ~((x <= 1.0))) tmp = 1.0 + (y * x); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -68.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -68 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -68 or 1 < x Initial program 52.0%
+-commutative52.0%
remove-double-neg52.0%
unsub-neg52.0%
sub-neg52.0%
+-commutative52.0%
distribute-rgt-in52.0%
*-lft-identity52.0%
associate--l+75.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 x around inf 99.9%
*-commutative99.9%
Simplified99.9%
if -68 < 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 97.8%
neg-mul-197.8%
unsub-neg97.8%
Simplified97.8%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (or (<= y -3.9e-14) (not (<= y 0.0034))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -3.9e-14) || !(y <= 0.0034)) {
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 <= (-3.9d-14)) .or. (.not. (y <= 0.0034d0))) 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 <= -3.9e-14) || !(y <= 0.0034)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.9e-14) or not (y <= 0.0034): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.9e-14) || !(y <= 0.0034)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.9e-14) || ~((y <= 0.0034))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.9e-14], N[Not[LessEqual[y, 0.0034]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{-14} \lor \neg \left(y \leq 0.0034\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.8999999999999998e-14 or 0.00339999999999999981 < y Initial program 99.4%
+-commutative99.4%
remove-double-neg99.4%
unsub-neg99.4%
sub-neg99.4%
+-commutative99.4%
distribute-rgt-in99.4%
*-lft-identity99.4%
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 51.3%
neg-mul-151.3%
unsub-neg51.3%
Simplified51.3%
Taylor expanded in y around inf 49.7%
neg-mul-149.7%
Simplified49.7%
if -3.8999999999999998e-14 < y < 0.00339999999999999981Initial program 56.9%
+-commutative56.9%
remove-double-neg56.9%
unsub-neg56.9%
sub-neg56.9%
+-commutative56.9%
distribute-rgt-in56.9%
*-lft-identity56.9%
associate--l+78.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 0 76.5%
Final simplification63.6%
(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 77.3%
+-commutative77.3%
remove-double-neg77.3%
unsub-neg77.3%
sub-neg77.3%
+-commutative77.3%
distribute-rgt-in77.3%
*-lft-identity77.3%
associate--l+88.6%
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 64.8%
neg-mul-164.8%
unsub-neg64.8%
Simplified64.8%
(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.3%
+-commutative77.3%
remove-double-neg77.3%
unsub-neg77.3%
sub-neg77.3%
+-commutative77.3%
distribute-rgt-in77.3%
*-lft-identity77.3%
associate--l+88.6%
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.2%
(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 77.3%
+-commutative77.3%
remove-double-neg77.3%
unsub-neg77.3%
sub-neg77.3%
+-commutative77.3%
distribute-rgt-in77.3%
*-lft-identity77.3%
associate--l+88.6%
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 64.8%
neg-mul-164.8%
unsub-neg64.8%
Simplified64.8%
Taylor expanded in y around inf 25.4%
neg-mul-125.4%
Simplified25.4%
add-sqr-sqrt14.7%
sqrt-unprod14.1%
sqr-neg14.1%
sqrt-unprod2.0%
add-log-exp5.3%
add-sqr-sqrt7.6%
add-sqr-sqrt7.6%
sqrt-unprod7.6%
add-sqr-sqrt5.3%
sqrt-unprod6.0%
sqr-neg6.0%
sqrt-unprod0.6%
add-sqr-sqrt1.6%
exp-neg1.6%
rgt-mult-inverse2.5%
metadata-eval2.5%
metadata-eval2.5%
Applied egg-rr2.5%
(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 2024116
(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))))