
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (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 = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (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 = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (- z y) y))
double code(double x, double y, double z) {
return fma(x, (z - y), y);
}
function code(x, y, z) return fma(x, Float64(z - y), y) end
code[x_, y_, z_] := N[(x * N[(z - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, z - y, y\right)
\end{array}
Initial program 97.2%
*-commutative97.2%
distribute-lft-out--97.2%
*-rgt-identity97.2%
cancel-sign-sub-inv97.2%
+-commutative97.2%
+-commutative97.2%
associate-+l+97.2%
+-commutative97.2%
*-commutative97.2%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.9e-50) (not (<= y 2.9e-31))) (* y (- 1.0 x)) (* x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.9e-50) || !(y <= 2.9e-31)) {
tmp = y * (1.0 - x);
} else {
tmp = x * 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 ((y <= (-5.9d-50)) .or. (.not. (y <= 2.9d-31))) then
tmp = y * (1.0d0 - x)
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.9e-50) || !(y <= 2.9e-31)) {
tmp = y * (1.0 - x);
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.9e-50) or not (y <= 2.9e-31): tmp = y * (1.0 - x) else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.9e-50) || !(y <= 2.9e-31)) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.9e-50) || ~((y <= 2.9e-31))) tmp = y * (1.0 - x); else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.9e-50], N[Not[LessEqual[y, 2.9e-31]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.9 \cdot 10^{-50} \lor \neg \left(y \leq 2.9 \cdot 10^{-31}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if y < -5.9e-50 or 2.9000000000000001e-31 < y Initial program 94.8%
Taylor expanded in y around inf 87.1%
if -5.9e-50 < y < 2.9000000000000001e-31Initial program 100.0%
Taylor expanded in y around 0 76.3%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.26e-49) (not (<= y 3.4e+87))) (* y (- 1.0 x)) (* x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.26e-49) || !(y <= 3.4e+87)) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - 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 ((y <= (-1.26d-49)) .or. (.not. (y <= 3.4d+87))) then
tmp = y * (1.0d0 - x)
else
tmp = x * (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.26e-49) || !(y <= 3.4e+87)) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.26e-49) or not (y <= 3.4e+87): tmp = y * (1.0 - x) else: tmp = x * (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.26e-49) || !(y <= 3.4e+87)) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(x * Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.26e-49) || ~((y <= 3.4e+87))) tmp = y * (1.0 - x); else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.26e-49], N[Not[LessEqual[y, 3.4e+87]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{-49} \lor \neg \left(y \leq 3.4 \cdot 10^{+87}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if y < -1.26000000000000005e-49 or 3.4000000000000002e87 < y Initial program 93.7%
Taylor expanded in y around inf 91.3%
if -1.26000000000000005e-49 < y < 3.4000000000000002e87Initial program 100.0%
Taylor expanded in x around inf 83.5%
mul-1-neg83.5%
unsub-neg83.5%
Simplified83.5%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= y -5.8e-50) (* y (- 1.0 x)) (if (<= y 3e+87) (* x (- z y)) (- y (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e-50) {
tmp = y * (1.0 - x);
} else if (y <= 3e+87) {
tmp = x * (z - y);
} else {
tmp = y - (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 (y <= (-5.8d-50)) then
tmp = y * (1.0d0 - x)
else if (y <= 3d+87) then
tmp = x * (z - y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e-50) {
tmp = y * (1.0 - x);
} else if (y <= 3e+87) {
tmp = x * (z - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e-50: tmp = y * (1.0 - x) elif y <= 3e+87: tmp = x * (z - y) else: tmp = y - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e-50) tmp = Float64(y * Float64(1.0 - x)); elseif (y <= 3e+87) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.8e-50) tmp = y * (1.0 - x); elseif (y <= 3e+87) tmp = x * (z - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e-50], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e+87], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-50}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+87}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < -5.80000000000000016e-50Initial program 95.0%
Taylor expanded in y around inf 86.9%
if -5.80000000000000016e-50 < y < 2.9999999999999999e87Initial program 100.0%
Taylor expanded in x around inf 83.5%
mul-1-neg83.5%
unsub-neg83.5%
Simplified83.5%
if 2.9999999999999999e87 < y Initial program 92.3%
Taylor expanded in y around inf 96.3%
distribute-lft-out--96.3%
*-rgt-identity96.3%
Simplified96.3%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.7e-35) (* x z) (if (<= x 2.1e-26) y (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e-35) {
tmp = x * z;
} else if (x <= 2.1e-26) {
tmp = y;
} else {
tmp = x * 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.7d-35)) then
tmp = x * z
else if (x <= 2.1d-26) then
tmp = y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e-35) {
tmp = x * z;
} else if (x <= 2.1e-26) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e-35: tmp = x * z elif x <= 2.1e-26: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e-35) tmp = Float64(x * z); elseif (x <= 2.1e-26) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.7e-35) tmp = x * z; elseif (x <= 2.1e-26) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e-35], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.1e-26], y, N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-35}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-26}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.7000000000000001e-35 or 2.10000000000000008e-26 < x Initial program 94.9%
Taylor expanded in y around 0 61.4%
if -1.7000000000000001e-35 < x < 2.10000000000000008e-26Initial program 100.0%
Taylor expanded in x around 0 72.2%
Final simplification66.4%
(FPCore (x y z) :precision binary64 (+ y (* x (- z y))))
double code(double x, double y, double z) {
return y + (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 = y + (x * (z - y))
end function
public static double code(double x, double y, double z) {
return y + (x * (z - y));
}
def code(x, y, z): return y + (x * (z - y))
function code(x, y, z) return Float64(y + Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = y + (x * (z - y)); end
code[x_, y_, z_] := N[(y + N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(z - y\right)
\end{array}
Initial program 97.2%
flip--86.6%
associate-*l/84.1%
metadata-eval84.1%
Applied egg-rr84.1%
Taylor expanded in x around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
*-commutative100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 97.2%
Taylor expanded in x around 0 35.5%
Final simplification35.5%
(FPCore (x y z) :precision binary64 (- y (* x (- y z))))
double code(double x, double y, double z) {
return y - (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 = y - (x * (y - z))
end function
public static double code(double x, double y, double z) {
return y - (x * (y - z));
}
def code(x, y, z): return y - (x * (y - z))
function code(x, y, z) return Float64(y - Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = y - (x * (y - z)); end
code[x_, y_, z_] := N[(y - N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - x \cdot \left(y - z\right)
\end{array}
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))