
(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 (- 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 77.2%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= y -2e+15) (* (- x 1.0) y) (if (<= y 1.45e-46) (- 1.0 y) (fma y x (- y)))))
double code(double x, double y) {
double tmp;
if (y <= -2e+15) {
tmp = (x - 1.0) * y;
} else if (y <= 1.45e-46) {
tmp = 1.0 - y;
} else {
tmp = fma(y, x, -y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2e+15) tmp = Float64(Float64(x - 1.0) * y); elseif (y <= 1.45e-46) tmp = Float64(1.0 - y); else tmp = fma(y, x, Float64(-y)); end return tmp end
code[x_, y_] := If[LessEqual[y, -2e+15], N[(N[(x - 1.0), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 1.45e-46], N[(1.0 - y), $MachinePrecision], N[(y * x + (-y)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+15}:\\
\;\;\;\;\left(x - 1\right) \cdot y\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-46}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -y\right)\\
\end{array}
\end{array}
if y < -2e15Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
if -2e15 < y < 1.45000000000000002e-46Initial program 56.2%
Taylor expanded in x around 0
lower--.f6477.5
Applied rewrites77.5%
if 1.45000000000000002e-46 < y Initial program 92.9%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6495.2
Applied rewrites95.2%
Applied rewrites95.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- x 1.0) y))) (if (<= y -2e+15) t_0 (if (<= y 1.45e-46) (- 1.0 y) t_0))))
double code(double x, double y) {
double t_0 = (x - 1.0) * y;
double tmp;
if (y <= -2e+15) {
tmp = t_0;
} else if (y <= 1.45e-46) {
tmp = 1.0 - y;
} 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 = (x - 1.0d0) * y
if (y <= (-2d+15)) then
tmp = t_0
else if (y <= 1.45d-46) then
tmp = 1.0d0 - y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - 1.0) * y;
double tmp;
if (y <= -2e+15) {
tmp = t_0;
} else if (y <= 1.45e-46) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x - 1.0) * y tmp = 0 if y <= -2e+15: tmp = t_0 elif y <= 1.45e-46: tmp = 1.0 - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x - 1.0) * y) tmp = 0.0 if (y <= -2e+15) tmp = t_0; elseif (y <= 1.45e-46) tmp = Float64(1.0 - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - 1.0) * y; tmp = 0.0; if (y <= -2e+15) tmp = t_0; elseif (y <= 1.45e-46) tmp = 1.0 - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - 1.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2e+15], t$95$0, If[LessEqual[y, 1.45e-46], N[(1.0 - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 1\right) \cdot y\\
\mathbf{if}\;y \leq -2 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-46}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2e15 or 1.45000000000000002e-46 < y Initial program 96.2%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6497.4
Applied rewrites97.4%
if -2e15 < y < 1.45000000000000002e-46Initial program 56.2%
Taylor expanded in x around 0
lower--.f6477.5
Applied rewrites77.5%
(FPCore (x y) :precision binary64 (if (<= (- 1.0 y) -20000000.0) (- y) (if (<= (- 1.0 y) 2.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if ((1.0 - y) <= -20000000.0) {
tmp = -y;
} else if ((1.0 - y) <= 2.0) {
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 ((1.0d0 - y) <= (-20000000.0d0)) then
tmp = -y
else if ((1.0d0 - y) <= 2.0d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((1.0 - y) <= -20000000.0) {
tmp = -y;
} else if ((1.0 - y) <= 2.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - y) <= -20000000.0: tmp = -y elif (1.0 - y) <= 2.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - y) <= -20000000.0) tmp = Float64(-y); elseif (Float64(1.0 - y) <= 2.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((1.0 - y) <= -20000000.0) tmp = -y; elseif ((1.0 - y) <= 2.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - y), $MachinePrecision], -20000000.0], (-y), If[LessEqual[N[(1.0 - y), $MachinePrecision], 2.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -20000000:\\
\;\;\;\;-y\\
\mathbf{elif}\;1 - y \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -2e7 or 2 < (-.f64 #s(literal 1 binary64) y) Initial program 100.0%
Taylor expanded in x around 0
lower--.f6442.0
Applied rewrites42.0%
Taylor expanded in y around inf
Applied rewrites41.3%
if -2e7 < (-.f64 #s(literal 1 binary64) y) < 2Initial program 54.7%
Taylor expanded in y around 0
Applied rewrites73.8%
(FPCore (x y) :precision binary64 (if (<= x -1.4e+25) (* y x) (if (<= x 5.2e+65) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -1.4e+25) {
tmp = y * x;
} else if (x <= 5.2e+65) {
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 <= (-1.4d+25)) then
tmp = y * x
else if (x <= 5.2d+65) 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 <= -1.4e+25) {
tmp = y * x;
} else if (x <= 5.2e+65) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e+25: tmp = y * x elif x <= 5.2e+65: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e+25) tmp = Float64(y * x); elseif (x <= 5.2e+65) 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 <= -1.4e+25) tmp = y * x; elseif (x <= 5.2e+65) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e+25], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.2e+65], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+25}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+65}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.4000000000000001e25 or 5.20000000000000005e65 < x Initial program 58.4%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
remove-double-negN/A
lower-*.f6482.1
Applied rewrites82.1%
if -1.4000000000000001e25 < x < 5.20000000000000005e65Initial program 92.9%
Taylor expanded in x around 0
lower--.f6492.3
Applied rewrites92.3%
Final simplification87.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.2%
Taylor expanded in x around 0
lower--.f6458.2
Applied rewrites58.2%
(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.2%
Taylor expanded in y around 0
Applied rewrites38.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 2024270
(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))))