
(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 7 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 y x 1.0) y))
double code(double x, double y) {
return fma(y, x, 1.0) - y;
}
function code(x, y) return Float64(fma(y, x, 1.0) - y) end
code[x_, y_] := N[(N[(y * x + 1.0), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, 1\right) - y
\end{array}
Initial program 81.0%
Taylor expanded in x around 0
--lowering--.f64N/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= y -8.8e-62) (fma y x (- y)) (if (<= y 4.4e-16) 1.0 (- (* y x) y))))
double code(double x, double y) {
double tmp;
if (y <= -8.8e-62) {
tmp = fma(y, x, -y);
} else if (y <= 4.4e-16) {
tmp = 1.0;
} else {
tmp = (y * x) - y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -8.8e-62) tmp = fma(y, x, Float64(-y)); elseif (y <= 4.4e-16) tmp = 1.0; else tmp = Float64(Float64(y * x) - y); end return tmp end
code[x_, y_] := If[LessEqual[y, -8.8e-62], N[(y * x + (-y)), $MachinePrecision], If[LessEqual[y, 4.4e-16], 1.0, N[(N[(y * x), $MachinePrecision] - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-62}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -y\right)\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x - y\\
\end{array}
\end{array}
if y < -8.80000000000000069e-62Initial program 93.4%
Taylor expanded in y around inf
associate-*r*N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
--lowering--.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
remove-double-negN/A
*-lowering-*.f6495.6
Simplified95.6%
sub-negN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f6495.6
Applied egg-rr95.6%
if -8.80000000000000069e-62 < y < 4.40000000000000001e-16Initial program 61.9%
Taylor expanded in y around 0
Simplified85.3%
if 4.40000000000000001e-16 < y Initial program 98.5%
Taylor expanded in y around inf
associate-*r*N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
--lowering--.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
remove-double-negN/A
*-lowering-*.f6499.8
Simplified99.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) y))) (if (<= y -5.8e-62) t_0 (if (<= y 1e-13) 1.0 t_0))))
double code(double x, double y) {
double t_0 = (y * x) - y;
double tmp;
if (y <= -5.8e-62) {
tmp = t_0;
} else if (y <= 1e-13) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (y * x) - y
if (y <= (-5.8d-62)) then
tmp = t_0
else if (y <= 1d-13) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * x) - y;
double tmp;
if (y <= -5.8e-62) {
tmp = t_0;
} else if (y <= 1e-13) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y * x) - y tmp = 0 if y <= -5.8e-62: tmp = t_0 elif y <= 1e-13: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(y * x) - y) tmp = 0.0 if (y <= -5.8e-62) tmp = t_0; elseif (y <= 1e-13) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (y * x) - y; tmp = 0.0; if (y <= -5.8e-62) tmp = t_0; elseif (y <= 1e-13) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[y, -5.8e-62], t$95$0, If[LessEqual[y, 1e-13], 1.0, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - y\\
\mathbf{if}\;y \leq -5.8 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 10^{-13}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.79999999999999971e-62 or 1e-13 < y Initial program 95.9%
Taylor expanded in y around inf
associate-*r*N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
cancel-sign-sub-invN/A
*-rgt-identityN/A
--lowering--.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
remove-double-negN/A
*-lowering-*.f6497.6
Simplified97.6%
if -5.79999999999999971e-62 < y < 1e-13Initial program 61.9%
Taylor expanded in y around 0
Simplified85.3%
(FPCore (x y) :precision binary64 (if (<= x -56000000.0) (* y x) (if (<= x 9.4e+61) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -56000000.0) {
tmp = y * x;
} else if (x <= 9.4e+61) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-56000000.0d0)) then
tmp = y * x
else if (x <= 9.4d+61) then
tmp = 1.0d0 - y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -56000000.0) {
tmp = y * x;
} else if (x <= 9.4e+61) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -56000000.0: tmp = y * x elif x <= 9.4e+61: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -56000000.0) tmp = Float64(y * x); elseif (x <= 9.4e+61) tmp = Float64(1.0 - y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -56000000.0) tmp = y * x; elseif (x <= 9.4e+61) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -56000000.0], N[(y * x), $MachinePrecision], If[LessEqual[x, 9.4e+61], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -56000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 9.4 \cdot 10^{+61}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.6e7 or 9.3999999999999997e61 < x Initial program 62.9%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
*-lowering-*.f6480.0
Simplified80.0%
if -5.6e7 < x < 9.3999999999999997e61Initial program 96.5%
Taylor expanded in x around 0
--lowering--.f6496.2
Simplified96.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 0.00085) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 0.00085) {
tmp = 1.0;
} else {
tmp = -y;
}
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)) then
tmp = -y
else if (y <= 0.00085d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 0.00085) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 0.00085: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 0.00085) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 0.00085) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 0.00085], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 0.00085:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 8.49999999999999953e-4 < y Initial program 99.9%
Taylor expanded in x around 0
--lowering--.f6445.9
Simplified45.9%
Taylor expanded in y around inf
mul-1-negN/A
neg-lowering-neg.f6444.8
Simplified44.8%
if -1 < y < 8.49999999999999953e-4Initial program 59.9%
Taylor expanded in y around 0
Simplified80.4%
(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 81.0%
Taylor expanded in x around 0
--lowering--.f6462.4
Simplified62.4%
(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 81.0%
Taylor expanded in y around 0
Simplified39.4%
(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 2024199
(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))))