
(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 (- (+ 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 77.2%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.05e-41) (* y x) (if (<= y 1.0) 1.0 (if (<= y 8e+179) (- y) (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -2.05e-41) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = 1.0;
} else if (y <= 8e+179) {
tmp = -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 (y <= (-2.05d-41)) then
tmp = y * x
else if (y <= 1.0d0) then
tmp = 1.0d0
else if (y <= 8d+179) then
tmp = -y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.05e-41) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = 1.0;
} else if (y <= 8e+179) {
tmp = -y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.05e-41: tmp = y * x elif y <= 1.0: tmp = 1.0 elif y <= 8e+179: tmp = -y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -2.05e-41) tmp = Float64(y * x); elseif (y <= 1.0) tmp = 1.0; elseif (y <= 8e+179) tmp = Float64(-y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.05e-41) tmp = y * x; elseif (y <= 1.0) tmp = 1.0; elseif (y <= 8e+179) tmp = -y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.05e-41], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], 1.0, If[LessEqual[y, 8e+179], (-y), N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{-41}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+179}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.05000000000000007e-41 or 7.99999999999999984e179 < y Initial program 94.7%
Taylor expanded in x around inf 59.4%
mul-1-neg59.4%
unsub-neg59.4%
sub-neg59.4%
associate--r+64.6%
metadata-eval64.6%
neg-sub064.6%
remove-double-neg64.6%
Simplified64.6%
if -2.05000000000000007e-41 < y < 1Initial program 60.0%
Taylor expanded in y around 0 81.8%
if 1 < y < 7.99999999999999984e179Initial program 100.0%
Taylor expanded in y around inf 97.0%
mul-1-neg97.0%
distribute-rgt-neg-in97.0%
sub-neg97.0%
distribute-neg-in97.0%
metadata-eval97.0%
remove-double-neg97.0%
Simplified97.0%
Taylor expanded in x around 0 73.5%
neg-mul-173.5%
Simplified73.5%
Final simplification74.2%
(FPCore (x y) :precision binary64 (if (or (<= y -4.4e-42) (not (<= y 1.62e-68))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -4.4e-42) || !(y <= 1.62e-68)) {
tmp = y * (x + -1.0);
} 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 ((y <= (-4.4d-42)) .or. (.not. (y <= 1.62d-68))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.4e-42) || !(y <= 1.62e-68)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.4e-42) or not (y <= 1.62e-68): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.4e-42) || !(y <= 1.62e-68)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.4e-42) || ~((y <= 1.62e-68))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.4e-42], N[Not[LessEqual[y, 1.62e-68]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-42} \lor \neg \left(y \leq 1.62 \cdot 10^{-68}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -4.4000000000000001e-42 or 1.62000000000000005e-68 < y Initial program 92.7%
Taylor expanded in y around inf 93.9%
mul-1-neg93.9%
distribute-rgt-neg-in93.9%
sub-neg93.9%
distribute-neg-in93.9%
metadata-eval93.9%
remove-double-neg93.9%
Simplified93.9%
if -4.4000000000000001e-42 < y < 1.62000000000000005e-68Initial program 60.5%
Taylor expanded in x around 0 84.9%
Final simplification89.6%
(FPCore (x y) :precision binary64 (if (<= y -1.25e-40) (- (* y x) y) (if (<= y 7.5e-69) (- 1.0 y) (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.25e-40) {
tmp = (y * x) - y;
} else if (y <= 7.5e-69) {
tmp = 1.0 - y;
} else {
tmp = y * (x + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.25d-40)) then
tmp = (y * x) - y
else if (y <= 7.5d-69) then
tmp = 1.0d0 - y
else
tmp = y * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.25e-40) {
tmp = (y * x) - y;
} else if (y <= 7.5e-69) {
tmp = 1.0 - y;
} else {
tmp = y * (x + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.25e-40: tmp = (y * x) - y elif y <= 7.5e-69: tmp = 1.0 - y else: tmp = y * (x + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.25e-40) tmp = Float64(Float64(y * x) - y); elseif (y <= 7.5e-69) tmp = Float64(1.0 - y); else tmp = Float64(y * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.25e-40) tmp = (y * x) - y; elseif (y <= 7.5e-69) tmp = 1.0 - y; else tmp = y * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.25e-40], N[(N[(y * x), $MachinePrecision] - y), $MachinePrecision], If[LessEqual[y, 7.5e-69], N[(1.0 - y), $MachinePrecision], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-40}:\\
\;\;\;\;y \cdot x - y\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-69}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -1.24999999999999991e-40Initial program 91.6%
Taylor expanded in y around inf 94.8%
mul-1-neg94.8%
distribute-rgt-neg-in94.8%
sub-neg94.8%
distribute-neg-in94.8%
metadata-eval94.8%
remove-double-neg94.8%
Simplified94.8%
+-commutative94.8%
distribute-lft-in94.8%
*-commutative94.8%
mul-1-neg94.8%
Applied egg-rr94.8%
Taylor expanded in y around 0 94.8%
distribute-lft-out--94.8%
*-rgt-identity94.8%
Simplified94.8%
if -1.24999999999999991e-40 < y < 7.5e-69Initial program 60.5%
Taylor expanded in x around 0 84.9%
if 7.5e-69 < y Initial program 93.7%
Taylor expanded in y around inf 93.0%
mul-1-neg93.0%
distribute-rgt-neg-in93.0%
sub-neg93.0%
distribute-neg-in93.0%
metadata-eval93.0%
remove-double-neg93.0%
Simplified93.0%
Final simplification89.6%
(FPCore (x y) :precision binary64 (if (<= x -9e+45) (* y x) (if (<= x 4.8e+22) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -9e+45) {
tmp = y * x;
} else if (x <= 4.8e+22) {
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 <= (-9d+45)) then
tmp = y * x
else if (x <= 4.8d+22) 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 <= -9e+45) {
tmp = y * x;
} else if (x <= 4.8e+22) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9e+45: tmp = y * x elif x <= 4.8e+22: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -9e+45) tmp = Float64(y * x); elseif (x <= 4.8e+22) 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 <= -9e+45) tmp = y * x; elseif (x <= 4.8e+22) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9e+45], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.8e+22], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+45}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+22}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -8.9999999999999997e45 or 4.8e22 < x Initial program 55.6%
Taylor expanded in x around inf 55.7%
mul-1-neg55.7%
unsub-neg55.7%
sub-neg55.7%
associate--r+77.4%
metadata-eval77.4%
neg-sub077.4%
remove-double-neg77.4%
Simplified77.4%
if -8.9999999999999997e45 < x < 4.8e22Initial program 95.1%
Taylor expanded in x around 0 95.5%
Final simplification87.3%
(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 98.8%
mul-1-neg98.8%
distribute-rgt-neg-in98.8%
sub-neg98.8%
distribute-neg-in98.8%
metadata-eval98.8%
remove-double-neg98.8%
Simplified98.8%
Taylor expanded in x around 0 43.3%
neg-mul-143.3%
Simplified43.3%
if -1 < y < 1Initial program 58.9%
Taylor expanded in y around 0 77.4%
Final simplification62.2%
(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 77.2%
Taylor expanded in y around 0 44.1%
Final simplification44.1%
(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 2023238
(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))))