
(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 79.5%
sub-neg79.5%
distribute-rgt-in79.5%
*-lft-identity79.5%
associate-+r+88.8%
+-commutative88.8%
sub-neg88.8%
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 -1.35e+26)
(* x y)
(if (<= y -1350000000.0)
(- y)
(if (<= y -4e-5)
(* x y)
(if (<= y 2e-75)
1.0
(if (<= y 2.9e+28) (* x y) (if (<= y 3.6e+245) (- y) (* x y))))))))
double code(double x, double y) {
double tmp;
if (y <= -1.35e+26) {
tmp = x * y;
} else if (y <= -1350000000.0) {
tmp = -y;
} else if (y <= -4e-5) {
tmp = x * y;
} else if (y <= 2e-75) {
tmp = 1.0;
} else if (y <= 2.9e+28) {
tmp = x * y;
} else if (y <= 3.6e+245) {
tmp = -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 (y <= (-1.35d+26)) then
tmp = x * y
else if (y <= (-1350000000.0d0)) then
tmp = -y
else if (y <= (-4d-5)) then
tmp = x * y
else if (y <= 2d-75) then
tmp = 1.0d0
else if (y <= 2.9d+28) then
tmp = x * y
else if (y <= 3.6d+245) then
tmp = -y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.35e+26) {
tmp = x * y;
} else if (y <= -1350000000.0) {
tmp = -y;
} else if (y <= -4e-5) {
tmp = x * y;
} else if (y <= 2e-75) {
tmp = 1.0;
} else if (y <= 2.9e+28) {
tmp = x * y;
} else if (y <= 3.6e+245) {
tmp = -y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.35e+26: tmp = x * y elif y <= -1350000000.0: tmp = -y elif y <= -4e-5: tmp = x * y elif y <= 2e-75: tmp = 1.0 elif y <= 2.9e+28: tmp = x * y elif y <= 3.6e+245: tmp = -y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.35e+26) tmp = Float64(x * y); elseif (y <= -1350000000.0) tmp = Float64(-y); elseif (y <= -4e-5) tmp = Float64(x * y); elseif (y <= 2e-75) tmp = 1.0; elseif (y <= 2.9e+28) tmp = Float64(x * y); elseif (y <= 3.6e+245) tmp = Float64(-y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.35e+26) tmp = x * y; elseif (y <= -1350000000.0) tmp = -y; elseif (y <= -4e-5) tmp = x * y; elseif (y <= 2e-75) tmp = 1.0; elseif (y <= 2.9e+28) tmp = x * y; elseif (y <= 3.6e+245) tmp = -y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.35e+26], N[(x * y), $MachinePrecision], If[LessEqual[y, -1350000000.0], (-y), If[LessEqual[y, -4e-5], N[(x * y), $MachinePrecision], If[LessEqual[y, 2e-75], 1.0, If[LessEqual[y, 2.9e+28], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.6e+245], (-y), N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+26}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1350000000:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -4 \cdot 10^{-5}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-75}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+28}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+245}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.35e26 or -1.35e9 < y < -4.00000000000000033e-5 or 1.9999999999999999e-75 < y < 2.9000000000000001e28 or 3.6000000000000002e245 < y Initial program 93.9%
Taylor expanded in x around inf 53.2%
mul-1-neg53.2%
unsub-neg53.2%
sub-neg53.2%
associate--r+59.3%
metadata-eval59.3%
neg-sub059.3%
remove-double-neg59.3%
Simplified59.3%
if -1.35e26 < y < -1.35e9 or 2.9000000000000001e28 < y < 3.6000000000000002e245Initial 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 65.0%
neg-mul-165.0%
Simplified65.0%
if -4.00000000000000033e-5 < y < 1.9999999999999999e-75Initial program 60.7%
Taylor expanded in y around 0 83.1%
Final simplification71.7%
(FPCore (x y) :precision binary64 (if (or (<= y -3.5) (not (<= y 4.5e-75))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -3.5) || !(y <= 4.5e-75)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - 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.5d0)) .or. (.not. (y <= 4.5d-75))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.5) || !(y <= 4.5e-75)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.5) or not (y <= 4.5e-75): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.5) || !(y <= 4.5e-75)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.5) || ~((y <= 4.5e-75))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.5], N[Not[LessEqual[y, 4.5e-75]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \lor \neg \left(y \leq 4.5 \cdot 10^{-75}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -3.5 or 4.5000000000000003e-75 < y Initial program 96.3%
Taylor expanded in y around inf 96.1%
mul-1-neg96.1%
distribute-rgt-neg-in96.1%
sub-neg96.1%
distribute-neg-in96.1%
metadata-eval96.1%
remove-double-neg96.1%
Simplified96.1%
if -3.5 < y < 4.5000000000000003e-75Initial program 60.7%
Taylor expanded in x around 0 84.1%
Final simplification90.5%
(FPCore (x y) :precision binary64 (if (<= x -2.5e+14) (* x y) (if (<= x 5.6e+29) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e+14) {
tmp = x * y;
} else if (x <= 5.6e+29) {
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 <= (-2.5d+14)) then
tmp = x * y
else if (x <= 5.6d+29) 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 <= -2.5e+14) {
tmp = x * y;
} else if (x <= 5.6e+29) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e+14: tmp = x * y elif x <= 5.6e+29: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e+14) tmp = Float64(x * y); elseif (x <= 5.6e+29) 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 <= -2.5e+14) tmp = x * y; elseif (x <= 5.6e+29) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e+14], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.6e+29], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+14}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{+29}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.5e14 or 5.5999999999999999e29 < x Initial program 55.3%
Taylor expanded in x around inf 55.3%
mul-1-neg55.3%
unsub-neg55.3%
sub-neg55.3%
associate--r+76.9%
metadata-eval76.9%
neg-sub076.9%
remove-double-neg76.9%
Simplified76.9%
if -2.5e14 < x < 5.5999999999999999e29Initial program 98.0%
Taylor expanded in x around 0 98.5%
Final simplification89.1%
(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 79.5%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -11.4) (- y) (if (<= y 0.145) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -11.4) {
tmp = -y;
} else if (y <= 0.145) {
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 <= (-11.4d0)) then
tmp = -y
else if (y <= 0.145d0) 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 <= -11.4) {
tmp = -y;
} else if (y <= 0.145) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -11.4: tmp = -y elif y <= 0.145: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -11.4) tmp = Float64(-y); elseif (y <= 0.145) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -11.4) tmp = -y; elseif (y <= 0.145) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -11.4], (-y), If[LessEqual[y, 0.145], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -11.4:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 0.145:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -11.4000000000000004 or 0.14499999999999999 < y Initial program 100.0%
Taylor expanded in y around inf 99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
sub-neg99.0%
distribute-neg-in99.0%
metadata-eval99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
Simplified51.4%
if -11.4000000000000004 < y < 0.14499999999999999Initial program 59.9%
Taylor expanded in y around 0 79.4%
Final simplification65.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 79.5%
Taylor expanded in y around 0 41.9%
Final simplification41.9%
(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 2023185
(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))))