
(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 (* (- 1.0 x) (- 1.0 y)))) (if (<= y -9.8e-107) t_0 (if (<= y 4.8e-46) (- 1.0 y) (+ x t_0)))))
double code(double x, double y) {
double t_0 = (1.0 - x) * (1.0 - y);
double tmp;
if (y <= -9.8e-107) {
tmp = t_0;
} else if (y <= 4.8e-46) {
tmp = 1.0 - y;
} else {
tmp = x + 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 <= (-9.8d-107)) then
tmp = t_0
else if (y <= 4.8d-46) then
tmp = 1.0d0 - y
else
tmp = x + 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 <= -9.8e-107) {
tmp = t_0;
} else if (y <= 4.8e-46) {
tmp = 1.0 - y;
} else {
tmp = x + t_0;
}
return tmp;
}
def code(x, y): t_0 = (1.0 - x) * (1.0 - y) tmp = 0 if y <= -9.8e-107: tmp = t_0 elif y <= 4.8e-46: tmp = 1.0 - y else: tmp = x + t_0 return tmp
function code(x, y) t_0 = Float64(Float64(1.0 - x) * Float64(1.0 - y)) tmp = 0.0 if (y <= -9.8e-107) tmp = t_0; elseif (y <= 4.8e-46) tmp = Float64(1.0 - y); else tmp = Float64(x + 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 <= -9.8e-107) tmp = t_0; elseif (y <= 4.8e-46) tmp = 1.0 - y; else tmp = x + 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, -9.8e-107], t$95$0, If[LessEqual[y, 4.8e-46], N[(1.0 - y), $MachinePrecision], N[(x + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot \left(1 - y\right)\\
\mathbf{if}\;y \leq -9.8 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-46}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x + t\_0\\
\end{array}
\end{array}
if y < -9.79999999999999959e-107Initial program 90.9%
Taylor expanded in x around 0
Applied rewrites91.3%
if -9.79999999999999959e-107 < y < 4.80000000000000027e-46Initial program 53.0%
Taylor expanded in x around 0
Applied rewrites51.2%
Taylor expanded in x around inf
Applied rewrites78.9%
if 4.80000000000000027e-46 < y Initial program 98.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- 1.0 x) (- 1.0 y)))) (if (<= y -9.8e-107) t_0 (if (<= y 1.0) (- 1.0 y) t_0))))
double code(double x, double y) {
double t_0 = (1.0 - x) * (1.0 - y);
double tmp;
if (y <= -9.8e-107) {
tmp = t_0;
} else if (y <= 1.0) {
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 <= (-9.8d-107)) then
tmp = t_0
else if (y <= 1.0d0) 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 <= -9.8e-107) {
tmp = t_0;
} else if (y <= 1.0) {
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 <= -9.8e-107: tmp = t_0 elif y <= 1.0: 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 <= -9.8e-107) tmp = t_0; elseif (y <= 1.0) 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 <= -9.8e-107) tmp = t_0; elseif (y <= 1.0) 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, -9.8e-107], t$95$0, If[LessEqual[y, 1.0], 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 -9.8 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.79999999999999959e-107 or 1 < y Initial program 95.5%
Taylor expanded in x around 0
Applied rewrites95.1%
if -9.79999999999999959e-107 < y < 1Initial program 55.7%
Taylor expanded in x around 0
Applied rewrites52.5%
Taylor expanded in x around inf
Applied rewrites77.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 79.3%
Taylor expanded in x around 0
Applied rewrites77.8%
Taylor expanded in x around inf
Applied rewrites61.7%
(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 2024321
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- (* y x) (- y 1)))
(+ x (* (- 1.0 x) (- 1.0 y))))