
(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 5 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.2%
+-commutative97.2%
*-commutative97.2%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.25e-87)
(not
(or (<= x -2.1e-119) (and (not (<= x -1.7e-175)) (<= x 5.4e-19)))))
(* x y)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e-87) || !((x <= -2.1e-119) || (!(x <= -1.7e-175) && (x <= 5.4e-19)))) {
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.25d-87)) .or. (.not. (x <= (-2.1d-119)) .or. (.not. (x <= (-1.7d-175))) .and. (x <= 5.4d-19))) 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.25e-87) || !((x <= -2.1e-119) || (!(x <= -1.7e-175) && (x <= 5.4e-19)))) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e-87) or not ((x <= -2.1e-119) or (not (x <= -1.7e-175) and (x <= 5.4e-19))): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e-87) || !((x <= -2.1e-119) || (!(x <= -1.7e-175) && (x <= 5.4e-19)))) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.25e-87) || ~(((x <= -2.1e-119) || (~((x <= -1.7e-175)) && (x <= 5.4e-19))))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e-87], N[Not[Or[LessEqual[x, -2.1e-119], And[N[Not[LessEqual[x, -1.7e-175]], $MachinePrecision], LessEqual[x, 5.4e-19]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-87} \lor \neg \left(x \leq -2.1 \cdot 10^{-119} \lor \neg \left(x \leq -1.7 \cdot 10^{-175}\right) \land x \leq 5.4 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.25000000000000011e-87 or -2.1e-119 < x < -1.7e-175 or 5.4000000000000002e-19 < x Initial program 95.5%
+-commutative95.5%
*-commutative95.5%
distribute-rgt-out--95.6%
*-lft-identity95.6%
associate-+l-95.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 57.5%
associate-*r*57.5%
*-commutative57.5%
mul-1-neg57.5%
Simplified57.5%
Taylor expanded in z around 0 53.3%
if -1.25000000000000011e-87 < x < -2.1e-119 or -1.7e-175 < x < 5.4000000000000002e-19Initial program 100.0%
+-commutative100.0%
*-commutative100.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 100.0%
associate-*r*100.0%
*-commutative100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 77.0%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e-61) (not (<= y 1.88e-84))) (+ z (* x y)) (- z (* z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-61) || !(y <= 1.88e-84)) {
tmp = z + (x * y);
} else {
tmp = z - (z * x);
}
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.3d-61)) .or. (.not. (y <= 1.88d-84))) then
tmp = z + (x * y)
else
tmp = z - (z * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-61) || !(y <= 1.88e-84)) {
tmp = z + (x * y);
} else {
tmp = z - (z * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e-61) or not (y <= 1.88e-84): tmp = z + (x * y) else: tmp = z - (z * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-61) || !(y <= 1.88e-84)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z - Float64(z * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.3e-61) || ~((y <= 1.88e-84))) tmp = z + (x * y); else tmp = z - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e-61], N[Not[LessEqual[y, 1.88e-84]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-61} \lor \neg \left(y \leq 1.88 \cdot 10^{-84}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot x\\
\end{array}
\end{array}
if y < -2.29999999999999992e-61 or 1.88000000000000004e-84 < y Initial program 95.4%
+-commutative95.4%
*-commutative95.4%
distribute-rgt-out--95.4%
*-lft-identity95.4%
associate-+l-95.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 91.1%
associate-*r*91.1%
*-commutative91.1%
mul-1-neg91.1%
Simplified91.1%
sub-neg91.1%
+-commutative91.1%
distribute-rgt-neg-out91.1%
remove-double-neg91.1%
Applied egg-rr91.1%
if -2.29999999999999992e-61 < y < 1.88000000000000004e-84Initial program 100.0%
+-commutative100.0%
*-commutative100.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 84.6%
Final simplification88.5%
(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.2%
+-commutative97.2%
*-commutative97.2%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 73.8%
associate-*r*73.8%
*-commutative73.8%
mul-1-neg73.8%
Simplified73.8%
sub-neg73.8%
+-commutative73.8%
distribute-rgt-neg-out73.8%
remove-double-neg73.8%
Applied egg-rr73.8%
Final simplification73.8%
(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.2%
+-commutative97.2%
*-commutative97.2%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 73.8%
associate-*r*73.8%
*-commutative73.8%
mul-1-neg73.8%
Simplified73.8%
Taylor expanded in z around inf 33.5%
Final simplification33.5%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))