
(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 98.4%
*-commutative98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
+-commutative98.4%
associate-+r+98.4%
*-commutative98.4%
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
(if (<= x -2.95e+190)
(* x y)
(if (<= x -1250000000.0)
(* x (- z))
(if (<= x -3.4e-78) (* x y) (if (<= x 3.6e-14) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.95e+190) {
tmp = x * y;
} else if (x <= -1250000000.0) {
tmp = x * -z;
} else if (x <= -3.4e-78) {
tmp = x * y;
} else if (x <= 3.6e-14) {
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 <= (-2.95d+190)) then
tmp = x * y
else if (x <= (-1250000000.0d0)) then
tmp = x * -z
else if (x <= (-3.4d-78)) then
tmp = x * y
else if (x <= 3.6d-14) 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 <= -2.95e+190) {
tmp = x * y;
} else if (x <= -1250000000.0) {
tmp = x * -z;
} else if (x <= -3.4e-78) {
tmp = x * y;
} else if (x <= 3.6e-14) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.95e+190: tmp = x * y elif x <= -1250000000.0: tmp = x * -z elif x <= -3.4e-78: tmp = x * y elif x <= 3.6e-14: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.95e+190) tmp = Float64(x * y); elseif (x <= -1250000000.0) tmp = Float64(x * Float64(-z)); elseif (x <= -3.4e-78) tmp = Float64(x * y); elseif (x <= 3.6e-14) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.95e+190) tmp = x * y; elseif (x <= -1250000000.0) tmp = x * -z; elseif (x <= -3.4e-78) tmp = x * y; elseif (x <= 3.6e-14) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.95e+190], N[(x * y), $MachinePrecision], If[LessEqual[x, -1250000000.0], N[(x * (-z)), $MachinePrecision], If[LessEqual[x, -3.4e-78], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.6e-14], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.95 \cdot 10^{+190}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1250000000:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-78}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.94999999999999986e190 or -1.25e9 < x < -3.40000000000000012e-78 or 3.5999999999999998e-14 < x Initial program 96.0%
Taylor expanded in y around inf 66.4%
if -2.94999999999999986e190 < x < -1.25e9Initial program 100.0%
Taylor expanded in y around 0 67.4%
Taylor expanded in x around inf 65.1%
associate-*r*65.1%
mul-1-neg65.1%
Simplified65.1%
if -3.40000000000000012e-78 < x < 3.5999999999999998e-14Initial program 100.0%
Taylor expanded in x around 0 78.7%
Final simplification71.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e-75) (not (<= x 0.0005))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-75) || !(x <= 0.0005)) {
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 <= (-1.65d-75)) .or. (.not. (x <= 0.0005d0))) 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 <= -1.65e-75) || !(x <= 0.0005)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e-75) or not (x <= 0.0005): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e-75) || !(x <= 0.0005)) 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 <= -1.65e-75) || ~((x <= 0.0005))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e-75], N[Not[LessEqual[x, 0.0005]], $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 -1.65 \cdot 10^{-75} \lor \neg \left(x \leq 0.0005\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1.65e-75 or 5.0000000000000001e-4 < x Initial program 97.1%
Taylor expanded in x around inf 96.2%
neg-mul-196.2%
+-commutative96.2%
unsub-neg96.2%
Simplified96.2%
if -1.65e-75 < x < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -45000.0) (not (<= x 0.057))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -45000.0) || !(x <= 0.057)) {
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 <= (-45000.0d0)) .or. (.not. (x <= 0.057d0))) 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 <= -45000.0) || !(x <= 0.057)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -45000.0) or not (x <= 0.057): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -45000.0) || !(x <= 0.057)) 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 <= -45000.0) || ~((x <= 0.057))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -45000.0], N[Not[LessEqual[x, 0.057]], $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 -45000 \lor \neg \left(x \leq 0.057\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -45000 or 0.0570000000000000021 < x Initial program 96.8%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
+-commutative98.7%
unsub-neg98.7%
Simplified98.7%
if -45000 < x < 0.0570000000000000021Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
+-commutative100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 98.9%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.15e+38) (* x y) (if (<= y 1.65e-39) (* z (- 1.0 x)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.15e+38) {
tmp = x * y;
} else if (y <= 1.65e-39) {
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 <= (-1.15d+38)) then
tmp = x * y
else if (y <= 1.65d-39) 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 <= -1.15e+38) {
tmp = x * y;
} else if (y <= 1.65e-39) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.15e+38: tmp = x * y elif y <= 1.65e-39: tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.15e+38) tmp = Float64(x * y); elseif (y <= 1.65e-39) 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 <= -1.15e+38) tmp = x * y; elseif (y <= 1.65e-39) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.15e+38], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.65e-39], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+38}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-39}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1500000000000001e38 or 1.64999999999999992e-39 < y Initial program 96.8%
Taylor expanded in y around inf 69.3%
if -1.1500000000000001e38 < y < 1.64999999999999992e-39Initial program 100.0%
Taylor expanded in y around 0 86.1%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= x -2.3e-71) (* x y) (if (<= x 1.15e-14) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-71) {
tmp = x * y;
} else if (x <= 1.15e-14) {
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 <= (-2.3d-71)) then
tmp = x * y
else if (x <= 1.15d-14) 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 <= -2.3e-71) {
tmp = x * y;
} else if (x <= 1.15e-14) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.3e-71: tmp = x * y elif x <= 1.15e-14: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.3e-71) tmp = Float64(x * y); elseif (x <= 1.15e-14) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.3e-71) tmp = x * y; elseif (x <= 1.15e-14) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.3e-71], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.15e-14], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-71}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.2999999999999998e-71 or 1.14999999999999999e-14 < x Initial program 97.1%
Taylor expanded in y around inf 57.9%
if -2.2999999999999998e-71 < x < 1.14999999999999999e-14Initial program 100.0%
Taylor expanded in x around 0 78.7%
Final simplification67.3%
(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 98.4%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 98.4%
*-commutative98.4%
neg-mul-198.4%
distribute-lft-in98.4%
*-rgt-identity98.4%
associate-+l+98.4%
+-commutative98.4%
distribute-rgt-neg-out98.4%
unsub-neg98.4%
distribute-rgt-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 98.4%
Taylor expanded in x around 0 38.8%
Final simplification38.8%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))