
(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 6 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 (+ 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 98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
neg-sub098.0%
neg-sub098.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
remove-double-neg98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.6e-38)
(and (not (<= x -5.3e-140))
(or (<= x -3.15e-155) (not (<= x 3.1e-35)))))
(* x (- z y))
y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e-38) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 3.1e-35)))) {
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 <= (-4.6d-38)) .or. (.not. (x <= (-5.3d-140))) .and. (x <= (-3.15d-155)) .or. (.not. (x <= 3.1d-35))) 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 <= -4.6e-38) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 3.1e-35)))) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.6e-38) or (not (x <= -5.3e-140) and ((x <= -3.15e-155) or not (x <= 3.1e-35))): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.6e-38) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 3.1e-35)))) 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 <= -4.6e-38) || (~((x <= -5.3e-140)) && ((x <= -3.15e-155) || ~((x <= 3.1e-35))))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e-38], And[N[Not[LessEqual[x, -5.3e-140]], $MachinePrecision], Or[LessEqual[x, -3.15e-155], N[Not[LessEqual[x, 3.1e-35]], $MachinePrecision]]]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-38} \lor \neg \left(x \leq -5.3 \cdot 10^{-140}\right) \land \left(x \leq -3.15 \cdot 10^{-155} \lor \neg \left(x \leq 3.1 \cdot 10^{-35}\right)\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.60000000000000003e-38 or -5.29999999999999984e-140 < x < -3.14999999999999985e-155 or 3.10000000000000012e-35 < x Initial program 96.6%
Taylor expanded in x around inf 95.8%
mul-1-neg95.8%
sub-neg95.8%
Simplified95.8%
if -4.60000000000000003e-38 < x < -5.29999999999999984e-140 or -3.14999999999999985e-155 < x < 3.10000000000000012e-35Initial program 100.0%
Taylor expanded in x around 0 76.5%
Final simplification87.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.05e-35)
(and (not (<= x -5.3e-140))
(or (<= x -3.15e-155) (not (<= x 9.6e-37)))))
(* x z)
y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-35) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 9.6e-37)))) {
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 <= (-1.05d-35)) .or. (.not. (x <= (-5.3d-140))) .and. (x <= (-3.15d-155)) .or. (.not. (x <= 9.6d-37))) 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 <= -1.05e-35) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 9.6e-37)))) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-35) or (not (x <= -5.3e-140) and ((x <= -3.15e-155) or not (x <= 9.6e-37))): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-35) || (!(x <= -5.3e-140) && ((x <= -3.15e-155) || !(x <= 9.6e-37)))) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e-35) || (~((x <= -5.3e-140)) && ((x <= -3.15e-155) || ~((x <= 9.6e-37))))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-35], And[N[Not[LessEqual[x, -5.3e-140]], $MachinePrecision], Or[LessEqual[x, -3.15e-155], N[Not[LessEqual[x, 9.6e-37]], $MachinePrecision]]]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-35} \lor \neg \left(x \leq -5.3 \cdot 10^{-140}\right) \land \left(x \leq -3.15 \cdot 10^{-155} \lor \neg \left(x \leq 9.6 \cdot 10^{-37}\right)\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.05e-35 or -5.29999999999999984e-140 < x < -3.14999999999999985e-155 or 9.59999999999999963e-37 < x Initial program 96.6%
Taylor expanded in y around 0 59.1%
if -1.05e-35 < x < -5.29999999999999984e-140 or -3.14999999999999985e-155 < x < 9.59999999999999963e-37Initial program 100.0%
Taylor expanded in x around 0 76.5%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e-41) (* x z) (if (<= z -8.8e-237) (* x (- y)) (if (<= z 6400000.0) y (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-41) {
tmp = x * z;
} else if (z <= -8.8e-237) {
tmp = x * -y;
} else if (z <= 6400000.0) {
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 (z <= (-8.5d-41)) then
tmp = x * z
else if (z <= (-8.8d-237)) then
tmp = x * -y
else if (z <= 6400000.0d0) 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 (z <= -8.5e-41) {
tmp = x * z;
} else if (z <= -8.8e-237) {
tmp = x * -y;
} else if (z <= 6400000.0) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e-41: tmp = x * z elif z <= -8.8e-237: tmp = x * -y elif z <= 6400000.0: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e-41) tmp = Float64(x * z); elseif (z <= -8.8e-237) tmp = Float64(x * Float64(-y)); elseif (z <= 6400000.0) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e-41) tmp = x * z; elseif (z <= -8.8e-237) tmp = x * -y; elseif (z <= 6400000.0) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e-41], N[(x * z), $MachinePrecision], If[LessEqual[z, -8.8e-237], N[(x * (-y)), $MachinePrecision], If[LessEqual[z, 6400000.0], y, N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-41}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -8.8 \cdot 10^{-237}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;z \leq 6400000:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -8.4999999999999996e-41 or 6.4e6 < z Initial program 96.5%
Taylor expanded in y around 0 70.0%
if -8.4999999999999996e-41 < z < -8.79999999999999992e-237Initial program 100.0%
Taylor expanded in x around inf 79.7%
mul-1-neg79.7%
sub-neg79.7%
Simplified79.7%
Taylor expanded in z around 0 62.5%
associate-*r*62.5%
mul-1-neg62.5%
Simplified62.5%
if -8.79999999999999992e-237 < z < 6.4e6Initial program 100.0%
Taylor expanded in x around 0 58.3%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e+25) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+25) || !(x <= 1.0)) {
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 <= (-1.6d+25)) .or. (.not. (x <= 1.0d0))) 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 <= -1.6e+25) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+25) or not (x <= 1.0): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+25) || !(x <= 1.0)) 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 <= -1.6e+25) || ~((x <= 1.0))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+25], N[Not[LessEqual[x, 1.0]], $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 -1.6 \cdot 10^{+25} \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -1.6e25 or 1 < x Initial program 96.0%
Taylor expanded in x around inf 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
if -1.6e25 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
associate-*r*98.0%
neg-mul-198.0%
Simplified98.0%
cancel-sign-sub98.0%
+-commutative98.0%
Applied egg-rr98.0%
Final simplification98.7%
(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 98.0%
Taylor expanded in x around 0 34.5%
Final simplification34.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 2023332
(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)))