
(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 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 80.1%
sub-neg80.1%
distribute-rgt-in80.1%
*-lft-identity80.1%
associate-+r+89.1%
+-commutative89.1%
sub-neg89.1%
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 -7.8e+95)
(* x y)
(if (<= y -1.9e+54)
(- y)
(if (<= y -1.15e-37)
(* x y)
(if (<= y 8.4e-23) 1.0 (if (<= y 2.2e+119) (* x y) (- y)))))))
double code(double x, double y) {
double tmp;
if (y <= -7.8e+95) {
tmp = x * y;
} else if (y <= -1.9e+54) {
tmp = -y;
} else if (y <= -1.15e-37) {
tmp = x * y;
} else if (y <= 8.4e-23) {
tmp = 1.0;
} else if (y <= 2.2e+119) {
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 <= (-7.8d+95)) then
tmp = x * y
else if (y <= (-1.9d+54)) then
tmp = -y
else if (y <= (-1.15d-37)) then
tmp = x * y
else if (y <= 8.4d-23) then
tmp = 1.0d0
else if (y <= 2.2d+119) 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 <= -7.8e+95) {
tmp = x * y;
} else if (y <= -1.9e+54) {
tmp = -y;
} else if (y <= -1.15e-37) {
tmp = x * y;
} else if (y <= 8.4e-23) {
tmp = 1.0;
} else if (y <= 2.2e+119) {
tmp = x * y;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e+95: tmp = x * y elif y <= -1.9e+54: tmp = -y elif y <= -1.15e-37: tmp = x * y elif y <= 8.4e-23: tmp = 1.0 elif y <= 2.2e+119: tmp = x * y else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e+95) tmp = Float64(x * y); elseif (y <= -1.9e+54) tmp = Float64(-y); elseif (y <= -1.15e-37) tmp = Float64(x * y); elseif (y <= 8.4e-23) tmp = 1.0; elseif (y <= 2.2e+119) tmp = Float64(x * y); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.8e+95) tmp = x * y; elseif (y <= -1.9e+54) tmp = -y; elseif (y <= -1.15e-37) tmp = x * y; elseif (y <= 8.4e-23) tmp = 1.0; elseif (y <= 2.2e+119) tmp = x * y; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e+95], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.9e+54], (-y), If[LessEqual[y, -1.15e-37], N[(x * y), $MachinePrecision], If[LessEqual[y, 8.4e-23], 1.0, If[LessEqual[y, 2.2e+119], N[(x * y), $MachinePrecision], (-y)]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+95}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{+54}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-37}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 8.4 \cdot 10^{-23}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+119}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -7.7999999999999994e95 or -1.9000000000000001e54 < y < -1.15e-37 or 8.4000000000000003e-23 < y < 2.2000000000000001e119Initial program 90.2%
Taylor expanded in x around inf 51.2%
mul-1-neg51.2%
unsub-neg51.2%
sub-neg51.2%
associate--r+60.8%
metadata-eval60.8%
neg-sub060.8%
remove-double-neg60.8%
Simplified60.8%
if -7.7999999999999994e95 < y < -1.9000000000000001e54 or 2.2000000000000001e119 < 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 69.4%
neg-mul-169.4%
Simplified69.4%
if -1.15e-37 < y < 8.4000000000000003e-23Initial program 64.4%
Taylor expanded in y around 0 86.1%
Final simplification74.4%
(FPCore (x y) :precision binary64 (if (or (<= y -8.8e-38) (not (<= y 4e-22))) (* y (+ x -1.0)) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -8.8e-38) || !(y <= 4e-22)) {
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 <= (-8.8d-38)) .or. (.not. (y <= 4d-22))) 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 <= -8.8e-38) || !(y <= 4e-22)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8.8e-38) or not (y <= 4e-22): tmp = y * (x + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -8.8e-38) || !(y <= 4e-22)) 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 <= -8.8e-38) || ~((y <= 4e-22))) tmp = y * (x + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8.8e-38], N[Not[LessEqual[y, 4e-22]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-38} \lor \neg \left(y \leq 4 \cdot 10^{-22}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.80000000000000029e-38 or 4.0000000000000002e-22 < y Initial program 93.9%
Taylor expanded in y around inf 96.6%
mul-1-neg96.6%
distribute-rgt-neg-in96.6%
sub-neg96.6%
distribute-neg-in96.6%
metadata-eval96.6%
remove-double-neg96.6%
Simplified96.6%
if -8.80000000000000029e-38 < y < 4.0000000000000002e-22Initial program 64.4%
Taylor expanded in y around 0 86.1%
Final simplification91.7%
(FPCore (x y) :precision binary64 (if (<= y -4.3e-38) (- (* x y) y) (if (<= y 9.5e-24) 1.0 (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -4.3e-38) {
tmp = (x * y) - y;
} else if (y <= 9.5e-24) {
tmp = 1.0;
} 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 <= (-4.3d-38)) then
tmp = (x * y) - y
else if (y <= 9.5d-24) then
tmp = 1.0d0
else
tmp = y * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.3e-38) {
tmp = (x * y) - y;
} else if (y <= 9.5e-24) {
tmp = 1.0;
} else {
tmp = y * (x + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.3e-38: tmp = (x * y) - y elif y <= 9.5e-24: tmp = 1.0 else: tmp = y * (x + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -4.3e-38) tmp = Float64(Float64(x * y) - y); elseif (y <= 9.5e-24) tmp = 1.0; else tmp = Float64(y * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.3e-38) tmp = (x * y) - y; elseif (y <= 9.5e-24) tmp = 1.0; else tmp = y * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.3e-38], N[(N[(x * y), $MachinePrecision] - y), $MachinePrecision], If[LessEqual[y, 9.5e-24], 1.0, N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-38}:\\
\;\;\;\;x \cdot y - y\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-24}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -4.3000000000000002e-38Initial program 92.3%
Taylor expanded in y around inf 94.7%
mul-1-neg94.7%
distribute-rgt-neg-in94.7%
sub-neg94.7%
distribute-neg-in94.7%
metadata-eval94.7%
remove-double-neg94.7%
Simplified94.7%
+-commutative94.7%
distribute-rgt-in94.7%
*-commutative94.7%
neg-mul-194.7%
sub-neg94.7%
Applied egg-rr94.7%
if -4.3000000000000002e-38 < y < 9.50000000000000029e-24Initial program 64.4%
Taylor expanded in y around 0 86.1%
if 9.50000000000000029e-24 < y Initial program 95.6%
Taylor expanded in y around inf 98.5%
mul-1-neg98.5%
distribute-rgt-neg-in98.5%
sub-neg98.5%
distribute-neg-in98.5%
metadata-eval98.5%
remove-double-neg98.5%
Simplified98.5%
Final simplification91.7%
(FPCore (x y) :precision binary64 (if (<= x -5e+137) (* x y) (if (<= x 1.6e+26) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -5e+137) {
tmp = x * y;
} else if (x <= 1.6e+26) {
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 <= (-5d+137)) then
tmp = x * y
else if (x <= 1.6d+26) 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 <= -5e+137) {
tmp = x * y;
} else if (x <= 1.6e+26) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+137: tmp = x * y elif x <= 1.6e+26: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+137) tmp = Float64(x * y); elseif (x <= 1.6e+26) 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 <= -5e+137) tmp = x * y; elseif (x <= 1.6e+26) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+137], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e+26], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+137}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+26}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.0000000000000002e137 or 1.60000000000000014e26 < x Initial program 57.5%
Taylor expanded in x around inf 57.5%
mul-1-neg57.5%
unsub-neg57.5%
sub-neg57.5%
associate--r+82.2%
metadata-eval82.2%
neg-sub082.2%
remove-double-neg82.2%
Simplified82.2%
if -5.0000000000000002e137 < x < 1.60000000000000014e26Initial program 91.5%
Taylor expanded in x around 0 91.3%
Final simplification88.2%
(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 80.1%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 2.1e+21) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 2.1e+21) {
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 <= 2.1d+21) 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 <= 2.1e+21) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 2.1e+21: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 2.1e+21) 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 <= 2.1e+21) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 2.1e+21], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+21}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 2.1e21 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
mul-1-neg99.2%
distribute-rgt-neg-in99.2%
sub-neg99.2%
distribute-neg-in99.2%
metadata-eval99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 53.8%
neg-mul-153.8%
Simplified53.8%
if -1 < y < 2.1e21Initial program 63.1%
Taylor expanded in y around 0 77.9%
Final simplification66.8%
(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 80.1%
Taylor expanded in y around 0 43.2%
Final simplification43.2%
(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 2023221
(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))))