
(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 4 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 (- (+ 1.0 (* y x)) y))
double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (y * x)) - y
end function
public static double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
def code(x, y): return (1.0 + (y * x)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(y * x)) - y) end
function tmp = code(x, y) tmp = (1.0 + (y * x)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + y \cdot x\right) - y
\end{array}
Initial program 78.8%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -5e+52) (* y x) (if (<= x 6.8e+76) 1.0 (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -5e+52) {
tmp = y * x;
} else if (x <= 6.8e+76) {
tmp = 1.0;
} 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 <= (-5d+52)) then
tmp = y * x
else if (x <= 6.8d+76) then
tmp = 1.0d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5e+52) {
tmp = y * x;
} else if (x <= 6.8e+76) {
tmp = 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+52: tmp = y * x elif x <= 6.8e+76: tmp = 1.0 else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+52) tmp = Float64(y * x); elseif (x <= 6.8e+76) tmp = 1.0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e+52) tmp = y * x; elseif (x <= 6.8e+76) tmp = 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+52], N[(y * x), $MachinePrecision], If[LessEqual[x, 6.8e+76], 1.0, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+52}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{+76}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5e52 or 6.7999999999999994e76 < x Initial program 52.6%
Taylor expanded in x around inf 52.6%
mul-1-neg52.6%
unsub-neg52.6%
associate--r-83.7%
metadata-eval83.7%
+-lft-identity83.7%
Simplified83.7%
if -5e52 < x < 6.7999999999999994e76Initial program 94.0%
Taylor expanded in y around 0 58.7%
Final simplification67.9%
(FPCore (x y) :precision binary64 (if (<= x -3e+59) (* y x) (if (<= x 2.2e+77) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -3e+59) {
tmp = y * x;
} else if (x <= 2.2e+77) {
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 <= (-3d+59)) then
tmp = y * x
else if (x <= 2.2d+77) 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 <= -3e+59) {
tmp = y * x;
} else if (x <= 2.2e+77) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3e+59: tmp = y * x elif x <= 2.2e+77: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -3e+59) tmp = Float64(y * x); elseif (x <= 2.2e+77) 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 <= -3e+59) tmp = y * x; elseif (x <= 2.2e+77) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3e+59], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.2e+77], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+59}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+77}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3e59 or 2.2e77 < x Initial program 52.6%
Taylor expanded in x around inf 52.6%
mul-1-neg52.6%
unsub-neg52.6%
associate--r-83.7%
metadata-eval83.7%
+-lft-identity83.7%
Simplified83.7%
if -3e59 < x < 2.2e77Initial program 94.0%
Taylor expanded in x around 0 95.8%
Final simplification91.3%
(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 78.8%
Taylor expanded in y around 0 44.0%
Final simplification44.0%
(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 2023199
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))