
(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 6 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 (+ 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 74.1%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (+ x -1.0))))
(if (<= (- 1.0 y) -2e+14)
t_0
(if (<= (- 1.0 y) 1.00005) (+ 1.0 (* y x)) t_0))))
double code(double x, double y) {
double t_0 = y * (x + -1.0);
double tmp;
if ((1.0 - y) <= -2e+14) {
tmp = t_0;
} else if ((1.0 - y) <= 1.00005) {
tmp = 1.0 + (y * x);
} 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 ((1.0d0 - y) <= (-2d+14)) then
tmp = t_0
else if ((1.0d0 - y) <= 1.00005d0) then
tmp = 1.0d0 + (y * x)
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 ((1.0 - y) <= -2e+14) {
tmp = t_0;
} else if ((1.0 - y) <= 1.00005) {
tmp = 1.0 + (y * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x + -1.0) tmp = 0 if (1.0 - y) <= -2e+14: tmp = t_0 elif (1.0 - y) <= 1.00005: tmp = 1.0 + (y * x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x + -1.0)) tmp = 0.0 if (Float64(1.0 - y) <= -2e+14) tmp = t_0; elseif (Float64(1.0 - y) <= 1.00005) tmp = Float64(1.0 + Float64(y * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x + -1.0); tmp = 0.0; if ((1.0 - y) <= -2e+14) tmp = t_0; elseif ((1.0 - y) <= 1.00005) tmp = 1.0 + (y * x); 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[N[(1.0 - y), $MachinePrecision], -2e+14], t$95$0, If[LessEqual[N[(1.0 - y), $MachinePrecision], 1.00005], N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + -1\right)\\
\mathbf{if}\;1 - y \leq -2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - y \leq 1.00005:\\
\;\;\;\;1 + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -2e14 or 1.00005000000000011 < (-.f64 #s(literal 1 binary64) y) Initial program 99.8%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-lowering-+.f6499.2%
Simplified99.2%
if -2e14 < (-.f64 #s(literal 1 binary64) y) < 1.00005000000000011Initial program 52.7%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6499.4%
Simplified99.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (+ x -1.0)))) (if (<= y -3.3e-81) t_0 (if (<= y 1.22e-51) 1.0 t_0))))
double code(double x, double y) {
double t_0 = y * (x + -1.0);
double tmp;
if (y <= -3.3e-81) {
tmp = t_0;
} else if (y <= 1.22e-51) {
tmp = 1.0;
} 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 <= (-3.3d-81)) then
tmp = t_0
else if (y <= 1.22d-51) then
tmp = 1.0d0
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 <= -3.3e-81) {
tmp = t_0;
} else if (y <= 1.22e-51) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x + -1.0) tmp = 0 if y <= -3.3e-81: tmp = t_0 elif y <= 1.22e-51: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x + -1.0)) tmp = 0.0 if (y <= -3.3e-81) tmp = t_0; elseif (y <= 1.22e-51) tmp = 1.0; 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 <= -3.3e-81) tmp = t_0; elseif (y <= 1.22e-51) tmp = 1.0; 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, -3.3e-81], t$95$0, If[LessEqual[y, 1.22e-51], 1.0, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + -1\right)\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-51}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.29999999999999987e-81 or 1.21999999999999998e-51 < y Initial program 88.0%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-lowering-+.f6488.6%
Simplified88.6%
if -3.29999999999999987e-81 < y < 1.21999999999999998e-51Initial program 52.0%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in y around 0
Simplified84.3%
(FPCore (x y) :precision binary64 (if (<= x -15000000000.0) (* y x) (if (<= x 2.05e+37) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -15000000000.0) {
tmp = y * x;
} else if (x <= 2.05e+37) {
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 <= (-15000000000.0d0)) then
tmp = y * x
else if (x <= 2.05d+37) 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 <= -15000000000.0) {
tmp = y * x;
} else if (x <= 2.05e+37) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -15000000000.0: tmp = y * x elif x <= 2.05e+37: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -15000000000.0) tmp = Float64(y * x); elseif (x <= 2.05e+37) 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 <= -15000000000.0) tmp = y * x; elseif (x <= 2.05e+37) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -15000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.05e+37], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -15000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{+37}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.5e10 or 2.0499999999999999e37 < x Initial program 50.0%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6475.7%
Simplified75.7%
if -1.5e10 < x < 2.0499999999999999e37Initial program 97.0%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6495.9%
Simplified95.9%
(FPCore (x y) :precision binary64 (if (<= y -1.2e-11) (* y x) (if (<= y 2.35e-48) 1.0 (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.2e-11) {
tmp = y * x;
} else if (y <= 2.35e-48) {
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.2d-11)) then
tmp = y * x
else if (y <= 2.35d-48) 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.2e-11) {
tmp = y * x;
} else if (y <= 2.35e-48) {
tmp = 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.2e-11: tmp = y * x elif y <= 2.35e-48: tmp = 1.0 else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.2e-11) tmp = Float64(y * x); elseif (y <= 2.35e-48) tmp = 1.0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.2e-11) tmp = y * x; elseif (y <= 2.35e-48) tmp = 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.2e-11], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.35e-48], 1.0, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{-11}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{-48}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.2000000000000001e-11 or 2.3499999999999999e-48 < y Initial program 96.0%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6454.9%
Simplified54.9%
if -1.2000000000000001e-11 < y < 2.3499999999999999e-48Initial program 51.8%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in y around 0
Simplified77.1%
(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 74.1%
sub-negN/A
distribute-rgt-inN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
metadata-evalN/A
associate-+l+N/A
associate-+r+N/A
*-lft-identityN/A
neg-mul-1N/A
distribute-rgt1-inN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
*-lft-identityN/A
mul0-lftN/A
+-lft-identityN/A
+-lowering-+.f64N/A
*-commutativeN/A
neg-mul-1N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified100.0%
Taylor expanded in y around 0
Simplified40.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 2024161
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (- (* y x) (- y 1)))
(+ x (* (- 1.0 x) (- 1.0 y))))