
(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%
*-commutative99.2%
neg-mul-199.2%
associate-*r*99.2%
*-commutative99.2%
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
(let* ((t_0 (* x (- z))))
(if (<= x -7e+77)
(* x y)
(if (<= x -4500000000000.0)
t_0
(if (<= x -5.6e-144)
(* x y)
(if (<= x 1.3e-167)
z
(if (<= x 60000000000.0)
(* x y)
(if (<= x 7.6e+248) t_0 (* x y)))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -7e+77) {
tmp = x * y;
} else if (x <= -4500000000000.0) {
tmp = t_0;
} else if (x <= -5.6e-144) {
tmp = x * y;
} else if (x <= 1.3e-167) {
tmp = z;
} else if (x <= 60000000000.0) {
tmp = x * y;
} else if (x <= 7.6e+248) {
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 = x * -z
if (x <= (-7d+77)) then
tmp = x * y
else if (x <= (-4500000000000.0d0)) then
tmp = t_0
else if (x <= (-5.6d-144)) then
tmp = x * y
else if (x <= 1.3d-167) then
tmp = z
else if (x <= 60000000000.0d0) then
tmp = x * y
else if (x <= 7.6d+248) 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 = x * -z;
double tmp;
if (x <= -7e+77) {
tmp = x * y;
} else if (x <= -4500000000000.0) {
tmp = t_0;
} else if (x <= -5.6e-144) {
tmp = x * y;
} else if (x <= 1.3e-167) {
tmp = z;
} else if (x <= 60000000000.0) {
tmp = x * y;
} else if (x <= 7.6e+248) {
tmp = t_0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if x <= -7e+77: tmp = x * y elif x <= -4500000000000.0: tmp = t_0 elif x <= -5.6e-144: tmp = x * y elif x <= 1.3e-167: tmp = z elif x <= 60000000000.0: tmp = x * y elif x <= 7.6e+248: tmp = t_0 else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -7e+77) tmp = Float64(x * y); elseif (x <= -4500000000000.0) tmp = t_0; elseif (x <= -5.6e-144) tmp = Float64(x * y); elseif (x <= 1.3e-167) tmp = z; elseif (x <= 60000000000.0) tmp = Float64(x * y); elseif (x <= 7.6e+248) tmp = t_0; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (x <= -7e+77) tmp = x * y; elseif (x <= -4500000000000.0) tmp = t_0; elseif (x <= -5.6e-144) tmp = x * y; elseif (x <= 1.3e-167) tmp = z; elseif (x <= 60000000000.0) tmp = x * y; elseif (x <= 7.6e+248) tmp = t_0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -7e+77], N[(x * y), $MachinePrecision], If[LessEqual[x, -4500000000000.0], t$95$0, If[LessEqual[x, -5.6e-144], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.3e-167], z, If[LessEqual[x, 60000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.6e+248], t$95$0, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -7 \cdot 10^{+77}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -4500000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.6 \cdot 10^{-144}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-167}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 60000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{+248}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -7.0000000000000003e77 or -4.5e12 < x < -5.59999999999999995e-144 or 1.2999999999999999e-167 < x < 6e10 or 7.6000000000000002e248 < x Initial program 98.3%
Taylor expanded in y around inf 65.2%
if -7.0000000000000003e77 < x < -4.5e12 or 6e10 < x < 7.6000000000000002e248Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-rgt1-in99.9%
associate-+r+100.0%
cancel-sign-sub-inv100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 99.4%
Taylor expanded in y around 0 71.8%
mul-1-neg71.8%
distribute-rgt-neg-out71.8%
Simplified71.8%
if -5.59999999999999995e-144 < x < 1.2999999999999999e-167Initial program 100.0%
Taylor expanded in x around 0 77.7%
Final simplification70.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -105.0)
(not (or (<= z 2.2e+17) (and (not (<= z 7e+66)) (<= z 6.5e+101)))))
(* z (- 1.0 x))
(* x (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -105.0) || !((z <= 2.2e+17) || (!(z <= 7e+66) && (z <= 6.5e+101)))) {
tmp = z * (1.0 - x);
} else {
tmp = x * (y - 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 ((z <= (-105.0d0)) .or. (.not. (z <= 2.2d+17) .or. (.not. (z <= 7d+66)) .and. (z <= 6.5d+101))) then
tmp = z * (1.0d0 - x)
else
tmp = x * (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -105.0) || !((z <= 2.2e+17) || (!(z <= 7e+66) && (z <= 6.5e+101)))) {
tmp = z * (1.0 - x);
} else {
tmp = x * (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -105.0) or not ((z <= 2.2e+17) or (not (z <= 7e+66) and (z <= 6.5e+101))): tmp = z * (1.0 - x) else: tmp = x * (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -105.0) || !((z <= 2.2e+17) || (!(z <= 7e+66) && (z <= 6.5e+101)))) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(x * Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -105.0) || ~(((z <= 2.2e+17) || (~((z <= 7e+66)) && (z <= 6.5e+101))))) tmp = z * (1.0 - x); else tmp = x * (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -105.0], N[Not[Or[LessEqual[z, 2.2e+17], And[N[Not[LessEqual[z, 7e+66]], $MachinePrecision], LessEqual[z, 6.5e+101]]]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -105 \lor \neg \left(z \leq 2.2 \cdot 10^{+17} \lor \neg \left(z \leq 7 \cdot 10^{+66}\right) \land z \leq 6.5 \cdot 10^{+101}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - z\right)\\
\end{array}
\end{array}
if z < -105 or 2.2e17 < z < 6.9999999999999994e66 or 6.50000000000000016e101 < z Initial program 98.1%
Taylor expanded in y around 0 89.3%
if -105 < z < 2.2e17 or 6.9999999999999994e66 < z < 6.50000000000000016e101Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-rgt1-in100.0%
associate-+r+100.0%
cancel-sign-sub-inv100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 85.2%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-64) (not (<= z 1.25e-67))) (* z (- 1.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-64) || !(z <= 1.25e-67)) {
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 ((z <= (-4.5d-64)) .or. (.not. (z <= 1.25d-67))) 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 ((z <= -4.5e-64) || !(z <= 1.25e-67)) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-64) or not (z <= 1.25e-67): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-64) || !(z <= 1.25e-67)) 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 ((z <= -4.5e-64) || ~((z <= 1.25e-67))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-64], N[Not[LessEqual[z, 1.25e-67]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-64} \lor \neg \left(z \leq 1.25 \cdot 10^{-67}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -4.5000000000000001e-64 or 1.25e-67 < z Initial program 98.6%
Taylor expanded in y around 0 82.1%
if -4.5000000000000001e-64 < z < 1.25e-67Initial program 100.0%
Taylor expanded in y around inf 73.1%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (<= x -5.6e-144) (* x y) (if (<= x 1.3e-167) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.6e-144) {
tmp = x * y;
} else if (x <= 1.3e-167) {
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 <= (-5.6d-144)) then
tmp = x * y
else if (x <= 1.3d-167) 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 <= -5.6e-144) {
tmp = x * y;
} else if (x <= 1.3e-167) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.6e-144: tmp = x * y elif x <= 1.3e-167: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.6e-144) tmp = Float64(x * y); elseif (x <= 1.3e-167) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.6e-144) tmp = x * y; elseif (x <= 1.3e-167) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.6e-144], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.3e-167], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-144}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-167}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.59999999999999995e-144 or 1.2999999999999999e-167 < x Initial program 99.0%
Taylor expanded in y around inf 51.7%
if -5.59999999999999995e-144 < x < 1.2999999999999999e-167Initial program 100.0%
Taylor expanded in x around 0 77.7%
Final simplification57.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 99.2%
sub-neg99.2%
+-commutative99.2%
distribute-rgt1-in99.2%
associate-+r+99.2%
cancel-sign-sub-inv99.2%
fma-def99.2%
Simplified99.2%
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 99.2%
Taylor expanded in x around 0 29.7%
Final simplification29.7%
herbie shell --seed 2023214
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))