
(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 8 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 97.6%
sub-neg97.6%
+-commutative97.6%
distribute-lft1-in97.6%
associate-+r+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
*-commutative97.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.3e+257)
(* x y)
(if (<= x -2.6e+57)
(* x (- z))
(if (<= x -17000.0) (* x y) (if (<= x 1.9e-46) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+257) {
tmp = x * y;
} else if (x <= -2.6e+57) {
tmp = x * -z;
} else if (x <= -17000.0) {
tmp = x * y;
} else if (x <= 1.9e-46) {
tmp = z;
} else {
tmp = 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 (x <= (-1.3d+257)) then
tmp = x * y
else if (x <= (-2.6d+57)) then
tmp = x * -z
else if (x <= (-17000.0d0)) then
tmp = x * y
else if (x <= 1.9d-46) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+257) {
tmp = x * y;
} else if (x <= -2.6e+57) {
tmp = x * -z;
} else if (x <= -17000.0) {
tmp = x * y;
} else if (x <= 1.9e-46) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+257: tmp = x * y elif x <= -2.6e+57: tmp = x * -z elif x <= -17000.0: tmp = x * y elif x <= 1.9e-46: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+257) tmp = Float64(x * y); elseif (x <= -2.6e+57) tmp = Float64(x * Float64(-z)); elseif (x <= -17000.0) tmp = Float64(x * y); elseif (x <= 1.9e-46) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+257) tmp = x * y; elseif (x <= -2.6e+57) tmp = x * -z; elseif (x <= -17000.0) tmp = x * y; elseif (x <= 1.9e-46) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+257], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.6e+57], N[(x * (-z)), $MachinePrecision], If[LessEqual[x, -17000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.9e-46], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+257}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{+57}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;x \leq -17000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-46}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.30000000000000011e257 or -2.6e57 < x < -17000 or 1.8999999999999998e-46 < x Initial program 94.3%
Taylor expanded in y around inf 67.7%
if -1.30000000000000011e257 < x < -2.6e57Initial program 97.8%
sub-neg97.8%
+-commutative97.8%
distribute-lft1-in97.8%
associate-+r+97.8%
+-commutative97.8%
*-commutative97.8%
neg-mul-197.8%
associate-*r*97.8%
*-commutative97.8%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around 0 63.1%
mul-1-neg63.1%
distribute-rgt-neg-in63.1%
Simplified63.1%
if -17000 < x < 1.8999999999999998e-46Initial program 100.0%
Taylor expanded in x around 0 82.8%
Final simplification74.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -17000.0) (not (<= x 3.1e-41))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -17000.0) || !(x <= 3.1e-41)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - 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 <= (-17000.0d0)) .or. (.not. (x <= 3.1d-41))) then
tmp = x * (y - z)
else
tmp = z * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -17000.0) || !(x <= 3.1e-41)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -17000.0) or not (x <= 3.1e-41): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -17000.0) || !(x <= 3.1e-41)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -17000.0) || ~((x <= 3.1e-41))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -17000.0], N[Not[LessEqual[x, 3.1e-41]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -17000 \lor \neg \left(x \leq 3.1 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -17000 or 3.10000000000000001e-41 < x Initial program 95.5%
sub-neg95.5%
+-commutative95.5%
distribute-lft1-in95.5%
associate-+r+95.5%
+-commutative95.5%
*-commutative95.5%
neg-mul-195.5%
associate-*r*95.5%
*-commutative95.5%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 97.5%
if -17000 < x < 3.10000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 83.6%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -25000.0) (not (<= x 1.65e-41))) (* x (- y z)) (- z (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -25000.0) || !(x <= 1.65e-41)) {
tmp = x * (y - z);
} else {
tmp = z - (x * 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 <= (-25000.0d0)) .or. (.not. (x <= 1.65d-41))) then
tmp = x * (y - z)
else
tmp = z - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -25000.0) || !(x <= 1.65e-41)) {
tmp = x * (y - z);
} else {
tmp = z - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -25000.0) or not (x <= 1.65e-41): tmp = x * (y - z) else: tmp = z - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -25000.0) || !(x <= 1.65e-41)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -25000.0) || ~((x <= 1.65e-41))) tmp = x * (y - z); else tmp = z - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -25000.0], N[Not[LessEqual[x, 1.65e-41]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -25000 \lor \neg \left(x \leq 1.65 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot z\\
\end{array}
\end{array}
if x < -25000 or 1.65000000000000012e-41 < x Initial program 95.5%
sub-neg95.5%
+-commutative95.5%
distribute-lft1-in95.5%
associate-+r+95.5%
+-commutative95.5%
*-commutative95.5%
neg-mul-195.5%
associate-*r*95.5%
*-commutative95.5%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 97.5%
if -25000 < x < 1.65000000000000012e-41Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around 0 83.6%
+-commutative83.6%
mul-1-neg83.6%
unsub-neg83.6%
Simplified83.6%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.1e+85) (* x y) (if (<= y 4.1e+51) (* z (- 1.0 x)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.1e+85) {
tmp = x * y;
} else if (y <= 4.1e+51) {
tmp = z * (1.0 - x);
} else {
tmp = 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 (y <= (-2.1d+85)) then
tmp = x * y
else if (y <= 4.1d+51) then
tmp = z * (1.0d0 - x)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.1e+85) {
tmp = x * y;
} else if (y <= 4.1e+51) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.1e+85: tmp = x * y elif y <= 4.1e+51: tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.1e+85) tmp = Float64(x * y); elseif (y <= 4.1e+51) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.1e+85) tmp = x * y; elseif (y <= 4.1e+51) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.1e+85], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.1e+51], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+85}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+51}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.1000000000000001e85 or 4.10000000000000011e51 < y Initial program 95.7%
Taylor expanded in y around inf 72.4%
if -2.1000000000000001e85 < y < 4.10000000000000011e51Initial program 98.8%
Taylor expanded in y around 0 79.6%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (<= x -17000.0) (* x y) (if (<= x 3.3e-42) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -17000.0) {
tmp = x * y;
} else if (x <= 3.3e-42) {
tmp = z;
} else {
tmp = 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 (x <= (-17000.0d0)) then
tmp = x * y
else if (x <= 3.3d-42) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -17000.0) {
tmp = x * y;
} else if (x <= 3.3e-42) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -17000.0: tmp = x * y elif x <= 3.3e-42: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -17000.0) tmp = Float64(x * y); elseif (x <= 3.3e-42) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -17000.0) tmp = x * y; elseif (x <= 3.3e-42) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -17000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.3e-42], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -17000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-42}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -17000 or 3.3000000000000002e-42 < x Initial program 95.5%
Taylor expanded in y around inf 60.0%
if -17000 < x < 3.3000000000000002e-42Initial program 100.0%
Taylor expanded in x around 0 82.8%
Final simplification70.8%
(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 97.6%
sub-neg97.6%
+-commutative97.6%
distribute-lft1-in97.6%
associate-+r+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
*-commutative97.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.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 97.6%
Taylor expanded in x around 0 41.5%
Final simplification41.5%
herbie shell --seed 2023202
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))