
(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 (* y x))))
double code(double x, double y) {
return 1.0 - (y - (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - (y - (y * x))
end function
public static double code(double x, double y) {
return 1.0 - (y - (y * x));
}
def code(x, y): return 1.0 - (y - (y * x))
function code(x, y) return Float64(1.0 - Float64(y - Float64(y * x))) end
function tmp = code(x, y) tmp = 1.0 - (y - (y * x)); end
code[x_, y_] := N[(1.0 - N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(y - y \cdot x\right)
\end{array}
Initial program 80.4%
+-commutative80.4%
sub-neg80.4%
distribute-rgt-in80.4%
*-lft-identity80.4%
associate-+l+80.4%
+-commutative80.4%
distribute-lft-neg-out80.4%
sub-neg80.4%
associate--l+89.3%
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%
*-commutative100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -3.4) (not (<= x 0.04))) (+ 1.0 (* y x)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -3.4) || !(x <= 0.04)) {
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 <= (-3.4d0)) .or. (.not. (x <= 0.04d0))) 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 <= -3.4) || !(x <= 0.04)) {
tmp = 1.0 + (y * x);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.4) or not (x <= 0.04): tmp = 1.0 + (y * x) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.4) || !(x <= 0.04)) 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 <= -3.4) || ~((x <= 0.04))) tmp = 1.0 + (y * x); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.4], N[Not[LessEqual[x, 0.04]], $MachinePrecision]], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \lor \neg \left(x \leq 0.04\right):\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -3.39999999999999991 or 0.0400000000000000008 < x Initial program 60.1%
+-commutative60.1%
sub-neg60.1%
distribute-rgt-in60.1%
*-lft-identity60.1%
associate-+l+60.2%
+-commutative60.2%
distribute-lft-neg-out60.2%
sub-neg60.2%
associate--l+78.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 98.9%
mul-1-neg98.9%
distribute-lft-neg-out98.9%
*-commutative98.9%
Simplified98.9%
sub-neg98.9%
+-commutative98.9%
distribute-rgt-neg-out98.9%
remove-double-neg98.9%
Applied egg-rr98.9%
if -3.39999999999999991 < x < 0.0400000000000000008Initial 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 99.7%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.08e-10) (not (<= y 1.85e-89))) (* y x) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.08e-10) || !(y <= 1.85e-89)) {
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 ((y <= (-1.08d-10)) .or. (.not. (y <= 1.85d-89))) 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 ((y <= -1.08e-10) || !(y <= 1.85e-89)) {
tmp = y * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.08e-10) or not (y <= 1.85e-89): tmp = y * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.08e-10) || !(y <= 1.85e-89)) tmp = Float64(y * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.08e-10) || ~((y <= 1.85e-89))) tmp = y * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.08e-10], N[Not[LessEqual[y, 1.85e-89]], $MachinePrecision]], N[(y * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{-10} \lor \neg \left(y \leq 1.85 \cdot 10^{-89}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.08000000000000002e-10 or 1.8499999999999999e-89 < y Initial program 95.5%
+-commutative95.5%
sub-neg95.5%
distribute-rgt-in95.6%
*-lft-identity95.6%
associate-+l+95.6%
+-commutative95.6%
distribute-lft-neg-out95.6%
sub-neg95.6%
associate--l+100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 56.4%
mul-1-neg56.4%
distribute-lft-neg-out56.4%
*-commutative56.4%
Simplified56.4%
Taylor expanded in y around inf 52.3%
if -1.08000000000000002e-10 < y < 1.8499999999999999e-89Initial program 59.9%
+-commutative59.9%
sub-neg59.9%
distribute-rgt-in59.9%
*-lft-identity59.9%
associate-+l+59.9%
+-commutative59.9%
distribute-lft-neg-out59.9%
sub-neg59.9%
associate--l+74.9%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
distribute-lft-neg-out99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around 0 83.1%
Final simplification65.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.1e+22) (not (<= x 1.02e+58))) (* y x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.1e+22) || !(x <= 1.02e+58)) {
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 <= (-1.1d+22)) .or. (.not. (x <= 1.02d+58))) 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 <= -1.1e+22) || !(x <= 1.02e+58)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.1e+22) or not (x <= 1.02e+58): tmp = y * x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.1e+22) || !(x <= 1.02e+58)) 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 <= -1.1e+22) || ~((x <= 1.02e+58))) tmp = y * x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.1e+22], N[Not[LessEqual[x, 1.02e+58]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+22} \lor \neg \left(x \leq 1.02 \cdot 10^{+58}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.1e22 or 1.02000000000000005e58 < x Initial program 58.7%
+-commutative58.7%
sub-neg58.7%
distribute-rgt-in58.8%
*-lft-identity58.8%
associate-+l+58.8%
+-commutative58.8%
distribute-lft-neg-out58.8%
sub-neg58.8%
associate--l+79.5%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 79.5%
if -1.1e22 < x < 1.02000000000000005e58Initial program 96.7%
+-commutative96.7%
sub-neg96.7%
distribute-rgt-in96.7%
*-lft-identity96.7%
associate-+l+96.7%
+-commutative96.7%
distribute-lft-neg-out96.7%
sub-neg96.7%
associate--l+96.7%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 95.9%
Final simplification88.8%
(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 80.4%
+-commutative80.4%
sub-neg80.4%
distribute-rgt-in80.4%
*-lft-identity80.4%
associate-+l+80.4%
+-commutative80.4%
distribute-lft-neg-out80.4%
sub-neg80.4%
associate--l+89.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.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 80.4%
+-commutative80.4%
sub-neg80.4%
distribute-rgt-in80.4%
*-lft-identity80.4%
associate-+l+80.4%
+-commutative80.4%
distribute-lft-neg-out80.4%
sub-neg80.4%
associate--l+89.3%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 74.9%
mul-1-neg74.9%
distribute-lft-neg-out74.9%
*-commutative74.9%
Simplified74.9%
Taylor expanded in y around 0 39.2%
Final simplification39.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 2023311
(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))))