
(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 96.9%
*-commutative96.9%
distribute-lft-out--96.9%
*-rgt-identity96.9%
cancel-sign-sub-inv96.9%
+-commutative96.9%
associate-+r+96.9%
*-commutative96.9%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -5e+115)
(* x y)
(if (<= x -2.9e+94)
t_0
(if (<= x -1.45e-46)
(* x y)
(if (<= x 1.08e-79)
z
(if (<= x 450000000.0)
(* x y)
(if (<= x 2.8e+257) t_0 (* x y)))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -5e+115) {
tmp = x * y;
} else if (x <= -2.9e+94) {
tmp = t_0;
} else if (x <= -1.45e-46) {
tmp = x * y;
} else if (x <= 1.08e-79) {
tmp = z;
} else if (x <= 450000000.0) {
tmp = x * y;
} else if (x <= 2.8e+257) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (x <= (-5d+115)) then
tmp = x * y
else if (x <= (-2.9d+94)) then
tmp = t_0
else if (x <= (-1.45d-46)) then
tmp = x * y
else if (x <= 1.08d-79) then
tmp = z
else if (x <= 450000000.0d0) then
tmp = x * y
else if (x <= 2.8d+257) then
tmp = t_0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -5e+115) {
tmp = x * y;
} else if (x <= -2.9e+94) {
tmp = t_0;
} else if (x <= -1.45e-46) {
tmp = x * y;
} else if (x <= 1.08e-79) {
tmp = z;
} else if (x <= 450000000.0) {
tmp = x * y;
} else if (x <= 2.8e+257) {
tmp = t_0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -5e+115: tmp = x * y elif x <= -2.9e+94: tmp = t_0 elif x <= -1.45e-46: tmp = x * y elif x <= 1.08e-79: tmp = z elif x <= 450000000.0: tmp = x * y elif x <= 2.8e+257: tmp = t_0 else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -5e+115) tmp = Float64(x * y); elseif (x <= -2.9e+94) tmp = t_0; elseif (x <= -1.45e-46) tmp = Float64(x * y); elseif (x <= 1.08e-79) tmp = z; elseif (x <= 450000000.0) tmp = Float64(x * y); elseif (x <= 2.8e+257) tmp = t_0; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -5e+115) tmp = x * y; elseif (x <= -2.9e+94) tmp = t_0; elseif (x <= -1.45e-46) tmp = x * y; elseif (x <= 1.08e-79) tmp = z; elseif (x <= 450000000.0) tmp = x * y; elseif (x <= 2.8e+257) tmp = t_0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -5e+115], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.9e+94], t$95$0, If[LessEqual[x, -1.45e-46], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.08e-79], z, If[LessEqual[x, 450000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.8e+257], t$95$0, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{+115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.9 \cdot 10^{+94}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-46}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.08 \cdot 10^{-79}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 450000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+257}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.00000000000000008e115 or -2.8999999999999998e94 < x < -1.45000000000000002e-46 or 1.0800000000000001e-79 < x < 4.5e8 or 2.7999999999999998e257 < x Initial program 94.0%
Taylor expanded in y around inf 68.2%
if -5.00000000000000008e115 < x < -2.8999999999999998e94 or 4.5e8 < x < 2.7999999999999998e257Initial program 96.7%
Taylor expanded in x around inf 99.2%
neg-mul-199.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 66.8%
mul-1-neg66.8%
distribute-rgt-neg-out66.8%
Simplified66.8%
if -1.45000000000000002e-46 < x < 1.0800000000000001e-79Initial program 100.0%
Taylor expanded in x around 0 82.3%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e-47) (not (<= x 3.8e-80))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-47) || !(x <= 3.8e-80)) {
tmp = x * (y - z);
} 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 <= (-5.6d-47)) .or. (.not. (x <= 3.8d-80))) then
tmp = x * (y - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-47) || !(x <= 3.8e-80)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e-47) or not (x <= 3.8e-80): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-47) || !(x <= 3.8e-80)) tmp = Float64(x * Float64(y - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.6e-47) || ~((x <= 3.8e-80))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-47], N[Not[LessEqual[x, 3.8e-80]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-47} \lor \neg \left(x \leq 3.8 \cdot 10^{-80}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.59999999999999986e-47 or 3.79999999999999967e-80 < x Initial program 95.0%
Taylor expanded in x around inf 96.2%
neg-mul-196.2%
sub-neg96.2%
Simplified96.2%
if -5.59999999999999986e-47 < x < 3.79999999999999967e-80Initial program 100.0%
Taylor expanded in x around 0 82.3%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-46) (not (<= x 1.08e-79))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-46) || !(x <= 1.08e-79)) {
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 <= (-3.1d-46)) .or. (.not. (x <= 1.08d-79))) 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 <= -3.1e-46) || !(x <= 1.08e-79)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-46) or not (x <= 1.08e-79): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-46) || !(x <= 1.08e-79)) 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 <= -3.1e-46) || ~((x <= 1.08e-79))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-46], N[Not[LessEqual[x, 1.08e-79]], $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 -3.1 \cdot 10^{-46} \lor \neg \left(x \leq 1.08 \cdot 10^{-79}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -3.1000000000000001e-46 or 1.0800000000000001e-79 < x Initial program 95.0%
Taylor expanded in x around inf 96.2%
neg-mul-196.2%
sub-neg96.2%
Simplified96.2%
if -3.1000000000000001e-46 < x < 1.0800000000000001e-79Initial program 100.0%
Taylor expanded in y around 0 82.3%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 2.2e-32))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 2.2e-32)) {
tmp = x * (y - 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 ((x <= (-1.0d0)) .or. (.not. (x <= 2.2d-32))) then
tmp = x * (y - 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 ((x <= -1.0) || !(x <= 2.2e-32)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 2.2e-32): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 2.2e-32)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 2.2e-32))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 2.2e-32]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 2.2 \cdot 10^{-32}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 2.2e-32 < x Initial program 94.5%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
sub-neg98.8%
Simplified98.8%
if -1 < x < 2.2e-32Initial program 100.0%
*-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
associate-+r+100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 99.6%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e-46) (* x y) (if (<= x 1.08e-79) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-46) {
tmp = x * y;
} else if (x <= 1.08e-79) {
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.65d-46)) then
tmp = x * y
else if (x <= 1.08d-79) 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.65e-46) {
tmp = x * y;
} else if (x <= 1.08e-79) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e-46: tmp = x * y elif x <= 1.08e-79: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e-46) tmp = Float64(x * y); elseif (x <= 1.08e-79) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e-46) tmp = x * y; elseif (x <= 1.08e-79) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e-46], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.08e-79], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-46}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.08 \cdot 10^{-79}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.65000000000000007e-46 or 1.0800000000000001e-79 < x Initial program 95.0%
Taylor expanded in y around inf 55.1%
if -1.65000000000000007e-46 < x < 1.0800000000000001e-79Initial program 100.0%
Taylor expanded in x around 0 82.3%
Final simplification65.2%
(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 96.9%
*-commutative96.9%
distribute-lft-out--96.9%
*-rgt-identity96.9%
cancel-sign-sub-inv96.9%
+-commutative96.9%
associate-+r+96.9%
*-commutative96.9%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.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 96.9%
Taylor expanded in x around 0 33.8%
Final simplification33.8%
herbie shell --seed 2023285
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))