
(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 96.9%
sub-neg96.9%
+-commutative96.9%
distribute-lft1-in96.9%
associate-+r+96.9%
+-commutative96.9%
*-commutative96.9%
neg-mul-196.9%
associate-*r*96.9%
*-commutative96.9%
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
(if (<= x -2.45e-8)
(* x y)
(if (<= x 3.35e-118)
z
(if (<= x 7.8e-38)
(* x y)
(if (<= x 1.0) z (if (<= x 1.16e+170) (* x (- z)) (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.45e-8) {
tmp = x * y;
} else if (x <= 3.35e-118) {
tmp = z;
} else if (x <= 7.8e-38) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = z;
} else if (x <= 1.16e+170) {
tmp = x * -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.45d-8)) then
tmp = x * y
else if (x <= 3.35d-118) then
tmp = z
else if (x <= 7.8d-38) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = z
else if (x <= 1.16d+170) then
tmp = x * -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.45e-8) {
tmp = x * y;
} else if (x <= 3.35e-118) {
tmp = z;
} else if (x <= 7.8e-38) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = z;
} else if (x <= 1.16e+170) {
tmp = x * -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.45e-8: tmp = x * y elif x <= 3.35e-118: tmp = z elif x <= 7.8e-38: tmp = x * y elif x <= 1.0: tmp = z elif x <= 1.16e+170: tmp = x * -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.45e-8) tmp = Float64(x * y); elseif (x <= 3.35e-118) tmp = z; elseif (x <= 7.8e-38) tmp = Float64(x * y); elseif (x <= 1.0) tmp = z; elseif (x <= 1.16e+170) tmp = Float64(x * Float64(-z)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.45e-8) tmp = x * y; elseif (x <= 3.35e-118) tmp = z; elseif (x <= 7.8e-38) tmp = x * y; elseif (x <= 1.0) tmp = z; elseif (x <= 1.16e+170) tmp = x * -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.45e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.35e-118], z, If[LessEqual[x, 7.8e-38], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], z, If[LessEqual[x, 1.16e+170], N[(x * (-z)), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.35 \cdot 10^{-118}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-38}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.16 \cdot 10^{+170}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.4500000000000001e-8 or 3.35000000000000016e-118 < x < 7.7999999999999998e-38 or 1.16e170 < x Initial program 93.1%
Taylor expanded in y around inf 66.2%
if -2.4500000000000001e-8 < x < 3.35000000000000016e-118 or 7.7999999999999998e-38 < x < 1Initial program 100.0%
Taylor expanded in x around 0 72.4%
if 1 < x < 1.16e170Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in99.9%
associate-+r+99.9%
+-commutative99.9%
*-commutative99.9%
neg-mul-199.9%
associate-*r*99.9%
*-commutative99.9%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 95.6%
Taylor expanded in y around 0 56.2%
mul-1-neg56.2%
distribute-rgt-neg-in56.2%
Simplified56.2%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.02e-43) (not (<= z 6.5e-77))) (* z (- 1.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e-43) || !(z <= 6.5e-77)) {
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 <= (-1.02d-43)) .or. (.not. (z <= 6.5d-77))) 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 <= -1.02e-43) || !(z <= 6.5e-77)) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.02e-43) or not (z <= 6.5e-77): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.02e-43) || !(z <= 6.5e-77)) 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 <= -1.02e-43) || ~((z <= 6.5e-77))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.02e-43], N[Not[LessEqual[z, 6.5e-77]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{-43} \lor \neg \left(z \leq 6.5 \cdot 10^{-77}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.0200000000000001e-43 or 6.4999999999999999e-77 < z Initial program 94.5%
Taylor expanded in y around 0 82.3%
if -1.0200000000000001e-43 < z < 6.4999999999999999e-77Initial program 100.0%
Taylor expanded in y around inf 79.2%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.2e+129) (not (<= z 1.8e-76))) (* z (- 1.0 x)) (* x (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+129) || !(z <= 1.8e-76)) {
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 <= (-4.2d+129)) .or. (.not. (z <= 1.8d-76))) 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 <= -4.2e+129) || !(z <= 1.8e-76)) {
tmp = z * (1.0 - x);
} else {
tmp = x * (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e+129) or not (z <= 1.8e-76): tmp = z * (1.0 - x) else: tmp = x * (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e+129) || !(z <= 1.8e-76)) 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 <= -4.2e+129) || ~((z <= 1.8e-76))) tmp = z * (1.0 - x); else tmp = x * (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e+129], N[Not[LessEqual[z, 1.8e-76]], $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 -4.2 \cdot 10^{+129} \lor \neg \left(z \leq 1.8 \cdot 10^{-76}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - z\right)\\
\end{array}
\end{array}
if z < -4.19999999999999993e129 or 1.8e-76 < z Initial program 95.6%
Taylor expanded in y around 0 89.8%
if -4.19999999999999993e129 < z < 1.8e-76Initial program 97.9%
sub-neg97.9%
+-commutative97.9%
distribute-lft1-in97.9%
associate-+r+97.9%
+-commutative97.9%
*-commutative97.9%
neg-mul-197.9%
associate-*r*97.9%
*-commutative97.9%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 82.4%
Final simplification85.7%
(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 94.0%
sub-neg94.0%
+-commutative94.0%
distribute-lft1-in94.0%
associate-+r+94.0%
+-commutative94.0%
*-commutative94.0%
neg-mul-194.0%
associate-*r*94.0%
*-commutative94.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 97.6%
if -1 < x < 1Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 98.2%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (<= x -9.5e-8) (* x y) (if (<= x 4.6e-118) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e-8) {
tmp = x * y;
} else if (x <= 4.6e-118) {
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 <= (-9.5d-8)) then
tmp = x * y
else if (x <= 4.6d-118) 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 <= -9.5e-8) {
tmp = x * y;
} else if (x <= 4.6e-118) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.5e-8: tmp = x * y elif x <= 4.6e-118: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.5e-8) tmp = Float64(x * y); elseif (x <= 4.6e-118) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.5e-8) tmp = x * y; elseif (x <= 4.6e-118) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.5e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.6e-118], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{-118}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -9.50000000000000036e-8 or 4.60000000000000042e-118 < x Initial program 95.1%
Taylor expanded in y around inf 58.5%
if -9.50000000000000036e-8 < x < 4.60000000000000042e-118Initial program 100.0%
Taylor expanded in x around 0 74.6%
Final simplification64.2%
(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.9%
sub-neg96.9%
+-commutative96.9%
distribute-lft1-in96.9%
associate-+r+96.9%
+-commutative96.9%
*-commutative96.9%
neg-mul-196.9%
associate-*r*96.9%
*-commutative96.9%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
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 96.9%
Taylor expanded in x around 0 33.0%
Final simplification33.0%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))