
(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 96.5%
sub-neg96.5%
+-commutative96.5%
distribute-lft1-in96.5%
associate-+r+96.5%
+-commutative96.5%
distribute-lft-neg-out96.5%
distribute-rgt-neg-out96.5%
distribute-lft-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= x -1.45e+222)
t_0
(if (<= x -3.05e-9)
(* x y)
(if (<= x 1.04e-10) z (if (<= x 6.4e+65) (* x y) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -1.45e+222) {
tmp = t_0;
} else if (x <= -3.05e-9) {
tmp = x * y;
} else if (x <= 1.04e-10) {
tmp = z;
} else if (x <= 6.4e+65) {
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 = x * -z
if (x <= (-1.45d+222)) then
tmp = t_0
else if (x <= (-3.05d-9)) then
tmp = x * y
else if (x <= 1.04d-10) then
tmp = z
else if (x <= 6.4d+65) 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 = x * -z;
double tmp;
if (x <= -1.45e+222) {
tmp = t_0;
} else if (x <= -3.05e-9) {
tmp = x * y;
} else if (x <= 1.04e-10) {
tmp = z;
} else if (x <= 6.4e+65) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if x <= -1.45e+222: tmp = t_0 elif x <= -3.05e-9: tmp = x * y elif x <= 1.04e-10: tmp = z elif x <= 6.4e+65: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -1.45e+222) tmp = t_0; elseif (x <= -3.05e-9) tmp = Float64(x * y); elseif (x <= 1.04e-10) tmp = z; elseif (x <= 6.4e+65) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (x <= -1.45e+222) tmp = t_0; elseif (x <= -3.05e-9) tmp = x * y; elseif (x <= 1.04e-10) tmp = z; elseif (x <= 6.4e+65) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -1.45e+222], t$95$0, If[LessEqual[x, -3.05e-9], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.04e-10], z, If[LessEqual[x, 6.4e+65], N[(x * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{+222}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -3.05 \cdot 10^{-9}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.04 \cdot 10^{-10}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 6.4 \cdot 10^{+65}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.44999999999999991e222 or 6.40000000000000014e65 < x Initial program 91.7%
+-commutative91.7%
remove-double-neg91.7%
distribute-rgt-neg-out91.7%
neg-sub091.7%
neg-sub091.7%
*-commutative91.7%
distribute-lft-neg-in91.7%
remove-double-neg91.7%
distribute-rgt-out--91.7%
*-lft-identity91.7%
associate-+l-91.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 68.6%
Taylor expanded in x around inf 68.6%
neg-mul-168.6%
distribute-rgt-neg-in68.6%
Simplified68.6%
if -1.44999999999999991e222 < x < -3.05e-9 or 1.04e-10 < x < 6.40000000000000014e65Initial program 95.2%
+-commutative95.2%
remove-double-neg95.2%
distribute-rgt-neg-out95.2%
neg-sub095.2%
neg-sub095.2%
*-commutative95.2%
distribute-lft-neg-in95.2%
remove-double-neg95.2%
distribute-rgt-out--95.2%
*-lft-identity95.2%
associate-+l-95.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 59.1%
if -3.05e-9 < x < 1.04e-10Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 71.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-44) (not (<= z 1.62e+35))) (- z (* x z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-44) || !(z <= 1.62e+35)) {
tmp = z - (x * 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 ((z <= (-6.5d-44)) .or. (.not. (z <= 1.62d+35))) then
tmp = z - (x * 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 ((z <= -6.5e-44) || !(z <= 1.62e+35)) {
tmp = z - (x * z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-44) or not (z <= 1.62e+35): tmp = z - (x * z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-44) || !(z <= 1.62e+35)) tmp = Float64(z - Float64(x * z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e-44) || ~((z <= 1.62e+35))) tmp = z - (x * z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-44], N[Not[LessEqual[z, 1.62e+35]], $MachinePrecision]], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-44} \lor \neg \left(z \leq 1.62 \cdot 10^{+35}\right):\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if z < -6.5e-44 or 1.62e35 < z Initial program 93.2%
+-commutative93.2%
remove-double-neg93.2%
distribute-rgt-neg-out93.2%
neg-sub093.2%
neg-sub093.2%
*-commutative93.2%
distribute-lft-neg-in93.2%
remove-double-neg93.2%
distribute-rgt-out--93.2%
*-lft-identity93.2%
associate-+l-93.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 89.1%
if -6.5e-44 < z < 1.62e35Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.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 89.7%
associate-*r*89.7%
neg-mul-189.7%
Simplified89.7%
cancel-sign-sub89.7%
+-commutative89.7%
Applied egg-rr89.7%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.9e+221) (not (<= x 8.5e+62))) (* x (- z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e+221) || !(x <= 8.5e+62)) {
tmp = x * -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 <= (-4.9d+221)) .or. (.not. (x <= 8.5d+62))) then
tmp = x * -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 <= -4.9e+221) || !(x <= 8.5e+62)) {
tmp = x * -z;
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.9e+221) or not (x <= 8.5e+62): tmp = x * -z else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.9e+221) || !(x <= 8.5e+62)) tmp = Float64(x * Float64(-z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.9e+221) || ~((x <= 8.5e+62))) tmp = x * -z; else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.9e+221], N[Not[LessEqual[x, 8.5e+62]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{+221} \lor \neg \left(x \leq 8.5 \cdot 10^{+62}\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -4.8999999999999999e221 or 8.4999999999999997e62 < x Initial program 91.7%
+-commutative91.7%
remove-double-neg91.7%
distribute-rgt-neg-out91.7%
neg-sub091.7%
neg-sub091.7%
*-commutative91.7%
distribute-lft-neg-in91.7%
remove-double-neg91.7%
distribute-rgt-out--91.7%
*-lft-identity91.7%
associate-+l-91.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 68.6%
Taylor expanded in x around inf 68.6%
neg-mul-168.6%
distribute-rgt-neg-in68.6%
Simplified68.6%
if -4.8999999999999999e221 < x < 8.4999999999999997e62Initial program 98.4%
+-commutative98.4%
remove-double-neg98.4%
distribute-rgt-neg-out98.4%
neg-sub098.4%
neg-sub098.4%
*-commutative98.4%
distribute-lft-neg-in98.4%
remove-double-neg98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 86.3%
associate-*r*86.3%
neg-mul-186.3%
Simplified86.3%
cancel-sign-sub86.3%
+-commutative86.3%
Applied egg-rr86.3%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e-12) (not (<= x 4e-5))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e-12) || !(x <= 4e-5)) {
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.95d-12)) .or. (.not. (x <= 4d-5))) 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.95e-12) || !(x <= 4e-5)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e-12) or not (x <= 4e-5): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e-12) || !(x <= 4e-5)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.95e-12) || ~((x <= 4e-5))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e-12], N[Not[LessEqual[x, 4e-5]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-12} \lor \neg \left(x \leq 4 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.94999999999999997e-12 or 4.00000000000000033e-5 < x Initial program 93.3%
+-commutative93.3%
remove-double-neg93.3%
distribute-rgt-neg-out93.3%
neg-sub093.3%
neg-sub093.3%
*-commutative93.3%
distribute-lft-neg-in93.3%
remove-double-neg93.3%
distribute-rgt-out--93.3%
*-lft-identity93.3%
associate-+l-93.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 48.7%
if -1.94999999999999997e-12 < x < 4.00000000000000033e-5Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 71.3%
Final simplification59.4%
(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.5%
+-commutative96.5%
remove-double-neg96.5%
distribute-rgt-neg-out96.5%
neg-sub096.5%
neg-sub096.5%
*-commutative96.5%
distribute-lft-neg-in96.5%
remove-double-neg96.5%
distribute-rgt-out--96.5%
*-lft-identity96.5%
associate-+l-96.5%
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 96.5%
+-commutative96.5%
remove-double-neg96.5%
distribute-rgt-neg-out96.5%
neg-sub096.5%
neg-sub096.5%
*-commutative96.5%
distribute-lft-neg-in96.5%
remove-double-neg96.5%
distribute-rgt-out--96.5%
*-lft-identity96.5%
associate-+l-96.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 35.4%
herbie shell --seed 2024131
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))