
(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 8 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 (+ x -1.0) y 1.0))
double code(double x, double y) {
return fma((x + -1.0), y, 1.0);
}
function code(x, y) return fma(Float64(x + -1.0), y, 1.0) end
code[x_, y_] := N[(N[(x + -1.0), $MachinePrecision] * y + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + -1, y, 1\right)
\end{array}
Initial program 77.1%
Simplified0
Applied egg-rr0
(FPCore (x y)
:precision binary64
(if (<= y -1.02e+290)
(- y)
(if (<= y -1.22e+195)
(* y x)
(if (<= y -8000.0)
(- y)
(if (<= y -3.45e-93)
1.0
(if (<= y -5.2e-147) (* y x) (if (<= y 2.9e-31) 1.0 (* y x))))))))
double code(double x, double y) {
double tmp;
if (y <= -1.02e+290) {
tmp = -y;
} else if (y <= -1.22e+195) {
tmp = y * x;
} else if (y <= -8000.0) {
tmp = -y;
} else if (y <= -3.45e-93) {
tmp = 1.0;
} else if (y <= -5.2e-147) {
tmp = y * x;
} else if (y <= 2.9e-31) {
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 <= (-1.02d+290)) then
tmp = -y
else if (y <= (-1.22d+195)) then
tmp = y * x
else if (y <= (-8000.0d0)) then
tmp = -y
else if (y <= (-3.45d-93)) then
tmp = 1.0d0
else if (y <= (-5.2d-147)) then
tmp = y * x
else if (y <= 2.9d-31) 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 <= -1.02e+290) {
tmp = -y;
} else if (y <= -1.22e+195) {
tmp = y * x;
} else if (y <= -8000.0) {
tmp = -y;
} else if (y <= -3.45e-93) {
tmp = 1.0;
} else if (y <= -5.2e-147) {
tmp = y * x;
} else if (y <= 2.9e-31) {
tmp = 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.02e+290: tmp = -y elif y <= -1.22e+195: tmp = y * x elif y <= -8000.0: tmp = -y elif y <= -3.45e-93: tmp = 1.0 elif y <= -5.2e-147: tmp = y * x elif y <= 2.9e-31: tmp = 1.0 else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.02e+290) tmp = Float64(-y); elseif (y <= -1.22e+195) tmp = Float64(y * x); elseif (y <= -8000.0) tmp = Float64(-y); elseif (y <= -3.45e-93) tmp = 1.0; elseif (y <= -5.2e-147) tmp = Float64(y * x); elseif (y <= 2.9e-31) tmp = 1.0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.02e+290) tmp = -y; elseif (y <= -1.22e+195) tmp = y * x; elseif (y <= -8000.0) tmp = -y; elseif (y <= -3.45e-93) tmp = 1.0; elseif (y <= -5.2e-147) tmp = y * x; elseif (y <= 2.9e-31) tmp = 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.02e+290], (-y), If[LessEqual[y, -1.22e+195], N[(y * x), $MachinePrecision], If[LessEqual[y, -8000.0], (-y), If[LessEqual[y, -3.45e-93], 1.0, If[LessEqual[y, -5.2e-147], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.9e-31], 1.0, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+290}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -1.22 \cdot 10^{+195}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -8000:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -3.45 \cdot 10^{-93}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.2 \cdot 10^{-147}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-31}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.02e290 or -1.2200000000000001e195 < y < -8e3Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
Taylor expanded in y around inf 0
Simplified0
Applied egg-rr0
if -1.02e290 < y < -1.2200000000000001e195 or -3.45000000000000015e-93 < y < -5.1999999999999997e-147 or 2.9000000000000001e-31 < y Initial program 86.1%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -8e3 < y < -3.45000000000000015e-93 or -5.1999999999999997e-147 < y < 2.9000000000000001e-31Initial program 62.1%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y) :precision binary64 (let* ((t_0 (+ 1.0 (* y x)))) (if (<= x -1.0) t_0 (if (<= x 5.6e-25) (- 1.0 y) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + (y * x);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 5.6e-25) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
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 = 1.0d0 + (y * x)
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 5.6d-25) then
tmp = 1.0d0 - y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (y * x);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 5.6e-25) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (y * x) tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 5.6e-25: tmp = 1.0 - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(y * x)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 5.6e-25) tmp = Float64(1.0 - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (y * x); tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 5.6e-25) tmp = 1.0 - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 5.6e-25], N[(1.0 - y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + y \cdot x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-25}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 5.59999999999999976e-25 < x Initial program 54.3%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -1 < x < 5.59999999999999976e-25Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
(FPCore (x y) :precision binary64 (if (<= x -4.5e+22) (* y x) (if (<= x 4.1e+102) (- 1.0 y) (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -4.5e+22) {
tmp = y * x;
} else if (x <= 4.1e+102) {
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 (x <= (-4.5d+22)) then
tmp = y * x
else if (x <= 4.1d+102) 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 (x <= -4.5e+22) {
tmp = y * x;
} else if (x <= 4.1e+102) {
tmp = 1.0 - y;
} else {
tmp = y * (x + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.5e+22: tmp = y * x elif x <= 4.1e+102: tmp = 1.0 - y else: tmp = y * (x + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -4.5e+22) tmp = Float64(y * x); elseif (x <= 4.1e+102) 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 (x <= -4.5e+22) tmp = y * x; elseif (x <= 4.1e+102) tmp = 1.0 - y; else tmp = y * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.5e+22], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.1e+102], N[(1.0 - y), $MachinePrecision], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+22}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+102}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.4999999999999998e22Initial program 53.1%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -4.4999999999999998e22 < x < 4.1e102Initial program 91.9%
Simplified0
Taylor expanded in x around 0 0
Simplified0
if 4.1e102 < x Initial program 54.2%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (if (<= x -4e+28) (* y x) (if (<= x 3.4e+102) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -4e+28) {
tmp = y * x;
} else if (x <= 3.4e+102) {
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 <= (-4d+28)) then
tmp = y * x
else if (x <= 3.4d+102) 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 <= -4e+28) {
tmp = y * x;
} else if (x <= 3.4e+102) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e+28: tmp = y * x elif x <= 3.4e+102: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4e+28) tmp = Float64(y * x); elseif (x <= 3.4e+102) 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 <= -4e+28) tmp = y * x; elseif (x <= 3.4e+102) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e+28], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.4e+102], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+28}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{+102}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.99999999999999983e28 or 3.4e102 < x Initial program 53.7%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -3.99999999999999983e28 < x < 3.4e102Initial program 91.9%
Simplified0
Taylor expanded in x around 0 0
Simplified0
(FPCore (x y) :precision binary64 (if (<= y -8000.0) (- y) (if (<= y 0.0009) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -8000.0) {
tmp = -y;
} else if (y <= 0.0009) {
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 <= (-8000.0d0)) then
tmp = -y
else if (y <= 0.0009d0) 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 <= -8000.0) {
tmp = -y;
} else if (y <= 0.0009) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8000.0: tmp = -y elif y <= 0.0009: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -8000.0) tmp = Float64(-y); elseif (y <= 0.0009) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8000.0) tmp = -y; elseif (y <= 0.0009) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8000.0], (-y), If[LessEqual[y, 0.0009], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8000:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 0.0009:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -8e3 or 8.9999999999999998e-4 < y Initial program 99.9%
Simplified0
Taylor expanded in x around 0 0
Simplified0
Taylor expanded in y around inf 0
Simplified0
Applied egg-rr0
if -8e3 < y < 8.9999999999999998e-4Initial program 57.1%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y) :precision binary64 (+ 1.0 (* y (+ x -1.0))))
double code(double x, double y) {
return 1.0 + (y * (x + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (y * (x + (-1.0d0)))
end function
public static double code(double x, double y) {
return 1.0 + (y * (x + -1.0));
}
def code(x, y): return 1.0 + (y * (x + -1.0))
function code(x, y) return Float64(1.0 + Float64(y * Float64(x + -1.0))) end
function tmp = code(x, y) tmp = 1.0 + (y * (x + -1.0)); end
code[x_, y_] := N[(1.0 + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + y \cdot \left(x + -1\right)
\end{array}
Initial program 77.1%
Simplified0
(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.1%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(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 2024110
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))