
(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.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ x (* (- 1.0 x) (- 1.0 y))))) (if (or (<= t_0 0.0) (not (<= t_0 2.0))) (fma y x (- y)) (- 1.0 y))))
double code(double x, double y) {
double t_0 = x + ((1.0 - x) * (1.0 - y));
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= 2.0)) {
tmp = fma(y, x, -y);
} else {
tmp = 1.0 - y;
}
return tmp;
}
function code(x, y) t_0 = Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) tmp = 0.0 if ((t_0 <= 0.0) || !(t_0 <= 2.0)) tmp = fma(y, x, Float64(-y)); else tmp = Float64(1.0 - y); end return 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[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(y * x + (-y)), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \left(1 - x\right) \cdot \left(1 - y\right)\\
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, -y\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 0.0 or 2 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) Initial program 69.1%
Taylor expanded in x around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
*-commutativeN/A
lower-*.f6453.4
Applied rewrites53.4%
Taylor expanded in y around inf
associate-*r*N/A
distribute-lft-out--N/A
*-rgt-identityN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6484.2
Applied rewrites84.2%
if 0.0 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 2Initial program 100.0%
Taylor expanded in x around 0
lower--.f64100.0
Applied rewrites100.0%
Final simplification87.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ x (* (- 1.0 x) (- 1.0 y))))) (if (or (<= t_0 0.0) (not (<= t_0 2.0))) (* (+ -1.0 x) y) (- 1.0 y))))
double code(double x, double y) {
double t_0 = x + ((1.0 - x) * (1.0 - y));
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= 2.0)) {
tmp = (-1.0 + x) * y;
} else {
tmp = 1.0 - y;
}
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 ((t_0 <= 0.0d0) .or. (.not. (t_0 <= 2.0d0))) then
tmp = ((-1.0d0) + x) * y
else
tmp = 1.0d0 - y
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 ((t_0 <= 0.0) || !(t_0 <= 2.0)) {
tmp = (-1.0 + x) * y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): t_0 = x + ((1.0 - x) * (1.0 - y)) tmp = 0 if (t_0 <= 0.0) or not (t_0 <= 2.0): tmp = (-1.0 + x) * y else: tmp = 1.0 - y return tmp
function code(x, y) t_0 = Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) tmp = 0.0 if ((t_0 <= 0.0) || !(t_0 <= 2.0)) tmp = Float64(Float64(-1.0 + x) * y); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) t_0 = x + ((1.0 - x) * (1.0 - y)); tmp = 0.0; if ((t_0 <= 0.0) || ~((t_0 <= 2.0))) tmp = (-1.0 + x) * y; else tmp = 1.0 - y; 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[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \left(1 - x\right) \cdot \left(1 - y\right)\\
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\left(-1 + x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 0.0 or 2 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) Initial program 69.1%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-neg-inN/A
metadata-evalN/A
mul-1-negN/A
remove-double-negN/A
lower-+.f6484.2
Applied rewrites84.2%
if 0.0 < (+.f64 x (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 1 binary64) y))) < 2Initial program 100.0%
Taylor expanded in x around 0
lower--.f64100.0
Applied rewrites100.0%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (or (<= (- 1.0 y) -10.0) (not (<= (- 1.0 y) 1.1))) (- y) 1.0))
double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -10.0) || !((1.0 - y) <= 1.1)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((1.0d0 - y) <= (-10.0d0)) .or. (.not. ((1.0d0 - y) <= 1.1d0))) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - y) <= -10.0) || !((1.0 - y) <= 1.1)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - y) <= -10.0) or not ((1.0 - y) <= 1.1): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - y) <= -10.0) || !(Float64(1.0 - y) <= 1.1)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - y) <= -10.0) || ~(((1.0 - y) <= 1.1))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - y), $MachinePrecision], -10.0], N[Not[LessEqual[N[(1.0 - y), $MachinePrecision], 1.1]], $MachinePrecision]], (-y), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -10 \lor \neg \left(1 - y \leq 1.1\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -10 or 1.1000000000000001 < (-.f64 #s(literal 1 binary64) y) Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-neg-inN/A
metadata-evalN/A
mul-1-negN/A
remove-double-negN/A
lower-+.f6499.2
Applied rewrites99.2%
Taylor expanded in x around 0
Applied rewrites47.2%
if -10 < (-.f64 #s(literal 1 binary64) y) < 1.1000000000000001Initial program 49.8%
Taylor expanded in x around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
*-commutativeN/A
lower-*.f6429.8
Applied rewrites29.8%
Taylor expanded in y around 0
Applied rewrites70.3%
Final simplification58.2%
(FPCore (x y) :precision binary64 (if (or (<= x -5400000000.0) (not (<= x 51000.0))) (* y x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -5400000000.0) || !(x <= 51000.0)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-5400000000.0d0)) .or. (.not. (x <= 51000.0d0))) then
tmp = y * x
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5400000000.0) || !(x <= 51000.0)) {
tmp = y * x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5400000000.0) or not (x <= 51000.0): tmp = y * x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -5400000000.0) || !(x <= 51000.0)) tmp = Float64(y * x); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5400000000.0) || ~((x <= 51000.0))) tmp = y * x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5400000000.0], N[Not[LessEqual[x, 51000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5400000000 \lor \neg \left(x \leq 51000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -5.4e9 or 51000 < x Initial program 54.6%
Taylor expanded in x around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
*-commutativeN/A
lower-*.f6476.9
Applied rewrites76.9%
if -5.4e9 < x < 51000Initial program 100.0%
Taylor expanded in x around 0
lower--.f6498.4
Applied rewrites98.4%
Final simplification87.1%
(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.0%
Taylor expanded in x around 0
lower--.f6459.0
Applied rewrites59.0%
(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.0%
Taylor expanded in x around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
associate--r-N/A
metadata-evalN/A
+-lft-identityN/A
*-commutativeN/A
lower-*.f6442.2
Applied rewrites42.2%
Taylor expanded in y around 0
Applied rewrites34.9%
(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 2024320
(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))))