
(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 (- z y) x y))
double code(double x, double y, double z) {
return fma((z - y), x, y);
}
function code(x, y, z) return fma(Float64(z - y), x, y) end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - y, x, y\right)
\end{array}
Initial program 97.3%
Taylor expanded in z around 0
distribute-rgt-out--N/A
unsub-negN/A
*-lft-identityN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -6e-105) (* x z) (if (<= x 5e-13) (* 1.0 y) (if (<= x 8.8e+82) (* x z) (* (- y) x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-105) {
tmp = x * z;
} else if (x <= 5e-13) {
tmp = 1.0 * y;
} else if (x <= 8.8e+82) {
tmp = x * z;
} else {
tmp = -y * 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 (x <= (-6d-105)) then
tmp = x * z
else if (x <= 5d-13) then
tmp = 1.0d0 * y
else if (x <= 8.8d+82) then
tmp = x * z
else
tmp = -y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6e-105) {
tmp = x * z;
} else if (x <= 5e-13) {
tmp = 1.0 * y;
} else if (x <= 8.8e+82) {
tmp = x * z;
} else {
tmp = -y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6e-105: tmp = x * z elif x <= 5e-13: tmp = 1.0 * y elif x <= 8.8e+82: tmp = x * z else: tmp = -y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6e-105) tmp = Float64(x * z); elseif (x <= 5e-13) tmp = Float64(1.0 * y); elseif (x <= 8.8e+82) tmp = Float64(x * z); else tmp = Float64(Float64(-y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6e-105) tmp = x * z; elseif (x <= 5e-13) tmp = 1.0 * y; elseif (x <= 8.8e+82) tmp = x * z; else tmp = -y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6e-105], N[(x * z), $MachinePrecision], If[LessEqual[x, 5e-13], N[(1.0 * y), $MachinePrecision], If[LessEqual[x, 8.8e+82], N[(x * z), $MachinePrecision], N[((-y) * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-105}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-13}:\\
\;\;\;\;1 \cdot y\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+82}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\end{array}
\end{array}
if x < -6.0000000000000002e-105 or 4.9999999999999999e-13 < x < 8.8000000000000005e82Initial program 97.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6459.3
Applied rewrites59.3%
if -6.0000000000000002e-105 < x < 4.9999999999999999e-13Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in x around 0
Applied rewrites77.9%
if 8.8000000000000005e82 < x Initial program 91.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites68.3%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.32) (not (<= x 3400000000000.0))) (* x (- z y)) (fma (- y) x y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.32) || !(x <= 3400000000000.0)) {
tmp = x * (z - y);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -0.32) || !(x <= 3400000000000.0)) tmp = Float64(x * Float64(z - y)); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.32], N[Not[LessEqual[x, 3400000000000.0]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.32 \lor \neg \left(x \leq 3400000000000\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if x < -0.320000000000000007 or 3.4e12 < x Initial program 94.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
if -0.320000000000000007 < x < 3.4e12Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6474.6
Applied rewrites74.6%
Applied rewrites74.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.32) (not (<= x 3400000000000.0))) (* x (- z y)) (* (- 1.0 x) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.32) || !(x <= 3400000000000.0)) {
tmp = x * (z - y);
} else {
tmp = (1.0 - 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 <= (-0.32d0)) .or. (.not. (x <= 3400000000000.0d0))) then
tmp = x * (z - y)
else
tmp = (1.0d0 - x) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.32) || !(x <= 3400000000000.0)) {
tmp = x * (z - y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.32) or not (x <= 3400000000000.0): tmp = x * (z - y) else: tmp = (1.0 - x) * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.32) || !(x <= 3400000000000.0)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.32) || ~((x <= 3400000000000.0))) tmp = x * (z - y); else tmp = (1.0 - x) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.32], N[Not[LessEqual[x, 3400000000000.0]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.32 \lor \neg \left(x \leq 3400000000000\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if x < -0.320000000000000007 or 3.4e12 < x Initial program 94.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
if -0.320000000000000007 < x < 3.4e12Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6474.6
Applied rewrites74.6%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e+20) (not (<= z 3.05e+82))) (* x z) (* (- 1.0 x) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+20) || !(z <= 3.05e+82)) {
tmp = x * z;
} else {
tmp = (1.0 - 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.7d+20)) .or. (.not. (z <= 3.05d+82))) then
tmp = x * z
else
tmp = (1.0d0 - x) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+20) || !(z <= 3.05e+82)) {
tmp = x * z;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e+20) or not (z <= 3.05e+82): tmp = x * z else: tmp = (1.0 - x) * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e+20) || !(z <= 3.05e+82)) tmp = Float64(x * z); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e+20) || ~((z <= 3.05e+82))) tmp = x * z; else tmp = (1.0 - x) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e+20], N[Not[LessEqual[z, 3.05e+82]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+20} \lor \neg \left(z \leq 3.05 \cdot 10^{+82}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if z < -1.7e20 or 3.0499999999999999e82 < z Initial program 94.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6475.6
Applied rewrites75.6%
if -1.7e20 < z < 3.0499999999999999e82Initial program 99.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.3
Applied rewrites84.3%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-105) (not (<= x 5e-13))) (* x z) (* 1.0 y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-105) || !(x <= 5e-13)) {
tmp = x * z;
} else {
tmp = 1.0 * 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 <= (-6d-105)) .or. (.not. (x <= 5d-13))) then
tmp = x * z
else
tmp = 1.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-105) || !(x <= 5e-13)) {
tmp = x * z;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-105) or not (x <= 5e-13): tmp = x * z else: tmp = 1.0 * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-105) || !(x <= 5e-13)) tmp = Float64(x * z); else tmp = Float64(1.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-105) || ~((x <= 5e-13))) tmp = x * z; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-105], N[Not[LessEqual[x, 5e-13]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-105} \lor \neg \left(x \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if x < -6.0000000000000002e-105 or 4.9999999999999999e-13 < x Initial program 95.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6453.7
Applied rewrites53.7%
if -6.0000000000000002e-105 < x < 4.9999999999999999e-13Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in x around 0
Applied rewrites77.9%
Final simplification63.3%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return 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 * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 97.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
Final simplification42.3%
(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 2024271
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(! :herbie-platform default (- y (* x (- y z))))
(+ (* (- 1.0 x) y) (* x z)))