
(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.8%
*-commutative98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
associate-+r+98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -3.1e+211)
t_0
(if (<= x -9e-9)
(* x y)
(if (<= x 7.5e-16) z (if (<= x 4.1e+89) (* x y) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -3.1e+211) {
tmp = t_0;
} else if (x <= -9e-9) {
tmp = x * y;
} else if (x <= 7.5e-16) {
tmp = z;
} else if (x <= 4.1e+89) {
tmp = x * y;
} 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 = z * -x
if (x <= (-3.1d+211)) then
tmp = t_0
else if (x <= (-9d-9)) then
tmp = x * y
else if (x <= 7.5d-16) then
tmp = z
else if (x <= 4.1d+89) then
tmp = x * y
else
tmp = t_0
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 <= -3.1e+211) {
tmp = t_0;
} else if (x <= -9e-9) {
tmp = x * y;
} else if (x <= 7.5e-16) {
tmp = z;
} else if (x <= 4.1e+89) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -3.1e+211: tmp = t_0 elif x <= -9e-9: tmp = x * y elif x <= 7.5e-16: tmp = z elif x <= 4.1e+89: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -3.1e+211) tmp = t_0; elseif (x <= -9e-9) tmp = Float64(x * y); elseif (x <= 7.5e-16) tmp = z; elseif (x <= 4.1e+89) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -3.1e+211) tmp = t_0; elseif (x <= -9e-9) tmp = x * y; elseif (x <= 7.5e-16) tmp = z; elseif (x <= 4.1e+89) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -3.1e+211], t$95$0, If[LessEqual[x, -9e-9], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.5e-16], z, If[LessEqual[x, 4.1e+89], N[(x * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{+211}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-9}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-16}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+89}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.1000000000000002e211 or 4.09999999999999985e89 < x Initial program 95.8%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 72.5%
mul-1-neg72.5%
distribute-rgt-neg-in72.5%
Simplified72.5%
if -3.1000000000000002e211 < x < -8.99999999999999953e-9 or 7.5e-16 < x < 4.09999999999999985e89Initial program 100.0%
Taylor expanded in y around inf 62.7%
if -8.99999999999999953e-9 < x < 7.5e-16Initial program 100.0%
Taylor expanded in x around 0 70.2%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.6%
Taylor expanded in x around inf 99.6%
neg-mul-199.6%
sub-neg99.6%
Simplified99.6%
if -1 < x < 1Initial 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%
*-commutative100.0%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 99.0%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.2e-22) (not (<= z 2.7e-16))) (* z (- 1.0 x)) (* x (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.2e-22) || !(z <= 2.7e-16)) {
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 <= (-1.2d-22)) .or. (.not. (z <= 2.7d-16))) 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 <= -1.2e-22) || !(z <= 2.7e-16)) {
tmp = z * (1.0 - x);
} else {
tmp = x * (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.2e-22) or not (z <= 2.7e-16): tmp = z * (1.0 - x) else: tmp = x * (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.2e-22) || !(z <= 2.7e-16)) 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 <= -1.2e-22) || ~((z <= 2.7e-16))) tmp = z * (1.0 - x); else tmp = x * (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.2e-22], N[Not[LessEqual[z, 2.7e-16]], $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 -1.2 \cdot 10^{-22} \lor \neg \left(z \leq 2.7 \cdot 10^{-16}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - z\right)\\
\end{array}
\end{array}
if z < -1.20000000000000001e-22 or 2.69999999999999999e-16 < z Initial program 98.0%
Taylor expanded in y around 0 87.6%
if -1.20000000000000001e-22 < z < 2.69999999999999999e-16Initial program 99.9%
Taylor expanded in x around inf 83.7%
neg-mul-183.7%
sub-neg83.7%
Simplified83.7%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-9) (not (<= x 1.25e-15))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-9) || !(x <= 1.25e-15)) {
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 <= (-3.8d-9)) .or. (.not. (x <= 1.25d-15))) 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 <= -3.8e-9) || !(x <= 1.25e-15)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-9) or not (x <= 1.25e-15): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-9) || !(x <= 1.25e-15)) 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 <= -3.8e-9) || ~((x <= 1.25e-15))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-9], N[Not[LessEqual[x, 1.25e-15]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-9} \lor \neg \left(x \leq 1.25 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.80000000000000011e-9 or 1.25e-15 < x Initial program 97.7%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
sub-neg98.2%
Simplified98.2%
if -3.80000000000000011e-9 < x < 1.25e-15Initial program 100.0%
Taylor expanded in x around 0 70.2%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+24) (not (<= y 1.95e+30))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+24) || !(y <= 1.95e+30)) {
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 ((y <= (-2.5d+24)) .or. (.not. (y <= 1.95d+30))) 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 ((y <= -2.5e+24) || !(y <= 1.95e+30)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+24) or not (y <= 1.95e+30): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+24) || !(y <= 1.95e+30)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.5e+24) || ~((y <= 1.95e+30))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+24], N[Not[LessEqual[y, 1.95e+30]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+24} \lor \neg \left(y \leq 1.95 \cdot 10^{+30}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.50000000000000023e24 or 1.95000000000000005e30 < y Initial program 97.6%
Taylor expanded in y around inf 70.0%
if -2.50000000000000023e24 < y < 1.95000000000000005e30Initial program 100.0%
Taylor expanded in x around 0 50.5%
Final simplification60.0%
(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.8%
*-commutative98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
associate-+r+98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-undefine100.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 98.8%
Taylor expanded in x around 0 35.4%
herbie shell --seed 2024096
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))