
(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 (+ 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.7%
+-commutative97.7%
remove-double-neg97.7%
distribute-rgt-neg-out97.7%
neg-sub097.7%
neg-sub097.7%
*-commutative97.7%
distribute-lft-neg-in97.7%
remove-double-neg97.7%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -5.5e+155) (* z (- x)) (if (or (<= x -7.3e-19) (not (<= x 2.05e-14))) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e+155) {
tmp = z * -x;
} else if ((x <= -7.3e-19) || !(x <= 2.05e-14)) {
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 <= (-5.5d+155)) then
tmp = z * -x
else if ((x <= (-7.3d-19)) .or. (.not. (x <= 2.05d-14))) 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 <= -5.5e+155) {
tmp = z * -x;
} else if ((x <= -7.3e-19) || !(x <= 2.05e-14)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.5e+155: tmp = z * -x elif (x <= -7.3e-19) or not (x <= 2.05e-14): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.5e+155) tmp = Float64(z * Float64(-x)); elseif ((x <= -7.3e-19) || !(x <= 2.05e-14)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.5e+155) tmp = z * -x; elseif ((x <= -7.3e-19) || ~((x <= 2.05e-14))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.5e+155], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[x, -7.3e-19], N[Not[LessEqual[x, 2.05e-14]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+155}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;x \leq -7.3 \cdot 10^{-19} \lor \neg \left(x \leq 2.05 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.5000000000000001e155Initial program 88.9%
+-commutative88.9%
remove-double-neg88.9%
distribute-rgt-neg-out88.9%
neg-sub088.9%
neg-sub088.9%
*-commutative88.9%
distribute-lft-neg-in88.9%
remove-double-neg88.9%
distribute-rgt-out--88.9%
*-lft-identity88.9%
associate-+l-88.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 60.3%
Taylor expanded in x around inf 60.3%
associate-*r*60.3%
neg-mul-160.3%
*-commutative60.3%
Simplified60.3%
if -5.5000000000000001e155 < x < -7.2999999999999997e-19 or 2.0500000000000001e-14 < x Initial program 97.8%
+-commutative97.8%
remove-double-neg97.8%
distribute-rgt-neg-out97.8%
neg-sub097.8%
neg-sub097.8%
*-commutative97.8%
distribute-lft-neg-in97.8%
remove-double-neg97.8%
distribute-rgt-out--97.8%
*-lft-identity97.8%
associate-+l-97.8%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 63.2%
mul-1-neg63.2%
distribute-rgt-neg-out63.2%
Simplified63.2%
Taylor expanded in z around 0 62.4%
if -7.2999999999999997e-19 < x < 2.0500000000000001e-14Initial 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 inf 80.4%
Taylor expanded in x around 0 80.4%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.5e+42) (not (<= z 5.2e+58))) (- z (* z x)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e+42) || !(z <= 5.2e+58)) {
tmp = z - (z * x);
} 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 <= (-7.5d+42)) .or. (.not. (z <= 5.2d+58))) then
tmp = z - (z * x)
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 <= -7.5e+42) || !(z <= 5.2e+58)) {
tmp = z - (z * x);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.5e+42) or not (z <= 5.2e+58): tmp = z - (z * x) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.5e+42) || !(z <= 5.2e+58)) tmp = Float64(z - Float64(z * x)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.5e+42) || ~((z <= 5.2e+58))) tmp = z - (z * x); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e+42], N[Not[LessEqual[z, 5.2e+58]], $MachinePrecision]], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+42} \lor \neg \left(z \leq 5.2 \cdot 10^{+58}\right):\\
\;\;\;\;z - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if z < -7.50000000000000041e42 or 5.19999999999999976e58 < z Initial program 94.3%
+-commutative94.3%
remove-double-neg94.3%
distribute-rgt-neg-out94.3%
neg-sub094.3%
neg-sub094.3%
*-commutative94.3%
distribute-lft-neg-in94.3%
remove-double-neg94.3%
distribute-rgt-out--94.3%
*-lft-identity94.3%
associate-+l-94.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 91.4%
if -7.50000000000000041e42 < z < 5.19999999999999976e58Initial 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 91.2%
mul-1-neg91.2%
distribute-rgt-neg-out91.2%
Simplified91.2%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.1e+43) (not (<= z 5.4e+58))) (- z (* z x)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e+43) || !(z <= 5.4e+58)) {
tmp = z - (z * x);
} 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 <= (-2.1d+43)) .or. (.not. (z <= 5.4d+58))) then
tmp = z - (z * x)
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 <= -2.1e+43) || !(z <= 5.4e+58)) {
tmp = z - (z * x);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1e+43) or not (z <= 5.4e+58): tmp = z - (z * x) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1e+43) || !(z <= 5.4e+58)) tmp = Float64(z - Float64(z * x)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.1e+43) || ~((z <= 5.4e+58))) tmp = z - (z * x); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1e+43], N[Not[LessEqual[z, 5.4e+58]], $MachinePrecision]], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+43} \lor \neg \left(z \leq 5.4 \cdot 10^{+58}\right):\\
\;\;\;\;z - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if z < -2.10000000000000002e43 or 5.4000000000000002e58 < z Initial program 94.3%
+-commutative94.3%
remove-double-neg94.3%
distribute-rgt-neg-out94.3%
neg-sub094.3%
neg-sub094.3%
*-commutative94.3%
distribute-lft-neg-in94.3%
remove-double-neg94.3%
distribute-rgt-out--94.3%
*-lft-identity94.3%
associate-+l-94.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 91.4%
if -2.10000000000000002e43 < z < 5.4000000000000002e58Initial 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 91.2%
mul-1-neg91.2%
distribute-rgt-neg-out91.2%
Simplified91.2%
sub-neg91.2%
+-commutative91.2%
distribute-rgt-neg-out91.2%
remove-double-neg91.2%
Applied egg-rr91.2%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-19) (not (<= x 2.85e-15))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-19) || !(x <= 2.85e-15)) {
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 <= (-4.8d-19)) .or. (.not. (x <= 2.85d-15))) 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 <= -4.8e-19) || !(x <= 2.85e-15)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-19) or not (x <= 2.85e-15): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-19) || !(x <= 2.85e-15)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e-19) || ~((x <= 2.85e-15))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-19], N[Not[LessEqual[x, 2.85e-15]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-19} \lor \neg \left(x \leq 2.85 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.80000000000000046e-19 or 2.8500000000000002e-15 < x Initial program 95.3%
+-commutative95.3%
remove-double-neg95.3%
distribute-rgt-neg-out95.3%
neg-sub095.3%
neg-sub095.3%
*-commutative95.3%
distribute-lft-neg-in95.3%
remove-double-neg95.3%
distribute-rgt-out--95.3%
*-lft-identity95.3%
associate-+l-95.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 59.1%
mul-1-neg59.1%
distribute-rgt-neg-out59.1%
Simplified59.1%
Taylor expanded in z around 0 58.3%
if -4.80000000000000046e-19 < x < 2.8500000000000002e-15Initial 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 inf 80.4%
Taylor expanded in x around 0 80.4%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
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)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 97.7%
+-commutative97.7%
remove-double-neg97.7%
distribute-rgt-neg-out97.7%
neg-sub097.7%
neg-sub097.7%
*-commutative97.7%
distribute-lft-neg-in97.7%
remove-double-neg97.7%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 79.4%
mul-1-neg79.4%
distribute-rgt-neg-out79.4%
Simplified79.4%
sub-neg79.4%
+-commutative79.4%
distribute-rgt-neg-out79.4%
remove-double-neg79.4%
Applied egg-rr79.4%
Final simplification79.4%
(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.7%
+-commutative97.7%
remove-double-neg97.7%
distribute-rgt-neg-out97.7%
neg-sub097.7%
neg-sub097.7%
*-commutative97.7%
distribute-lft-neg-in97.7%
remove-double-neg97.7%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.2%
Taylor expanded in x around 0 41.3%
herbie shell --seed 2024103
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))