
(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 3 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 (let* ((t_0 (+ x (* (- 1.0 x) (- 1.0 y))))) (if (<= y -8.6e-46) t_0 (if (<= y 1.56e-24) (- 1.0 y) t_0))))
double code(double x, double y) {
double t_0 = x + ((1.0 - x) * (1.0 - y));
double tmp;
if (y <= -8.6e-46) {
tmp = t_0;
} else if (y <= 1.56e-24) {
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 - x) * (1.0d0 - y))
if (y <= (-8.6d-46)) then
tmp = t_0
else if (y <= 1.56d-24) 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 - x) * (1.0 - y));
double tmp;
if (y <= -8.6e-46) {
tmp = t_0;
} else if (y <= 1.56e-24) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x + ((1.0 - x) * (1.0 - y)) tmp = 0 if y <= -8.6e-46: tmp = t_0 elif y <= 1.56e-24: tmp = 1.0 - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) tmp = 0.0 if (y <= -8.6e-46) tmp = t_0; elseif (y <= 1.56e-24) tmp = Float64(1.0 - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x + ((1.0 - x) * (1.0 - y)); tmp = 0.0; if (y <= -8.6e-46) tmp = t_0; elseif (y <= 1.56e-24) tmp = 1.0 - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.6e-46], t$95$0, If[LessEqual[y, 1.56e-24], N[(1.0 - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \left(1 - x\right) \cdot \left(1 - y\right)\\
\mathbf{if}\;y \leq -8.6 \cdot 10^{-46}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.56 \cdot 10^{-24}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.6000000000000007e-46 or 1.56e-24 < y Initial program 97.1%
if -8.6000000000000007e-46 < y < 1.56e-24Initial program 53.1%
Taylor expanded in x around 0
Applied rewrites50.1%
Taylor expanded in x around inf
Applied rewrites80.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- 1.0 x) (- 1.0 y)))) (if (<= y -4.1e-26) t_0 (if (<= y 0.0015) (- 1.0 y) t_0))))
double code(double x, double y) {
double t_0 = (1.0 - x) * (1.0 - y);
double tmp;
if (y <= -4.1e-26) {
tmp = t_0;
} else if (y <= 0.0015) {
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 = (1.0d0 - x) * (1.0d0 - y)
if (y <= (-4.1d-26)) then
tmp = t_0
else if (y <= 0.0015d0) 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 = (1.0 - x) * (1.0 - y);
double tmp;
if (y <= -4.1e-26) {
tmp = t_0;
} else if (y <= 0.0015) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (1.0 - x) * (1.0 - y) tmp = 0 if y <= -4.1e-26: tmp = t_0 elif y <= 0.0015: tmp = 1.0 - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(1.0 - x) * Float64(1.0 - y)) tmp = 0.0 if (y <= -4.1e-26) tmp = t_0; elseif (y <= 0.0015) tmp = Float64(1.0 - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (1.0 - x) * (1.0 - y); tmp = 0.0; if (y <= -4.1e-26) tmp = t_0; elseif (y <= 0.0015) tmp = 1.0 - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.1e-26], t$95$0, If[LessEqual[y, 0.0015], N[(1.0 - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot \left(1 - y\right)\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0015:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.0999999999999999e-26 or 0.0015 < y Initial program 99.2%
Taylor expanded in x around 0
Applied rewrites97.6%
if -4.0999999999999999e-26 < y < 0.0015Initial program 55.4%
Taylor expanded in x around 0
Applied rewrites51.5%
Taylor expanded in x around inf
Applied rewrites78.9%
(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
Applied rewrites74.4%
Taylor expanded in x around inf
Applied rewrites65.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 2024313
(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))))