
(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 97.3%
*-commutative97.3%
distribute-lft-out--97.3%
*-rgt-identity97.3%
cancel-sign-sub-inv97.3%
+-commutative97.3%
associate-+r+97.3%
+-commutative97.3%
*-commutative97.3%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.15e-26)
(* x y)
(if (<= x -1.6e-109)
z
(if (<= x -5.8e-125)
(* x y)
(if (<= x 2.1e-83)
z
(if (or (<= x 8.8e+39) (and (not (<= x 3e+101)) (<= x 2.3e+159)))
(* x y)
(* x (- z))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-26) {
tmp = x * y;
} else if (x <= -1.6e-109) {
tmp = z;
} else if (x <= -5.8e-125) {
tmp = x * y;
} else if (x <= 2.1e-83) {
tmp = z;
} else if ((x <= 8.8e+39) || (!(x <= 3e+101) && (x <= 2.3e+159))) {
tmp = x * y;
} else {
tmp = 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 <= (-2.15d-26)) then
tmp = x * y
else if (x <= (-1.6d-109)) then
tmp = z
else if (x <= (-5.8d-125)) then
tmp = x * y
else if (x <= 2.1d-83) then
tmp = z
else if ((x <= 8.8d+39) .or. (.not. (x <= 3d+101)) .and. (x <= 2.3d+159)) then
tmp = x * y
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-26) {
tmp = x * y;
} else if (x <= -1.6e-109) {
tmp = z;
} else if (x <= -5.8e-125) {
tmp = x * y;
} else if (x <= 2.1e-83) {
tmp = z;
} else if ((x <= 8.8e+39) || (!(x <= 3e+101) && (x <= 2.3e+159))) {
tmp = x * y;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.15e-26: tmp = x * y elif x <= -1.6e-109: tmp = z elif x <= -5.8e-125: tmp = x * y elif x <= 2.1e-83: tmp = z elif (x <= 8.8e+39) or (not (x <= 3e+101) and (x <= 2.3e+159)): tmp = x * y else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.15e-26) tmp = Float64(x * y); elseif (x <= -1.6e-109) tmp = z; elseif (x <= -5.8e-125) tmp = Float64(x * y); elseif (x <= 2.1e-83) tmp = z; elseif ((x <= 8.8e+39) || (!(x <= 3e+101) && (x <= 2.3e+159))) tmp = Float64(x * y); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.15e-26) tmp = x * y; elseif (x <= -1.6e-109) tmp = z; elseif (x <= -5.8e-125) tmp = x * y; elseif (x <= 2.1e-83) tmp = z; elseif ((x <= 8.8e+39) || (~((x <= 3e+101)) && (x <= 2.3e+159))) tmp = x * y; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.15e-26], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.6e-109], z, If[LessEqual[x, -5.8e-125], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.1e-83], z, If[Or[LessEqual[x, 8.8e+39], And[N[Not[LessEqual[x, 3e+101]], $MachinePrecision], LessEqual[x, 2.3e+159]]], N[(x * y), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-26}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-109}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-83}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+39} \lor \neg \left(x \leq 3 \cdot 10^{+101}\right) \land x \leq 2.3 \cdot 10^{+159}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -2.14999999999999994e-26 or -1.6000000000000001e-109 < x < -5.8000000000000004e-125 or 2.0999999999999999e-83 < x < 8.8000000000000006e39 or 2.99999999999999993e101 < x < 2.29999999999999995e159Initial program 96.4%
Taylor expanded in y around inf 67.0%
if -2.14999999999999994e-26 < x < -1.6000000000000001e-109 or -5.8000000000000004e-125 < x < 2.0999999999999999e-83Initial program 100.0%
Taylor expanded in x around 0 80.5%
if 8.8000000000000006e39 < x < 2.99999999999999993e101 or 2.29999999999999995e159 < x Initial program 92.7%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 71.7%
associate-*r*71.7%
mul-1-neg71.7%
Simplified71.7%
Final simplification73.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y z))))
(if (<= x -2.1e-25)
t_0
(if (<= x -5.4e-110)
z
(if (<= x -1.12e-125) (* x y) (if (<= x 3.6e-83) z t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.1e-25) {
tmp = t_0;
} else if (x <= -5.4e-110) {
tmp = z;
} else if (x <= -1.12e-125) {
tmp = x * y;
} else if (x <= 3.6e-83) {
tmp = z;
} else {
tmp = t_0;
}
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 = x * (y - z)
if (x <= (-2.1d-25)) then
tmp = t_0
else if (x <= (-5.4d-110)) then
tmp = z
else if (x <= (-1.12d-125)) then
tmp = x * y
else if (x <= 3.6d-83) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.1e-25) {
tmp = t_0;
} else if (x <= -5.4e-110) {
tmp = z;
} else if (x <= -1.12e-125) {
tmp = x * y;
} else if (x <= 3.6e-83) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -2.1e-25: tmp = t_0 elif x <= -5.4e-110: tmp = z elif x <= -1.12e-125: tmp = x * y elif x <= 3.6e-83: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -2.1e-25) tmp = t_0; elseif (x <= -5.4e-110) tmp = z; elseif (x <= -1.12e-125) tmp = Float64(x * y); elseif (x <= 3.6e-83) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -2.1e-25) tmp = t_0; elseif (x <= -5.4e-110) tmp = z; elseif (x <= -1.12e-125) tmp = x * y; elseif (x <= 3.6e-83) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.1e-25], t$95$0, If[LessEqual[x, -5.4e-110], z, If[LessEqual[x, -1.12e-125], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.6e-83], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -2.1 \cdot 10^{-25}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{-110}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -1.12 \cdot 10^{-125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-83}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -2.10000000000000002e-25 or 3.60000000000000012e-83 < x Initial program 95.3%
Taylor expanded in x around inf 94.5%
mul-1-neg94.5%
sub-neg94.5%
Simplified94.5%
if -2.10000000000000002e-25 < x < -5.3999999999999996e-110 or -1.11999999999999997e-125 < x < 3.60000000000000012e-83Initial program 100.0%
Taylor expanded in x around 0 80.5%
if -5.3999999999999996e-110 < x < -1.11999999999999997e-125Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification89.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.9e-25)
(not
(or (<= x -5.1e-110) (and (not (<= x -7.2e-125)) (<= x 3.3e-83)))))
(* x y)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e-25) || !((x <= -5.1e-110) || (!(x <= -7.2e-125) && (x <= 3.3e-83)))) {
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 <= (-1.9d-25)) .or. (.not. (x <= (-5.1d-110)) .or. (.not. (x <= (-7.2d-125))) .and. (x <= 3.3d-83))) 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 <= -1.9e-25) || !((x <= -5.1e-110) || (!(x <= -7.2e-125) && (x <= 3.3e-83)))) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e-25) or not ((x <= -5.1e-110) or (not (x <= -7.2e-125) and (x <= 3.3e-83))): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e-25) || !((x <= -5.1e-110) || (!(x <= -7.2e-125) && (x <= 3.3e-83)))) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.9e-25) || ~(((x <= -5.1e-110) || (~((x <= -7.2e-125)) && (x <= 3.3e-83))))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e-25], N[Not[Or[LessEqual[x, -5.1e-110], And[N[Not[LessEqual[x, -7.2e-125]], $MachinePrecision], LessEqual[x, 3.3e-83]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-25} \lor \neg \left(x \leq -5.1 \cdot 10^{-110} \lor \neg \left(x \leq -7.2 \cdot 10^{-125}\right) \land x \leq 3.3 \cdot 10^{-83}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.8999999999999999e-25 or -5.1000000000000002e-110 < x < -7.2000000000000004e-125 or 3.2999999999999999e-83 < x Initial program 95.4%
Taylor expanded in y around inf 60.8%
if -1.8999999999999999e-25 < x < -5.1000000000000002e-110 or -7.2000000000000004e-125 < x < 3.2999999999999999e-83Initial program 100.0%
Taylor expanded in x around 0 80.5%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -370000.0) (not (<= x 1.1e-9))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -370000.0) || !(x <= 1.1e-9)) {
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 <= (-370000.0d0)) .or. (.not. (x <= 1.1d-9))) 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 <= -370000.0) || !(x <= 1.1e-9)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -370000.0) or not (x <= 1.1e-9): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -370000.0) || !(x <= 1.1e-9)) 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 <= -370000.0) || ~((x <= 1.1e-9))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -370000.0], N[Not[LessEqual[x, 1.1e-9]], $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 -370000 \lor \neg \left(x \leq 1.1 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -3.7e5 or 1.0999999999999999e-9 < x Initial program 94.4%
Taylor expanded in x around inf 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
if -3.7e5 < x < 1.0999999999999999e-9Initial program 100.0%
+-commutative100.0%
*-commutative100.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 0 98.8%
mul-1-neg98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
Simplified98.8%
sub-neg98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
remove-double-neg98.8%
Applied egg-rr98.8%
Final simplification99.1%
(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.3%
+-commutative97.3%
*-commutative97.3%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
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 97.3%
Taylor expanded in x around 0 36.6%
Final simplification36.6%
herbie shell --seed 2024024
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))