
(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 5 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 (- (* x y) (+ y -1.0)))
double code(double x, double y) {
return (x * y) - (y + -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) - (y + (-1.0d0))
end function
public static double code(double x, double y) {
return (x * y) - (y + -1.0);
}
def code(x, y): return (x * y) - (y + -1.0)
function code(x, y) return Float64(Float64(x * y) - Float64(y + -1.0)) end
function tmp = code(x, y) tmp = (x * y) - (y + -1.0); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] - N[(y + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y - \left(y + -1\right)
\end{array}
Initial program 75.9%
+-commutative75.9%
sub-neg75.9%
distribute-lft-in75.9%
+-commutative75.9%
*-rgt-identity75.9%
associate-+r-75.9%
associate-+l-100.0%
+-inverses100.0%
--rgt-identity100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
*-commutative100.0%
unsub-neg100.0%
associate-+l-100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.3e+238)
(- y)
(if (<= y -5.8e+125)
(* x y)
(if (<= y -2.75e+82)
(- y)
(if (<= y -3.6e-22) (* x y) (if (<= y 0.0105) 1.0 (- y)))))))
double code(double x, double y) {
double tmp;
if (y <= -4.3e+238) {
tmp = -y;
} else if (y <= -5.8e+125) {
tmp = x * y;
} else if (y <= -2.75e+82) {
tmp = -y;
} else if (y <= -3.6e-22) {
tmp = x * y;
} else if (y <= 0.0105) {
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 <= (-4.3d+238)) then
tmp = -y
else if (y <= (-5.8d+125)) then
tmp = x * y
else if (y <= (-2.75d+82)) then
tmp = -y
else if (y <= (-3.6d-22)) then
tmp = x * y
else if (y <= 0.0105d0) 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 <= -4.3e+238) {
tmp = -y;
} else if (y <= -5.8e+125) {
tmp = x * y;
} else if (y <= -2.75e+82) {
tmp = -y;
} else if (y <= -3.6e-22) {
tmp = x * y;
} else if (y <= 0.0105) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.3e+238: tmp = -y elif y <= -5.8e+125: tmp = x * y elif y <= -2.75e+82: tmp = -y elif y <= -3.6e-22: tmp = x * y elif y <= 0.0105: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.3e+238) tmp = Float64(-y); elseif (y <= -5.8e+125) tmp = Float64(x * y); elseif (y <= -2.75e+82) tmp = Float64(-y); elseif (y <= -3.6e-22) tmp = Float64(x * y); elseif (y <= 0.0105) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.3e+238) tmp = -y; elseif (y <= -5.8e+125) tmp = x * y; elseif (y <= -2.75e+82) tmp = -y; elseif (y <= -3.6e-22) tmp = x * y; elseif (y <= 0.0105) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.3e+238], (-y), If[LessEqual[y, -5.8e+125], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.75e+82], (-y), If[LessEqual[y, -3.6e-22], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.0105], 1.0, (-y)]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{+238}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.75 \cdot 10^{+82}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-22}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -4.29999999999999983e238 or -5.79999999999999986e125 < y < -2.74999999999999998e82 or 0.0105000000000000007 < y Initial program 99.9%
+-commutative99.9%
sub-neg99.9%
distribute-lft-in99.9%
+-commutative99.9%
*-rgt-identity99.9%
associate-+r-99.9%
associate-+l-100.0%
+-inverses100.0%
--rgt-identity100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
*-commutative100.0%
unsub-neg100.0%
associate-+l-100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.1%
Taylor expanded in x around 0 69.2%
mul-1-neg69.2%
Simplified69.2%
if -4.29999999999999983e238 < y < -5.79999999999999986e125 or -2.74999999999999998e82 < y < -3.5999999999999998e-22Initial program 95.8%
Taylor expanded in x around -inf 67.4%
*-commutative67.4%
Simplified67.4%
if -3.5999999999999998e-22 < y < 0.0105000000000000007Initial program 52.3%
Taylor expanded in y around 0 76.4%
Final simplification72.4%
(FPCore (x y) :precision binary64 (if (<= x -5.8e+31) (* x y) (if (<= x 4.4e+89) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -5.8e+31) {
tmp = x * y;
} else if (x <= 4.4e+89) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5.8d+31)) then
tmp = x * y
else if (x <= 4.4d+89) then
tmp = 1.0d0 - y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.8e+31) {
tmp = x * y;
} else if (x <= 4.4e+89) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.8e+31: tmp = x * y elif x <= 4.4e+89: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5.8e+31) tmp = Float64(x * y); elseif (x <= 4.4e+89) tmp = Float64(1.0 - y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.8e+31) tmp = x * y; elseif (x <= 4.4e+89) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.8e+31], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.4e+89], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+31}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{+89}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.8000000000000001e31 or 4.4e89 < x Initial program 50.4%
Taylor expanded in x around -inf 77.9%
*-commutative77.9%
Simplified77.9%
if -5.8000000000000001e31 < x < 4.4e89Initial program 92.5%
Taylor expanded in x around 0 95.2%
Final simplification88.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 0.0105) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 0.0105) {
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 <= 0.0105d0) 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 <= 0.0105) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 0.0105: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 0.0105) 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 <= 0.0105) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 0.0105], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 0.0105000000000000007 < y Initial program 99.9%
+-commutative99.9%
sub-neg99.9%
distribute-lft-in99.9%
+-commutative99.9%
*-rgt-identity99.9%
associate-+r-99.9%
associate-+l-100.0%
+-inverses100.0%
--rgt-identity100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
*-commutative100.0%
unsub-neg100.0%
associate-+l-100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.2%
Taylor expanded in x around 0 56.9%
mul-1-neg56.9%
Simplified56.9%
if -1 < y < 0.0105000000000000007Initial program 51.5%
Taylor expanded in y around 0 75.3%
Final simplification66.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 75.9%
Taylor expanded in y around 0 38.7%
Final simplification38.7%
(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 2023297
(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))))