
(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 74.2%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
cancel-sign-sub-invN/A
associate--r+N/A
*-rgt-identityN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
distribute-lft-inN/A
sub-negN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- x 1.0) y))) (if (<= y -7e-34) t_0 (if (<= y 3.2e-89) 1.0 t_0))))
double code(double x, double y) {
double t_0 = (x - 1.0) * y;
double tmp;
if (y <= -7e-34) {
tmp = t_0;
} else if (y <= 3.2e-89) {
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 = (x - 1.0d0) * y
if (y <= (-7d-34)) then
tmp = t_0
else if (y <= 3.2d-89) 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 = (x - 1.0) * y;
double tmp;
if (y <= -7e-34) {
tmp = t_0;
} else if (y <= 3.2e-89) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x - 1.0) * y tmp = 0 if y <= -7e-34: tmp = t_0 elif y <= 3.2e-89: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x - 1.0) * y) tmp = 0.0 if (y <= -7e-34) tmp = t_0; elseif (y <= 3.2e-89) tmp = 1.0; 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 <= -7e-34) tmp = t_0; elseif (y <= 3.2e-89) tmp = 1.0; 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, -7e-34], t$95$0, If[LessEqual[y, 3.2e-89], 1.0, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 1\right) \cdot y\\
\mathbf{if}\;y \leq -7 \cdot 10^{-34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-89}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7e-34 or 3.19999999999999998e-89 < y Initial program 94.1%
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--.f6490.5
Applied rewrites90.5%
if -7e-34 < y < 3.19999999999999998e-89Initial program 54.9%
Taylor expanded in y around 0
Applied rewrites80.3%
(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 2024230
(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))))