
(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 6 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 (- z y))))
double code(double x, double y, double z) {
return z - (x * (z - 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 * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\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%
(FPCore (x y z) :precision binary64 (if (<= x -2.65e+28) (* z (- x)) (if (or (<= x -3.45e-19) (not (<= x 2.8e-31))) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.65e+28) {
tmp = z * -x;
} else if ((x <= -3.45e-19) || !(x <= 2.8e-31)) {
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 <= (-2.65d+28)) then
tmp = z * -x
else if ((x <= (-3.45d-19)) .or. (.not. (x <= 2.8d-31))) 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 <= -2.65e+28) {
tmp = z * -x;
} else if ((x <= -3.45e-19) || !(x <= 2.8e-31)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.65e+28: tmp = z * -x elif (x <= -3.45e-19) or not (x <= 2.8e-31): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.65e+28) tmp = Float64(z * Float64(-x)); elseif ((x <= -3.45e-19) || !(x <= 2.8e-31)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.65e+28) tmp = z * -x; elseif ((x <= -3.45e-19) || ~((x <= 2.8e-31))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.65e+28], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[x, -3.45e-19], N[Not[LessEqual[x, 2.8e-31]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{+28}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;x \leq -3.45 \cdot 10^{-19} \lor \neg \left(x \leq 2.8 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.6500000000000002e28Initial program 93.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 73.7%
neg-mul-173.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
Simplified73.7%
if -2.6500000000000002e28 < x < -3.4499999999999999e-19 or 2.7999999999999999e-31 < x Initial program 97.3%
Taylor expanded in y around inf 60.3%
if -3.4499999999999999e-19 < x < 2.7999999999999999e-31Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 77.5%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1060000000000.0) (not (<= x 6.4e-24))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1060000000000.0) || !(x <= 6.4e-24)) {
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 <= (-1060000000000.0d0)) .or. (.not. (x <= 6.4d-24))) 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 <= -1060000000000.0) || !(x <= 6.4e-24)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1060000000000.0) or not (x <= 6.4e-24): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1060000000000.0) || !(x <= 6.4e-24)) 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 <= -1060000000000.0) || ~((x <= 6.4e-24))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1060000000000.0], N[Not[LessEqual[x, 6.4e-24]], $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 -1060000000000 \lor \neg \left(x \leq 6.4 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1.06e12 or 6.40000000000000025e-24 < x Initial program 95.2%
Taylor expanded in x around inf 98.9%
neg-mul-198.9%
sub-neg98.9%
Simplified98.9%
if -1.06e12 < x < 6.40000000000000025e-24Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-28) (not (<= x 1.9e-33))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-28) || !(x <= 1.9e-33)) {
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 <= (-8.5d-28)) .or. (.not. (x <= 1.9d-33))) 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 <= -8.5e-28) || !(x <= 1.9e-33)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-28) or not (x <= 1.9e-33): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-28) || !(x <= 1.9e-33)) 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 <= -8.5e-28) || ~((x <= 1.9e-33))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-28], N[Not[LessEqual[x, 1.9e-33]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-28} \lor \neg \left(x \leq 1.9 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.49999999999999925e-28 or 1.89999999999999997e-33 < x Initial program 95.5%
Taylor expanded in x around inf 96.9%
neg-mul-196.9%
sub-neg96.9%
Simplified96.9%
if -8.49999999999999925e-28 < x < 1.89999999999999997e-33Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 77.9%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.15e-19) (not (<= x 6.2e-33))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.15e-19) || !(x <= 6.2e-33)) {
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 <= (-3.15d-19)) .or. (.not. (x <= 6.2d-33))) 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 <= -3.15e-19) || !(x <= 6.2e-33)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.15e-19) or not (x <= 6.2e-33): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.15e-19) || !(x <= 6.2e-33)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.15e-19) || ~((x <= 6.2e-33))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.15e-19], N[Not[LessEqual[x, 6.2e-33]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.15 \cdot 10^{-19} \lor \neg \left(x \leq 6.2 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.15000000000000009e-19 or 6.19999999999999994e-33 < x Initial program 95.4%
Taylor expanded in y around inf 48.1%
if -3.15000000000000009e-19 < x < 6.19999999999999994e-33Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 77.5%
Final simplification62.3%
(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%
Taylor expanded in x around 0 74.1%
Taylor expanded in x around 0 39.8%
herbie shell --seed 2024132
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))