
(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 y x (- 1.0 y)))
double code(double x, double y) {
return fma(y, x, (1.0 - y));
}
function code(x, y) return fma(y, x, Float64(1.0 - y)) end
code[x_, y_] := N[(y * x + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, 1 - y\right)
\end{array}
Initial program 76.1%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
mul-1-negN/A
unsub-negN/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
neg-sub0N/A
remove-double-negN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
associate--r+N/A
+-commutativeN/A
associate--r+N/A
sub-negN/A
distribute-lft-neg-outN/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
*-commutativeN/A
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- x (* (+ -1.0 y) (- 1.0 x)))) (t_1 (fma y x (- y)))) (if (<= t_0 0.0) t_1 (if (<= t_0 2000000000000.0) (- 1.0 y) t_1))))
double code(double x, double y) {
double t_0 = x - ((-1.0 + y) * (1.0 - x));
double t_1 = fma(y, x, -y);
double tmp;
if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 2000000000000.0) {
tmp = 1.0 - y;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(x - Float64(Float64(-1.0 + y) * Float64(1.0 - x))) t_1 = fma(y, x, Float64(-y)) tmp = 0.0 if (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 2000000000000.0) tmp = Float64(1.0 - y); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(N[(-1.0 + y), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * x + (-y)), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 2000000000000.0], N[(1.0 - y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \left(-1 + y\right) \cdot \left(1 - x\right)\\
t_1 := \mathsf{fma}\left(y, x, -y\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2000000000000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 0.0 or 2e12 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) Initial program 67.6%
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--.f6484.8
Applied rewrites84.8%
Applied rewrites84.8%
if 0.0 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 2e12Initial program 100.0%
Taylor expanded in x around 0
lower--.f64100.0
Applied rewrites100.0%
Final simplification88.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (- x (* (+ -1.0 y) (- 1.0 x)))) (t_1 (* (- x 1.0) y))) (if (<= t_0 0.0) t_1 (if (<= t_0 2000000000000.0) (- 1.0 y) t_1))))
double code(double x, double y) {
double t_0 = x - ((-1.0 + y) * (1.0 - x));
double t_1 = (x - 1.0) * y;
double tmp;
if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 2000000000000.0) {
tmp = 1.0 - y;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x - (((-1.0d0) + y) * (1.0d0 - x))
t_1 = (x - 1.0d0) * y
if (t_0 <= 0.0d0) then
tmp = t_1
else if (t_0 <= 2000000000000.0d0) then
tmp = 1.0d0 - y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - ((-1.0 + y) * (1.0 - x));
double t_1 = (x - 1.0) * y;
double tmp;
if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 2000000000000.0) {
tmp = 1.0 - y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x - ((-1.0 + y) * (1.0 - x)) t_1 = (x - 1.0) * y tmp = 0 if t_0 <= 0.0: tmp = t_1 elif t_0 <= 2000000000000.0: tmp = 1.0 - y else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x - Float64(Float64(-1.0 + y) * Float64(1.0 - x))) t_1 = Float64(Float64(x - 1.0) * y) tmp = 0.0 if (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 2000000000000.0) tmp = Float64(1.0 - y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x - ((-1.0 + y) * (1.0 - x)); t_1 = (x - 1.0) * y; tmp = 0.0; if (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 2000000000000.0) tmp = 1.0 - y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(N[(-1.0 + y), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - 1.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 2000000000000.0], N[(1.0 - y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \left(-1 + y\right) \cdot \left(1 - x\right)\\
t_1 := \left(x - 1\right) \cdot y\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2000000000000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 0.0 or 2e12 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) Initial program 67.6%
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--.f6484.8
Applied rewrites84.8%
if 0.0 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 2e12Initial program 100.0%
Taylor expanded in x around 0
lower--.f64100.0
Applied rewrites100.0%
Final simplification88.8%
(FPCore (x y) :precision binary64 (if (<= x -4.7e+29) (* y x) (if (<= x 3e+21) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -4.7e+29) {
tmp = y * x;
} else if (x <= 3e+21) {
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 <= (-4.7d+29)) then
tmp = y * x
else if (x <= 3d+21) 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 <= -4.7e+29) {
tmp = y * x;
} else if (x <= 3e+21) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.7e+29: tmp = y * x elif x <= 3e+21: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.7e+29) tmp = Float64(y * x); elseif (x <= 3e+21) 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 <= -4.7e+29) tmp = y * x; elseif (x <= 3e+21) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.7e+29], N[(y * x), $MachinePrecision], If[LessEqual[x, 3e+21], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{+29}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+21}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.7000000000000002e29 or 3e21 < x Initial program 48.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
*-commutativeN/A
lower-*.f6478.7
Applied rewrites78.7%
if -4.7000000000000002e29 < x < 3e21Initial program 97.3%
Taylor expanded in x around 0
lower--.f6495.6
Applied rewrites95.6%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.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 (y <= (-1.0d0)) then
tmp = -y
else if (y <= 1.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 (y <= -1.0) {
tmp = -y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial 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--.f6498.9
Applied rewrites98.9%
Taylor expanded in x around 0
Applied rewrites55.3%
if -1 < y < 1Initial program 53.3%
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
*-commutativeN/A
lower-*.f6430.2
Applied rewrites30.2%
Taylor expanded in y around 0
Applied rewrites70.7%
(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 76.1%
Taylor expanded in x around 0
lower--.f6464.1
Applied rewrites64.1%
(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 76.1%
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
*-commutativeN/A
lower-*.f6437.2
Applied rewrites37.2%
Taylor expanded in y around 0
Applied rewrites37.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 2024298
(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))))