
(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 x y (- 1.0 y)))
double code(double x, double y) {
return fma(x, y, (1.0 - y));
}
function code(x, y) return fma(x, y, Float64(1.0 - y)) end
code[x_, y_] := N[(x * y + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, 1 - y\right)
\end{array}
Initial program 73.6%
sub-neg73.6%
distribute-rgt-in73.6%
*-lft-identity73.6%
associate-+r+86.6%
+-commutative86.6%
sub-neg86.6%
associate-+l+100.0%
neg-mul-1100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-*r*100.0%
neg-mul-1100.0%
mul0-lft100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+r+100.0%
sub-neg100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -5e+270)
(- y)
(if (<= y -2.35e+209)
(* x y)
(if (<= y -1.12e+185)
(- y)
(if (<= y -1.02e-38)
(* x y)
(if (<= y 1.22e-147) 1.0 (if (<= y 1.4e+69) (* x y) (- y))))))))
double code(double x, double y) {
double tmp;
if (y <= -5e+270) {
tmp = -y;
} else if (y <= -2.35e+209) {
tmp = x * y;
} else if (y <= -1.12e+185) {
tmp = -y;
} else if (y <= -1.02e-38) {
tmp = x * y;
} else if (y <= 1.22e-147) {
tmp = 1.0;
} else if (y <= 1.4e+69) {
tmp = x * y;
} 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 <= (-5d+270)) then
tmp = -y
else if (y <= (-2.35d+209)) then
tmp = x * y
else if (y <= (-1.12d+185)) then
tmp = -y
else if (y <= (-1.02d-38)) then
tmp = x * y
else if (y <= 1.22d-147) then
tmp = 1.0d0
else if (y <= 1.4d+69) then
tmp = x * y
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5e+270) {
tmp = -y;
} else if (y <= -2.35e+209) {
tmp = x * y;
} else if (y <= -1.12e+185) {
tmp = -y;
} else if (y <= -1.02e-38) {
tmp = x * y;
} else if (y <= 1.22e-147) {
tmp = 1.0;
} else if (y <= 1.4e+69) {
tmp = x * y;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5e+270: tmp = -y elif y <= -2.35e+209: tmp = x * y elif y <= -1.12e+185: tmp = -y elif y <= -1.02e-38: tmp = x * y elif y <= 1.22e-147: tmp = 1.0 elif y <= 1.4e+69: tmp = x * y else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -5e+270) tmp = Float64(-y); elseif (y <= -2.35e+209) tmp = Float64(x * y); elseif (y <= -1.12e+185) tmp = Float64(-y); elseif (y <= -1.02e-38) tmp = Float64(x * y); elseif (y <= 1.22e-147) tmp = 1.0; elseif (y <= 1.4e+69) tmp = Float64(x * y); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5e+270) tmp = -y; elseif (y <= -2.35e+209) tmp = x * y; elseif (y <= -1.12e+185) tmp = -y; elseif (y <= -1.02e-38) tmp = x * y; elseif (y <= 1.22e-147) tmp = 1.0; elseif (y <= 1.4e+69) tmp = x * y; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5e+270], (-y), If[LessEqual[y, -2.35e+209], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.12e+185], (-y), If[LessEqual[y, -1.02e-38], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.22e-147], 1.0, If[LessEqual[y, 1.4e+69], N[(x * y), $MachinePrecision], (-y)]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+270}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -2.35 \cdot 10^{+209}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.12 \cdot 10^{+185}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -1.02 \cdot 10^{-38}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-147}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+69}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -4.99999999999999976e270 or -2.35e209 < y < -1.11999999999999996e185 or 1.39999999999999991e69 < y Initial 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 63.7%
neg-mul-163.7%
Simplified63.7%
if -4.99999999999999976e270 < y < -2.35e209 or -1.11999999999999996e185 < y < -1.01999999999999998e-38 or 1.21999999999999995e-147 < y < 1.39999999999999991e69Initial program 78.9%
Taylor expanded in x around inf 43.1%
mul-1-neg43.1%
unsub-neg43.1%
sub-neg43.1%
associate--r+63.4%
metadata-eval63.4%
neg-sub063.4%
remove-double-neg63.4%
Simplified63.4%
if -1.01999999999999998e-38 < y < 1.21999999999999995e-147Initial program 48.8%
Taylor expanded in y around 0 84.4%
Final simplification70.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (+ x -1.0))))
(if (<= y -2.5e-40)
t_0
(if (<= y 1.22e-147)
(- 1.0 y)
(if (<= y 2.7e-54) (* x y) (if (<= y 420.0) (- 1.0 y) t_0))))))
double code(double x, double y) {
double t_0 = y * (x + -1.0);
double tmp;
if (y <= -2.5e-40) {
tmp = t_0;
} else if (y <= 1.22e-147) {
tmp = 1.0 - y;
} else if (y <= 2.7e-54) {
tmp = x * y;
} else if (y <= 420.0) {
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 = y * (x + (-1.0d0))
if (y <= (-2.5d-40)) then
tmp = t_0
else if (y <= 1.22d-147) then
tmp = 1.0d0 - y
else if (y <= 2.7d-54) then
tmp = x * y
else if (y <= 420.0d0) 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 = y * (x + -1.0);
double tmp;
if (y <= -2.5e-40) {
tmp = t_0;
} else if (y <= 1.22e-147) {
tmp = 1.0 - y;
} else if (y <= 2.7e-54) {
tmp = x * y;
} else if (y <= 420.0) {
tmp = 1.0 - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x + -1.0) tmp = 0 if y <= -2.5e-40: tmp = t_0 elif y <= 1.22e-147: tmp = 1.0 - y elif y <= 2.7e-54: tmp = x * y elif y <= 420.0: tmp = 1.0 - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x + -1.0)) tmp = 0.0 if (y <= -2.5e-40) tmp = t_0; elseif (y <= 1.22e-147) tmp = Float64(1.0 - y); elseif (y <= 2.7e-54) tmp = Float64(x * y); elseif (y <= 420.0) tmp = Float64(1.0 - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x + -1.0); tmp = 0.0; if (y <= -2.5e-40) tmp = t_0; elseif (y <= 1.22e-147) tmp = 1.0 - y; elseif (y <= 2.7e-54) tmp = x * y; elseif (y <= 420.0) tmp = 1.0 - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5e-40], t$95$0, If[LessEqual[y, 1.22e-147], N[(1.0 - y), $MachinePrecision], If[LessEqual[y, 2.7e-54], N[(x * y), $MachinePrecision], If[LessEqual[y, 420.0], N[(1.0 - y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + -1\right)\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{-40}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-147}:\\
\;\;\;\;1 - y\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-54}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 420:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.49999999999999982e-40 or 420 < y Initial program 96.2%
Taylor expanded in y around inf 95.6%
mul-1-neg95.6%
distribute-rgt-neg-in95.6%
sub-neg95.6%
distribute-neg-in95.6%
metadata-eval95.6%
remove-double-neg95.6%
Simplified95.6%
if -2.49999999999999982e-40 < y < 1.21999999999999995e-147 or 2.70000000000000026e-54 < y < 420Initial program 52.1%
Taylor expanded in x around 0 82.5%
if 1.21999999999999995e-147 < y < 2.70000000000000026e-54Initial program 15.6%
Taylor expanded in x around inf 2.7%
mul-1-neg2.7%
unsub-neg2.7%
sub-neg2.7%
associate--r+82.8%
metadata-eval82.8%
neg-sub082.8%
remove-double-neg82.8%
Simplified82.8%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= x -58000000000.0) (* x y) (if (<= x 7.5e+121) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -58000000000.0) {
tmp = x * y;
} else if (x <= 7.5e+121) {
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 <= (-58000000000.0d0)) then
tmp = x * y
else if (x <= 7.5d+121) 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 <= -58000000000.0) {
tmp = x * y;
} else if (x <= 7.5e+121) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -58000000000.0: tmp = x * y elif x <= 7.5e+121: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -58000000000.0) tmp = Float64(x * y); elseif (x <= 7.5e+121) 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 <= -58000000000.0) tmp = x * y; elseif (x <= 7.5e+121) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -58000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.5e+121], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -58000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+121}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.8e10 or 7.49999999999999965e121 < x Initial program 52.3%
Taylor expanded in x around inf 52.1%
mul-1-neg52.1%
unsub-neg52.1%
sub-neg52.1%
associate--r+79.2%
metadata-eval79.2%
neg-sub079.2%
remove-double-neg79.2%
Simplified79.2%
if -5.8e10 < x < 7.49999999999999965e121Initial program 89.9%
Taylor expanded in x around 0 90.6%
Final simplification85.7%
(FPCore (x y) :precision binary64 (- (+ 1.0 (* x y)) y))
double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (x * y)) - y
end function
public static double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
def code(x, y): return (1.0 + (x * y)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(x * y)) - y) end
function tmp = code(x, y) tmp = (1.0 + (x * y)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + x \cdot y\right) - y
\end{array}
Initial program 73.6%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(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.9%
mul-1-neg98.9%
distribute-rgt-neg-in98.9%
sub-neg98.9%
distribute-neg-in98.9%
metadata-eval98.9%
remove-double-neg98.9%
Simplified98.9%
Taylor expanded in x around 0 49.3%
neg-mul-149.3%
Simplified49.3%
if -1 < y < 1Initial program 48.0%
Taylor expanded in y around 0 69.5%
Final simplification59.6%
(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 73.6%
Taylor expanded in y around 0 36.6%
Final simplification36.6%
(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 2023230
(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))))