
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 99.2%
sub-neg99.2%
+-commutative99.2%
distribute-lft1-in99.2%
associate-+r+99.2%
+-commutative99.2%
distribute-lft-neg-out99.2%
distribute-rgt-neg-out99.2%
distribute-lft-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -0.0016) (* x y) (if (<= x 5.6e-42) z (if (<= x 3.1e+29) (* x y) (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0016) {
tmp = x * y;
} else if (x <= 5.6e-42) {
tmp = z;
} else if (x <= 3.1e+29) {
tmp = x * y;
} else {
tmp = z * -x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-0.0016d0)) then
tmp = x * y
else if (x <= 5.6d-42) then
tmp = z
else if (x <= 3.1d+29) then
tmp = x * y
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.0016) {
tmp = x * y;
} else if (x <= 5.6e-42) {
tmp = z;
} else if (x <= 3.1e+29) {
tmp = x * y;
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0016: tmp = x * y elif x <= 5.6e-42: tmp = z elif x <= 3.1e+29: tmp = x * y else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0016) tmp = Float64(x * y); elseif (x <= 5.6e-42) tmp = z; elseif (x <= 3.1e+29) tmp = Float64(x * y); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.0016) tmp = x * y; elseif (x <= 5.6e-42) tmp = z; elseif (x <= 3.1e+29) tmp = x * y; else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0016], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.6e-42], z, If[LessEqual[x, 3.1e+29], N[(x * y), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0016:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-42}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+29}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -0.00160000000000000008 or 5.59999999999999996e-42 < x < 3.0999999999999999e29Initial program 97.5%
+-commutative97.5%
remove-double-neg97.5%
distribute-rgt-neg-out97.5%
neg-sub097.5%
neg-sub097.5%
*-commutative97.5%
distribute-lft-neg-in97.5%
remove-double-neg97.5%
distribute-rgt-out--97.5%
*-lft-identity97.5%
associate-+l-97.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 60.1%
if -0.00160000000000000008 < x < 5.59999999999999996e-42Initial program 99.9%
+-commutative99.9%
remove-double-neg99.9%
distribute-rgt-neg-out99.9%
neg-sub099.9%
neg-sub099.9%
*-commutative99.9%
distribute-lft-neg-in99.9%
remove-double-neg99.9%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 81.8%
Taylor expanded in x around 0 81.0%
if 3.0999999999999999e29 < x Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.0%
Taylor expanded in x around inf 63.0%
mul-1-neg63.0%
*-commutative63.0%
distribute-rgt-neg-in63.0%
Simplified63.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e+33) (not (<= z 8.2e+95))) (- z (* x z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+33) || !(z <= 8.2e+95)) {
tmp = z - (x * z);
} else {
tmp = z + (x * y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-3.3d+33)) .or. (.not. (z <= 8.2d+95))) then
tmp = z - (x * z)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+33) || !(z <= 8.2e+95)) {
tmp = z - (x * z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e+33) or not (z <= 8.2e+95): tmp = z - (x * z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e+33) || !(z <= 8.2e+95)) tmp = Float64(z - Float64(x * z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e+33) || ~((z <= 8.2e+95))) tmp = z - (x * z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e+33], N[Not[LessEqual[z, 8.2e+95]], $MachinePrecision]], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+33} \lor \neg \left(z \leq 8.2 \cdot 10^{+95}\right):\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if z < -3.29999999999999976e33 or 8.19999999999999972e95 < z Initial program 98.3%
+-commutative98.3%
remove-double-neg98.3%
distribute-rgt-neg-out98.3%
neg-sub098.3%
neg-sub098.3%
*-commutative98.3%
distribute-lft-neg-in98.3%
remove-double-neg98.3%
distribute-rgt-out--98.3%
*-lft-identity98.3%
associate-+l-98.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 91.2%
if -3.29999999999999976e33 < z < 8.19999999999999972e95Initial program 99.9%
+-commutative99.9%
remove-double-neg99.9%
distribute-rgt-neg-out99.9%
neg-sub099.9%
neg-sub099.9%
*-commutative99.9%
distribute-lft-neg-in99.9%
remove-double-neg99.9%
distribute-rgt-out--99.9%
*-lft-identity99.9%
associate-+l-99.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 91.1%
mul-1-neg91.1%
distribute-rgt-neg-out91.1%
Simplified91.1%
sub-neg91.1%
distribute-rgt-neg-out91.1%
remove-double-neg91.1%
+-commutative91.1%
Applied egg-rr91.1%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0012) (not (<= x 5.9e-42))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !(x <= 5.9e-42)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-0.0012d0)) .or. (.not. (x <= 5.9d-42))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !(x <= 5.9e-42)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0012) or not (x <= 5.9e-42): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0012) || !(x <= 5.9e-42)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0012) || ~((x <= 5.9e-42))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0012], N[Not[LessEqual[x, 5.9e-42]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0012 \lor \neg \left(x \leq 5.9 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -0.00119999999999999989 or 5.89999999999999992e-42 < x Initial program 98.3%
+-commutative98.3%
remove-double-neg98.3%
distribute-rgt-neg-out98.3%
neg-sub098.3%
neg-sub098.3%
*-commutative98.3%
distribute-lft-neg-in98.3%
remove-double-neg98.3%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 57.1%
if -0.00119999999999999989 < x < 5.89999999999999992e-42Initial program 99.9%
+-commutative99.9%
remove-double-neg99.9%
distribute-rgt-neg-out99.9%
neg-sub099.9%
neg-sub099.9%
*-commutative99.9%
distribute-lft-neg-in99.9%
remove-double-neg99.9%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 81.8%
Taylor expanded in x around 0 81.0%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (<= x 6.5e+30) (+ z (* x y)) (* z (- x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 6.5e+30) {
tmp = z + (x * y);
} else {
tmp = z * -x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= 6.5d+30) then
tmp = z + (x * y)
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 6.5e+30) {
tmp = z + (x * y);
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 6.5e+30: tmp = z + (x * y) else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 6.5e+30) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 6.5e+30) tmp = z + (x * y); else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 6.5e+30], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.5 \cdot 10^{+30}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < 6.5e30Initial program 99.0%
+-commutative99.0%
remove-double-neg99.0%
distribute-rgt-neg-out99.0%
neg-sub099.0%
neg-sub099.0%
*-commutative99.0%
distribute-lft-neg-in99.0%
remove-double-neg99.0%
distribute-rgt-out--99.0%
*-lft-identity99.0%
associate-+l-99.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 85.4%
mul-1-neg85.4%
distribute-rgt-neg-out85.4%
Simplified85.4%
sub-neg85.4%
distribute-rgt-neg-out85.4%
remove-double-neg85.4%
+-commutative85.4%
Applied egg-rr85.4%
if 6.5e30 < x Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.0%
Taylor expanded in x around inf 63.0%
mul-1-neg63.0%
*-commutative63.0%
distribute-rgt-neg-in63.0%
Simplified63.0%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (+ z (* x (- y z))))
double code(double x, double y, double z) {
return z + (x * (y - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - z));
}
def code(x, y, z): return z + (x * (y - z))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = z + (x * (y - z)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - z\right)
\end{array}
Initial program 99.2%
+-commutative99.2%
remove-double-neg99.2%
distribute-rgt-neg-out99.2%
neg-sub099.2%
neg-sub099.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
remove-double-neg99.2%
distribute-rgt-out--99.2%
*-lft-identity99.2%
associate-+l-99.2%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.2%
+-commutative99.2%
remove-double-neg99.2%
distribute-rgt-neg-out99.2%
neg-sub099.2%
neg-sub099.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
remove-double-neg99.2%
distribute-rgt-out--99.2%
*-lft-identity99.2%
associate-+l-99.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 66.7%
Taylor expanded in x around 0 43.7%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))