
(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.6%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -3.6e+25) (- y) (if (<= y -1.5e-74) (* y x) (if (<= y 1.9e-13) 1.0 (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -3.6e+25) {
tmp = -y;
} else if (y <= -1.5e-74) {
tmp = y * x;
} else if (y <= 1.9e-13) {
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 (y <= (-3.6d+25)) then
tmp = -y
else if (y <= (-1.5d-74)) then
tmp = y * x
else if (y <= 1.9d-13) 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 (y <= -3.6e+25) {
tmp = -y;
} else if (y <= -1.5e-74) {
tmp = y * x;
} else if (y <= 1.9e-13) {
tmp = 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.6e+25: tmp = -y elif y <= -1.5e-74: tmp = y * x elif y <= 1.9e-13: tmp = 1.0 else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -3.6e+25) tmp = Float64(-y); elseif (y <= -1.5e-74) tmp = Float64(y * x); elseif (y <= 1.9e-13) tmp = 1.0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.6e+25) tmp = -y; elseif (y <= -1.5e-74) tmp = y * x; elseif (y <= 1.9e-13) tmp = 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.6e+25], (-y), If[LessEqual[y, -1.5e-74], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.9e-13], 1.0, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+25}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{-74}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.60000000000000015e25Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
distribute-neg-in100.0%
metadata-eval100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 55.5%
neg-mul-155.5%
Simplified55.5%
if -3.60000000000000015e25 < y < -1.50000000000000003e-74 or 1.9e-13 < y Initial program 91.5%
Taylor expanded in x around inf 46.1%
mul-1-neg46.1%
unsub-neg46.1%
sub-neg46.1%
associate--r+54.3%
metadata-eval54.3%
neg-sub054.3%
remove-double-neg54.3%
Simplified54.3%
if -1.50000000000000003e-74 < y < 1.9e-13Initial program 57.0%
Taylor expanded in y around 0 88.8%
Final simplification70.3%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5e-74) (not (<= y 9.6e-12))) (* y (+ x -1.0)) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -2.5e-74) || !(y <= 9.6e-12)) {
tmp = y * (x + -1.0);
} 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 ((y <= (-2.5d-74)) .or. (.not. (y <= 9.6d-12))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.5e-74) || !(y <= 9.6e-12)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5e-74) or not (y <= 9.6e-12): tmp = y * (x + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5e-74) || !(y <= 9.6e-12)) tmp = Float64(y * Float64(x + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.5e-74) || ~((y <= 9.6e-12))) tmp = y * (x + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.5e-74], N[Not[LessEqual[y, 9.6e-12]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-74} \lor \neg \left(y \leq 9.6 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.49999999999999999e-74 or 9.59999999999999948e-12 < y Initial program 94.9%
Taylor expanded in y around inf 96.0%
mul-1-neg96.0%
distribute-rgt-neg-in96.0%
sub-neg96.0%
distribute-neg-in96.0%
metadata-eval96.0%
remove-double-neg96.0%
Simplified96.0%
if -2.49999999999999999e-74 < y < 9.59999999999999948e-12Initial program 57.0%
Taylor expanded in y around 0 88.8%
Final simplification92.7%
(FPCore (x y) :precision binary64 (if (<= y -6e-75) (* y (+ x -1.0)) (if (<= y 9e-19) 1.0 (- (* y x) y))))
double code(double x, double y) {
double tmp;
if (y <= -6e-75) {
tmp = y * (x + -1.0);
} else if (y <= 9e-19) {
tmp = 1.0;
} else {
tmp = (y * x) - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-6d-75)) then
tmp = y * (x + (-1.0d0))
else if (y <= 9d-19) then
tmp = 1.0d0
else
tmp = (y * x) - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6e-75) {
tmp = y * (x + -1.0);
} else if (y <= 9e-19) {
tmp = 1.0;
} else {
tmp = (y * x) - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e-75: tmp = y * (x + -1.0) elif y <= 9e-19: tmp = 1.0 else: tmp = (y * x) - y return tmp
function code(x, y) tmp = 0.0 if (y <= -6e-75) tmp = Float64(y * Float64(x + -1.0)); elseif (y <= 9e-19) tmp = 1.0; else tmp = Float64(Float64(y * x) - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e-75) tmp = y * (x + -1.0); elseif (y <= 9e-19) tmp = 1.0; else tmp = (y * x) - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e-75], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9e-19], 1.0, N[(N[(y * x), $MachinePrecision] - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-75}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-19}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x - y\\
\end{array}
\end{array}
if y < -5.9999999999999997e-75Initial program 91.7%
Taylor expanded in y around inf 94.3%
mul-1-neg94.3%
distribute-rgt-neg-in94.3%
sub-neg94.3%
distribute-neg-in94.3%
metadata-eval94.3%
remove-double-neg94.3%
Simplified94.3%
if -5.9999999999999997e-75 < y < 9.00000000000000026e-19Initial program 57.0%
Taylor expanded in y around 0 88.8%
if 9.00000000000000026e-19 < y Initial program 98.6%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
distribute-rgt-neg-in98.0%
sub-neg98.0%
distribute-neg-in98.0%
metadata-eval98.0%
remove-double-neg98.0%
Simplified98.0%
Taylor expanded in y around 0 98.0%
distribute-lft-out--98.0%
cancel-sign-sub-inv98.0%
*-rgt-identity98.0%
unsub-neg98.0%
Simplified98.0%
Final simplification92.7%
(FPCore (x y) :precision binary64 (if (<= x -6.6e+113) (* y x) (if (<= x 1100000000000.0) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -6.6e+113) {
tmp = y * x;
} else if (x <= 1100000000000.0) {
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 <= (-6.6d+113)) then
tmp = y * x
else if (x <= 1100000000000.0d0) 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 <= -6.6e+113) {
tmp = y * x;
} else if (x <= 1100000000000.0) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.6e+113: tmp = y * x elif x <= 1100000000000.0: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -6.6e+113) tmp = Float64(y * x); elseif (x <= 1100000000000.0) 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 <= -6.6e+113) tmp = y * x; elseif (x <= 1100000000000.0) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.6e+113], N[(y * x), $MachinePrecision], If[LessEqual[x, 1100000000000.0], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{+113}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1100000000000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6.6000000000000006e113 or 1.1e12 < x Initial program 54.2%
Taylor expanded in x around inf 54.2%
mul-1-neg54.2%
unsub-neg54.2%
sub-neg54.2%
associate--r+73.9%
metadata-eval73.9%
neg-sub073.9%
remove-double-neg73.9%
Simplified73.9%
if -6.6000000000000006e113 < x < 1.1e12Initial program 92.3%
Taylor expanded in x around 0 93.1%
Final simplification85.7%
(FPCore (x y) :precision binary64 (if (<= y -3.3e-26) (- y) (if (<= y 3.3e-8) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -3.3e-26) {
tmp = -y;
} else if (y <= 3.3e-8) {
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 <= (-3.3d-26)) then
tmp = -y
else if (y <= 3.3d-8) 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 <= -3.3e-26) {
tmp = -y;
} else if (y <= 3.3e-8) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.3e-26: tmp = -y elif y <= 3.3e-8: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.3e-26) tmp = Float64(-y); elseif (y <= 3.3e-8) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.3e-26) tmp = -y; elseif (y <= 3.3e-8) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.3e-26], (-y), If[LessEqual[y, 3.3e-8], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-26}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-8}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -3.2999999999999998e-26 or 3.29999999999999977e-8 < y Initial program 98.0%
Taylor expanded in y around inf 98.6%
mul-1-neg98.6%
distribute-rgt-neg-in98.6%
sub-neg98.6%
distribute-neg-in98.6%
metadata-eval98.6%
remove-double-neg98.6%
Simplified98.6%
Taylor expanded in x around 0 50.1%
neg-mul-150.1%
Simplified50.1%
if -3.2999999999999998e-26 < y < 3.29999999999999977e-8Initial program 56.6%
Taylor expanded in y around 0 85.4%
Final simplification67.5%
(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.6%
Taylor expanded in y around 0 43.4%
Final simplification43.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 2023224
(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))))