
(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 (fma (+ x -1.0) y 1.0))
double code(double x, double y) {
return fma((x + -1.0), y, 1.0);
}
function code(x, y) return fma(Float64(x + -1.0), y, 1.0) end
code[x_, y_] := N[(N[(x + -1.0), $MachinePrecision] * y + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + -1, y, 1\right)
\end{array}
Initial program 78.3%
+-commutative78.3%
remove-double-neg78.3%
unsub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-rgt-in78.3%
*-lft-identity78.3%
associate--l+88.5%
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%
+-commutative100.0%
*-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -1.2e+128)
(not
(or (<= x -5.6e+68)
(and (not (<= x -28000000.0)) (<= x 67000000000.0)))))
(* x y)
(- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.2e+128) || !((x <= -5.6e+68) || (!(x <= -28000000.0) && (x <= 67000000000.0)))) {
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 <= (-1.2d+128)) .or. (.not. (x <= (-5.6d+68)) .or. (.not. (x <= (-28000000.0d0))) .and. (x <= 67000000000.0d0))) 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 <= -1.2e+128) || !((x <= -5.6e+68) || (!(x <= -28000000.0) && (x <= 67000000000.0)))) {
tmp = x * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.2e+128) or not ((x <= -5.6e+68) or (not (x <= -28000000.0) and (x <= 67000000000.0))): tmp = x * y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.2e+128) || !((x <= -5.6e+68) || (!(x <= -28000000.0) && (x <= 67000000000.0)))) 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 <= -1.2e+128) || ~(((x <= -5.6e+68) || (~((x <= -28000000.0)) && (x <= 67000000000.0))))) tmp = x * y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.2e+128], N[Not[Or[LessEqual[x, -5.6e+68], And[N[Not[LessEqual[x, -28000000.0]], $MachinePrecision], LessEqual[x, 67000000000.0]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+128} \lor \neg \left(x \leq -5.6 \cdot 10^{+68} \lor \neg \left(x \leq -28000000\right) \land x \leq 67000000000\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.2000000000000001e128 or -5.6e68 < x < -2.8e7 or 6.7e10 < x Initial program 60.4%
+-commutative60.4%
remove-double-neg60.4%
unsub-neg60.4%
sub-neg60.4%
+-commutative60.4%
distribute-rgt-in60.4%
*-lft-identity60.4%
associate--l+83.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 83.2%
*-commutative83.2%
Simplified83.2%
if -1.2000000000000001e128 < x < -5.6e68 or -2.8e7 < x < 6.7e10Initial program 92.0%
+-commutative92.0%
remove-double-neg92.0%
unsub-neg92.0%
sub-neg92.0%
+-commutative92.0%
distribute-rgt-in92.0%
*-lft-identity92.0%
associate--l+92.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.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
Final simplification91.1%
(FPCore (x y) :precision binary64 (if (or (<= (- 1.0 y) -20000000000.0) (not (<= (- 1.0 y) 1.0000002))) (* (+ x -1.0) y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -20000000000.0) || !((1.0 - y) <= 1.0000002)) {
tmp = (x + -1.0) * 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 (((1.0d0 - y) <= (-20000000000.0d0)) .or. (.not. ((1.0d0 - y) <= 1.0000002d0))) then
tmp = (x + (-1.0d0)) * y
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -20000000000.0) || !((1.0 - y) <= 1.0000002)) {
tmp = (x + -1.0) * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - y) <= -20000000000.0) or not ((1.0 - y) <= 1.0000002): tmp = (x + -1.0) * y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - y) <= -20000000000.0) || !(Float64(1.0 - y) <= 1.0000002)) tmp = Float64(Float64(x + -1.0) * y); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - y) <= -20000000000.0) || ~(((1.0 - y) <= 1.0000002))) tmp = (x + -1.0) * y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - y), $MachinePrecision], -20000000000.0], N[Not[LessEqual[N[(1.0 - y), $MachinePrecision], 1.0000002]], $MachinePrecision]], N[(N[(x + -1.0), $MachinePrecision] * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -20000000000 \lor \neg \left(1 - y \leq 1.0000002\right):\\
\;\;\;\;\left(x + -1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if (-.f64 1 y) < -2e10 or 1.00000019999999989 < (-.f64 1 y) Initial program 99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
sub-neg99.8%
+-commutative99.8%
distribute-rgt-in99.8%
*-lft-identity99.8%
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 y around inf 99.7%
if -2e10 < (-.f64 1 y) < 1.00000019999999989Initial program 55.4%
+-commutative55.4%
remove-double-neg55.4%
unsub-neg55.4%
sub-neg55.4%
+-commutative55.4%
distribute-rgt-in55.4%
*-lft-identity55.4%
associate--l+76.2%
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 77.0%
mul-1-neg77.0%
unsub-neg77.0%
Simplified77.0%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (or (<= y -3.3e-8) (not (<= y 1.65e-5))) (* x y) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -3.3e-8) || !(y <= 1.65e-5)) {
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 <= (-3.3d-8)) .or. (.not. (y <= 1.65d-5))) 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 <= -3.3e-8) || !(y <= 1.65e-5)) {
tmp = x * y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.3e-8) or not (y <= 1.65e-5): tmp = x * y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.3e-8) || !(y <= 1.65e-5)) tmp = Float64(x * y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.3e-8) || ~((y <= 1.65e-5))) tmp = x * y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.3e-8], N[Not[LessEqual[y, 1.65e-5]], $MachinePrecision]], N[(x * y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-8} \lor \neg \left(y \leq 1.65 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.29999999999999977e-8 or 1.6500000000000001e-5 < y Initial program 99.7%
+-commutative99.7%
remove-double-neg99.7%
unsub-neg99.7%
sub-neg99.7%
+-commutative99.7%
distribute-rgt-in99.7%
*-lft-identity99.7%
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 inf 51.5%
*-commutative51.5%
Simplified51.5%
if -3.29999999999999977e-8 < y < 1.6500000000000001e-5Initial program 53.7%
+-commutative53.7%
remove-double-neg53.7%
unsub-neg53.7%
sub-neg53.7%
+-commutative53.7%
distribute-rgt-in53.7%
*-lft-identity53.7%
associate--l+75.3%
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.0%
Final simplification62.9%
(FPCore (x y) :precision binary64 (+ 1.0 (* (+ x -1.0) y)))
double code(double x, double y) {
return 1.0 + ((x + -1.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((x + (-1.0d0)) * y)
end function
public static double code(double x, double y) {
return 1.0 + ((x + -1.0) * y);
}
def code(x, y): return 1.0 + ((x + -1.0) * y)
function code(x, y) return Float64(1.0 + Float64(Float64(x + -1.0) * y)) end
function tmp = code(x, y) tmp = 1.0 + ((x + -1.0) * y); end
code[x_, y_] := N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(x + -1\right) \cdot y
\end{array}
Initial program 78.3%
+-commutative78.3%
remove-double-neg78.3%
unsub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-rgt-in78.3%
*-lft-identity78.3%
associate--l+88.5%
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%
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 78.3%
+-commutative78.3%
remove-double-neg78.3%
unsub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-rgt-in78.3%
*-lft-identity78.3%
associate--l+88.5%
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 36.9%
Final simplification36.9%
(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 2024055
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))