
(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 8 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 (* (- 1.0 x) y)))
double code(double x, double y, double z) {
return fma(x, z, ((1.0 - x) * y));
}
function code(x, y, z) return fma(x, z, Float64(Float64(1.0 - x) * y)) end
code[x_, y_, z_] := N[(x * z + N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, z, \left(1 - x\right) \cdot y\right)
\end{array}
Initial program 99.6%
+-commutative99.6%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(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 99.6%
*-commutative99.6%
sub-neg99.6%
distribute-lft-in99.6%
associate-+l+99.6%
*-rgt-identity99.6%
+-commutative99.6%
distribute-rgt-neg-out99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.32e-89)
(* x z)
(if (<= x 1.42e-31)
y
(if (or (<= x 1.65e+14)
(and (not (<= x 1e+36))
(or (<= x 3.8e+143) (not (<= x 3.9e+261)))))
(* x z)
(* x (- y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.32e-89) {
tmp = x * z;
} else if (x <= 1.42e-31) {
tmp = y;
} else if ((x <= 1.65e+14) || (!(x <= 1e+36) && ((x <= 3.8e+143) || !(x <= 3.9e+261)))) {
tmp = x * z;
} else {
tmp = 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 <= (-1.32d-89)) then
tmp = x * z
else if (x <= 1.42d-31) then
tmp = y
else if ((x <= 1.65d+14) .or. (.not. (x <= 1d+36)) .and. (x <= 3.8d+143) .or. (.not. (x <= 3.9d+261))) then
tmp = x * z
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.32e-89) {
tmp = x * z;
} else if (x <= 1.42e-31) {
tmp = y;
} else if ((x <= 1.65e+14) || (!(x <= 1e+36) && ((x <= 3.8e+143) || !(x <= 3.9e+261)))) {
tmp = x * z;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.32e-89: tmp = x * z elif x <= 1.42e-31: tmp = y elif (x <= 1.65e+14) or (not (x <= 1e+36) and ((x <= 3.8e+143) or not (x <= 3.9e+261))): tmp = x * z else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.32e-89) tmp = Float64(x * z); elseif (x <= 1.42e-31) tmp = y; elseif ((x <= 1.65e+14) || (!(x <= 1e+36) && ((x <= 3.8e+143) || !(x <= 3.9e+261)))) tmp = Float64(x * z); else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.32e-89) tmp = x * z; elseif (x <= 1.42e-31) tmp = y; elseif ((x <= 1.65e+14) || (~((x <= 1e+36)) && ((x <= 3.8e+143) || ~((x <= 3.9e+261))))) tmp = x * z; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.32e-89], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.42e-31], y, If[Or[LessEqual[x, 1.65e+14], And[N[Not[LessEqual[x, 1e+36]], $MachinePrecision], Or[LessEqual[x, 3.8e+143], N[Not[LessEqual[x, 3.9e+261]], $MachinePrecision]]]], N[(x * z), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{-89}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.42 \cdot 10^{-31}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+14} \lor \neg \left(x \leq 10^{+36}\right) \land \left(x \leq 3.8 \cdot 10^{+143} \lor \neg \left(x \leq 3.9 \cdot 10^{+261}\right)\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -1.32e-89 or 1.4200000000000001e-31 < x < 1.65e14 or 1.00000000000000004e36 < x < 3.8e143 or 3.89999999999999994e261 < x Initial program 99.2%
Taylor expanded in y around 0 60.8%
if -1.32e-89 < x < 1.4200000000000001e-31Initial program 100.0%
Taylor expanded in x around 0 78.2%
if 1.65e14 < x < 1.00000000000000004e36 or 3.8e143 < x < 3.89999999999999994e261Initial program 100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 73.3%
mul-1-neg73.3%
distribute-rgt-neg-out73.3%
Simplified73.3%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.8e-92) (not (<= x 6.5e-31))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e-92) || !(x <= 6.5e-31)) {
tmp = x * (z - y);
} else {
tmp = 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 <= (-7.8d-92)) .or. (.not. (x <= 6.5d-31))) then
tmp = x * (z - y)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e-92) || !(x <= 6.5e-31)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.8e-92) or not (x <= 6.5e-31): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.8e-92) || !(x <= 6.5e-31)) tmp = Float64(x * Float64(z - y)); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.8e-92) || ~((x <= 6.5e-31))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.8e-92], N[Not[LessEqual[x, 6.5e-31]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-92} \lor \neg \left(x \leq 6.5 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -7.7999999999999993e-92 or 6.49999999999999967e-31 < x Initial program 99.3%
Taylor expanded in x around inf 93.6%
mul-1-neg93.6%
sub-neg93.6%
Simplified93.6%
if -7.7999999999999993e-92 < x < 6.49999999999999967e-31Initial program 100.0%
Taylor expanded in x around 0 78.2%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -19.0) (not (<= x 0.0072))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -19.0) || !(x <= 0.0072)) {
tmp = x * (z - y);
} else {
tmp = y + (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 <= (-19.0d0)) .or. (.not. (x <= 0.0072d0))) then
tmp = x * (z - y)
else
tmp = y + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -19.0) || !(x <= 0.0072)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -19.0) or not (x <= 0.0072): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -19.0) || !(x <= 0.0072)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -19.0) || ~((x <= 0.0072))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -19.0], N[Not[LessEqual[x, 0.0072]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19 \lor \neg \left(x \leq 0.0072\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -19 or 0.0071999999999999998 < x Initial program 99.2%
Taylor expanded in x around inf 98.4%
mul-1-neg98.4%
sub-neg98.4%
Simplified98.4%
if -19 < x < 0.0071999999999999998Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
associate-+l+100.0%
*-rgt-identity100.0%
+-commutative100.0%
distribute-rgt-neg-out100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 100.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-90) (not (<= x 1.4e-34))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-90) || !(x <= 1.4e-34)) {
tmp = x * z;
} else {
tmp = 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 <= (-3.8d-90)) .or. (.not. (x <= 1.4d-34))) then
tmp = x * z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-90) || !(x <= 1.4e-34)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-90) or not (x <= 1.4e-34): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-90) || !(x <= 1.4e-34)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-90) || ~((x <= 1.4e-34))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-90], N[Not[LessEqual[x, 1.4e-34]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-90} \lor \neg \left(x \leq 1.4 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.8e-90 or 1.39999999999999998e-34 < x Initial program 99.3%
Taylor expanded in y around 0 54.8%
if -3.8e-90 < x < 1.39999999999999998e-34Initial program 100.0%
Taylor expanded in x around 0 78.2%
Final simplification64.2%
(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 99.6%
*-commutative99.6%
sub-neg99.6%
distribute-lft-in99.6%
associate-+l+99.6%
*-rgt-identity99.6%
+-commutative99.6%
distribute-rgt-neg-out99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.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 99.6%
Taylor expanded in x around 0 36.4%
Final simplification36.4%
(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 2023301
(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)))