
(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 4 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) y)))
double code(double x, double y) {
return 1.0 + ((y * x) - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((y * x) - y)
end function
public static double code(double x, double y) {
return 1.0 + ((y * x) - y);
}
def code(x, y): return 1.0 + ((y * x) - y)
function code(x, y) return Float64(1.0 + Float64(Float64(y * x) - y)) end
function tmp = code(x, y) tmp = 1.0 + ((y * x) - y); end
code[x_, y_] := N[(1.0 + N[(N[(y * x), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(y \cdot x - y\right)
\end{array}
Initial program 77.7%
+-commutative77.7%
sub-neg77.7%
distribute-rgt-in77.8%
*-lft-identity77.8%
associate-+l+77.8%
+-commutative77.8%
distribute-lft-neg-out77.8%
sub-neg77.8%
associate--l+88.9%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -38000.0) (not (<= x 0.000155))) (+ 1.0 (* y x)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -38000.0) || !(x <= 0.000155)) {
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 <= (-38000.0d0)) .or. (.not. (x <= 0.000155d0))) 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 <= -38000.0) || !(x <= 0.000155)) {
tmp = 1.0 + (y * x);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -38000.0) or not (x <= 0.000155): tmp = 1.0 + (y * x) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -38000.0) || !(x <= 0.000155)) 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 <= -38000.0) || ~((x <= 0.000155))) tmp = 1.0 + (y * x); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -38000.0], N[Not[LessEqual[x, 0.000155]], $MachinePrecision]], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -38000 \lor \neg \left(x \leq 0.000155\right):\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -38000 or 1.55e-4 < x Initial program 57.2%
+-commutative57.2%
sub-neg57.2%
distribute-rgt-in57.2%
*-lft-identity57.2%
associate-+l+57.2%
+-commutative57.2%
distribute-lft-neg-out57.2%
sub-neg57.2%
associate--l+78.6%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.4%
mul-1-neg99.4%
distribute-lft-neg-out99.4%
*-commutative99.4%
Simplified99.4%
if -38000 < x < 1.55e-4Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.6%
Final simplification99.0%
(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.7%
+-commutative77.7%
sub-neg77.7%
distribute-rgt-in77.8%
*-lft-identity77.8%
associate-+l+77.8%
+-commutative77.8%
distribute-lft-neg-out77.8%
sub-neg77.8%
associate--l+88.9%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.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 77.7%
+-commutative77.7%
sub-neg77.7%
distribute-rgt-in77.8%
*-lft-identity77.8%
associate-+l+77.8%
+-commutative77.8%
distribute-lft-neg-out77.8%
sub-neg77.8%
associate--l+88.9%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.5%
Final simplification62.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 2023336
(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))))