
(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 82.1%
sub-neg82.1%
distribute-rgt-in82.1%
*-lft-identity82.1%
associate-+r+90.2%
+-commutative90.2%
sub-neg90.2%
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 -4.4e+45)
(- y)
(if (<= y -5.4e-33)
(* x y)
(if (<= y 8.8e-10) 1.0 (if (<= y 3.7e+221) (* x y) (- y))))))
double code(double x, double y) {
double tmp;
if (y <= -4.4e+45) {
tmp = -y;
} else if (y <= -5.4e-33) {
tmp = x * y;
} else if (y <= 8.8e-10) {
tmp = 1.0;
} else if (y <= 3.7e+221) {
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 <= (-4.4d+45)) then
tmp = -y
else if (y <= (-5.4d-33)) then
tmp = x * y
else if (y <= 8.8d-10) then
tmp = 1.0d0
else if (y <= 3.7d+221) 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 <= -4.4e+45) {
tmp = -y;
} else if (y <= -5.4e-33) {
tmp = x * y;
} else if (y <= 8.8e-10) {
tmp = 1.0;
} else if (y <= 3.7e+221) {
tmp = x * y;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.4e+45: tmp = -y elif y <= -5.4e-33: tmp = x * y elif y <= 8.8e-10: tmp = 1.0 elif y <= 3.7e+221: tmp = x * y else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.4e+45) tmp = Float64(-y); elseif (y <= -5.4e-33) tmp = Float64(x * y); elseif (y <= 8.8e-10) tmp = 1.0; elseif (y <= 3.7e+221) tmp = Float64(x * y); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.4e+45) tmp = -y; elseif (y <= -5.4e-33) tmp = x * y; elseif (y <= 8.8e-10) tmp = 1.0; elseif (y <= 3.7e+221) tmp = x * y; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.4e+45], (-y), If[LessEqual[y, -5.4e-33], N[(x * y), $MachinePrecision], If[LessEqual[y, 8.8e-10], 1.0, If[LessEqual[y, 3.7e+221], N[(x * y), $MachinePrecision], (-y)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+45}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -5.4 \cdot 10^{-33}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{-10}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+221}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -4.4000000000000001e45 or 3.70000000000000001e221 < 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 62.3%
neg-mul-162.3%
Simplified62.3%
if -4.4000000000000001e45 < y < -5.4000000000000002e-33 or 8.7999999999999996e-10 < y < 3.70000000000000001e221Initial program 93.4%
Taylor expanded in x around inf 60.9%
mul-1-neg60.9%
unsub-neg60.9%
sub-neg60.9%
associate--r+67.5%
metadata-eval67.5%
neg-sub067.5%
remove-double-neg67.5%
Simplified67.5%
if -5.4000000000000002e-33 < y < 8.7999999999999996e-10Initial program 62.6%
Taylor expanded in y around 0 83.3%
Final simplification72.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.65e-59) (not (<= y 2.45))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.65e-59) || !(y <= 2.45)) {
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 <= (-1.65d-59)) .or. (.not. (y <= 2.45d0))) 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 <= -1.65e-59) || !(y <= 2.45)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.65e-59) or not (y <= 2.45): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.65e-59) || !(y <= 2.45)) 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 <= -1.65e-59) || ~((y <= 2.45))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.65e-59], N[Not[LessEqual[y, 2.45]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-59} \lor \neg \left(y \leq 2.45\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -1.64999999999999991e-59 or 2.4500000000000002 < y Initial program 95.0%
Taylor expanded in y around inf 97.2%
mul-1-neg97.2%
distribute-rgt-neg-in97.2%
sub-neg97.2%
distribute-neg-in97.2%
metadata-eval97.2%
remove-double-neg97.2%
Simplified97.2%
if -1.64999999999999991e-59 < y < 2.4500000000000002Initial program 63.6%
Taylor expanded in x around 0 84.8%
Final simplification92.1%
(FPCore (x y) :precision binary64 (if (<= x -12800000.0) (* x y) (if (<= x 680000.0) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -12800000.0) {
tmp = x * y;
} else if (x <= 680000.0) {
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 <= (-12800000.0d0)) then
tmp = x * y
else if (x <= 680000.0d0) 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 <= -12800000.0) {
tmp = x * y;
} else if (x <= 680000.0) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -12800000.0: tmp = x * y elif x <= 680000.0: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -12800000.0) tmp = Float64(x * y); elseif (x <= 680000.0) 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 <= -12800000.0) tmp = x * y; elseif (x <= 680000.0) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -12800000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 680000.0], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -12800000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 680000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.28e7 or 6.8e5 < x Initial program 61.2%
Taylor expanded in x around inf 60.2%
mul-1-neg60.2%
unsub-neg60.2%
sub-neg60.2%
associate--r+77.8%
metadata-eval77.8%
neg-sub077.8%
remove-double-neg77.8%
Simplified77.8%
if -1.28e7 < x < 6.8e5Initial program 100.0%
Taylor expanded in x around 0 97.2%
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 82.1%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.65e-14) (- y) (if (<= y 37000000.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.65e-14) {
tmp = -y;
} else if (y <= 37000000.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.65d-14)) then
tmp = -y
else if (y <= 37000000.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.65e-14) {
tmp = -y;
} else if (y <= 37000000.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.65e-14: tmp = -y elif y <= 37000000.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.65e-14) tmp = Float64(-y); elseif (y <= 37000000.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.65e-14) tmp = -y; elseif (y <= 37000000.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.65e-14], (-y), If[LessEqual[y, 37000000.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-14}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 37000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1.6499999999999999e-14 or 3.7e7 < y Initial program 99.5%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
sub-neg99.6%
distribute-neg-in99.6%
metadata-eval99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 48.3%
neg-mul-148.3%
Simplified48.3%
if -1.6499999999999999e-14 < y < 3.7e7Initial program 61.5%
Taylor expanded in y around 0 79.1%
Final simplification62.4%
(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 82.1%
Taylor expanded in y around 0 37.7%
Final simplification37.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 2023257
(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))))