
(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 96.1%
sub-neg96.1%
+-commutative96.1%
distribute-rgt1-in96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
neg-mul-196.1%
associate-*r*96.1%
*-commutative96.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.75e+167)
(* x (- y))
(if (<= x -6.5e-7)
(* x z)
(if (<= x 2.8e-136)
y
(if (and (not (<= x 1.8e-41)) (<= x 0.085)) y (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.75e+167) {
tmp = x * -y;
} else if (x <= -6.5e-7) {
tmp = x * z;
} else if (x <= 2.8e-136) {
tmp = y;
} else if (!(x <= 1.8e-41) && (x <= 0.085)) {
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.75d+167)) then
tmp = x * -y
else if (x <= (-6.5d-7)) then
tmp = x * z
else if (x <= 2.8d-136) then
tmp = y
else if ((.not. (x <= 1.8d-41)) .and. (x <= 0.085d0)) 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.75e+167) {
tmp = x * -y;
} else if (x <= -6.5e-7) {
tmp = x * z;
} else if (x <= 2.8e-136) {
tmp = y;
} else if (!(x <= 1.8e-41) && (x <= 0.085)) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.75e+167: tmp = x * -y elif x <= -6.5e-7: tmp = x * z elif x <= 2.8e-136: tmp = y elif not (x <= 1.8e-41) and (x <= 0.085): tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.75e+167) tmp = Float64(x * Float64(-y)); elseif (x <= -6.5e-7) tmp = Float64(x * z); elseif (x <= 2.8e-136) tmp = y; elseif (!(x <= 1.8e-41) && (x <= 0.085)) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.75e+167) tmp = x * -y; elseif (x <= -6.5e-7) tmp = x * z; elseif (x <= 2.8e-136) tmp = y; elseif (~((x <= 1.8e-41)) && (x <= 0.085)) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.75e+167], N[(x * (-y)), $MachinePrecision], If[LessEqual[x, -6.5e-7], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.8e-136], y, If[And[N[Not[LessEqual[x, 1.8e-41]], $MachinePrecision], LessEqual[x, 0.085]], y, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{+167}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq -6.5 \cdot 10^{-7}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-136}:\\
\;\;\;\;y\\
\mathbf{elif}\;\neg \left(x \leq 1.8 \cdot 10^{-41}\right) \land x \leq 0.085:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.74999999999999994e167Initial program 89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt1-in89.3%
associate-+l+89.3%
+-commutative89.3%
*-commutative89.3%
neg-mul-189.3%
associate-*r*89.3%
*-commutative89.3%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 66.8%
mul-1-neg66.8%
distribute-rgt-neg-in66.8%
Simplified66.8%
if -1.74999999999999994e167 < x < -6.50000000000000024e-7 or 2.8000000000000001e-136 < x < 1.8e-41 or 0.0850000000000000061 < x Initial program 93.4%
Taylor expanded in y around 0 60.2%
if -6.50000000000000024e-7 < x < 2.8000000000000001e-136 or 1.8e-41 < x < 0.0850000000000000061Initial program 100.0%
Taylor expanded in x around 0 77.9%
Final simplification69.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z y))) (t_1 (* y (- 1.0 x))))
(if (<= x -5.5e-6)
t_0
(if (<= x 3.2e-138)
t_1
(if (<= x 1.65e-44) (* x z) (if (<= x 1450.0) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double t_1 = y * (1.0 - x);
double tmp;
if (x <= -5.5e-6) {
tmp = t_0;
} else if (x <= 3.2e-138) {
tmp = t_1;
} else if (x <= 1.65e-44) {
tmp = x * z;
} else if (x <= 1450.0) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * (z - y)
t_1 = y * (1.0d0 - x)
if (x <= (-5.5d-6)) then
tmp = t_0
else if (x <= 3.2d-138) then
tmp = t_1
else if (x <= 1.65d-44) then
tmp = x * z
else if (x <= 1450.0d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z - y);
double t_1 = y * (1.0 - x);
double tmp;
if (x <= -5.5e-6) {
tmp = t_0;
} else if (x <= 3.2e-138) {
tmp = t_1;
} else if (x <= 1.65e-44) {
tmp = x * z;
} else if (x <= 1450.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) t_1 = y * (1.0 - x) tmp = 0 if x <= -5.5e-6: tmp = t_0 elif x <= 3.2e-138: tmp = t_1 elif x <= 1.65e-44: tmp = x * z elif x <= 1450.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) t_1 = Float64(y * Float64(1.0 - x)) tmp = 0.0 if (x <= -5.5e-6) tmp = t_0; elseif (x <= 3.2e-138) tmp = t_1; elseif (x <= 1.65e-44) tmp = Float64(x * z); elseif (x <= 1450.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z - y); t_1 = y * (1.0 - x); tmp = 0.0; if (x <= -5.5e-6) tmp = t_0; elseif (x <= 3.2e-138) tmp = t_1; elseif (x <= 1.65e-44) tmp = x * z; elseif (x <= 1450.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.5e-6], t$95$0, If[LessEqual[x, 3.2e-138], t$95$1, If[LessEqual[x, 1.65e-44], N[(x * z), $MachinePrecision], If[LessEqual[x, 1450.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
t_1 := y \cdot \left(1 - x\right)\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-44}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1450:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.4999999999999999e-6 or 1450 < x Initial program 91.5%
sub-neg91.5%
+-commutative91.5%
distribute-rgt1-in91.4%
associate-+l+91.4%
+-commutative91.4%
*-commutative91.4%
neg-mul-191.4%
associate-*r*91.4%
*-commutative91.4%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.1%
if -5.4999999999999999e-6 < x < 3.2000000000000001e-138 or 1.65000000000000003e-44 < x < 1450Initial program 100.0%
Taylor expanded in y around inf 80.9%
if 3.2000000000000001e-138 < x < 1.65000000000000003e-44Initial program 100.0%
Taylor expanded in y around 0 61.8%
Final simplification88.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.2e-6)
(* x z)
(if (<= x 2.8e-136)
y
(if (and (not (<= x 7e-45)) (<= x 0.085)) y (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e-6) {
tmp = x * z;
} else if (x <= 2.8e-136) {
tmp = y;
} else if (!(x <= 7e-45) && (x <= 0.085)) {
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.2d-6)) then
tmp = x * z
else if (x <= 2.8d-136) then
tmp = y
else if ((.not. (x <= 7d-45)) .and. (x <= 0.085d0)) 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.2e-6) {
tmp = x * z;
} else if (x <= 2.8e-136) {
tmp = y;
} else if (!(x <= 7e-45) && (x <= 0.085)) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e-6: tmp = x * z elif x <= 2.8e-136: tmp = y elif not (x <= 7e-45) and (x <= 0.085): tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e-6) tmp = Float64(x * z); elseif (x <= 2.8e-136) tmp = y; elseif (!(x <= 7e-45) && (x <= 0.085)) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.2e-6) tmp = x * z; elseif (x <= 2.8e-136) tmp = y; elseif (~((x <= 7e-45)) && (x <= 0.085)) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e-6], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.8e-136], y, If[And[N[Not[LessEqual[x, 7e-45]], $MachinePrecision], LessEqual[x, 0.085]], y, N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-6}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-136}:\\
\;\;\;\;y\\
\mathbf{elif}\;\neg \left(x \leq 7 \cdot 10^{-45}\right) \land x \leq 0.085:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.1999999999999999e-6 or 2.8000000000000001e-136 < x < 7e-45 or 0.0850000000000000061 < x Initial program 92.5%
Taylor expanded in y around 0 56.8%
if -1.1999999999999999e-6 < x < 2.8000000000000001e-136 or 7e-45 < x < 0.0850000000000000061Initial program 100.0%
Taylor expanded in x around 0 77.9%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (if (<= z -5.1e+53) (* x z) (if (<= z 2.3e+135) (* y (- 1.0 x)) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.1e+53) {
tmp = x * z;
} else if (z <= 2.3e+135) {
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 (z <= (-5.1d+53)) then
tmp = x * z
else if (z <= 2.3d+135) 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 (z <= -5.1e+53) {
tmp = x * z;
} else if (z <= 2.3e+135) {
tmp = y * (1.0 - x);
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.1e+53: tmp = x * z elif z <= 2.3e+135: tmp = y * (1.0 - x) else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.1e+53) tmp = Float64(x * z); elseif (z <= 2.3e+135) 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 (z <= -5.1e+53) tmp = x * z; elseif (z <= 2.3e+135) tmp = y * (1.0 - x); else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.1e+53], N[(x * z), $MachinePrecision], If[LessEqual[z, 2.3e+135], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.1 \cdot 10^{+53}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+135}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -5.0999999999999998e53 or 2.3000000000000001e135 < z Initial program 92.0%
Taylor expanded in y around 0 74.1%
if -5.0999999999999998e53 < z < 2.3000000000000001e135Initial program 98.7%
Taylor expanded in y around inf 82.4%
Final simplification79.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 96.1%
sub-neg96.1%
+-commutative96.1%
distribute-rgt1-in96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
neg-mul-196.1%
associate-*r*96.1%
*-commutative96.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.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 96.1%
Taylor expanded in x around 0 41.0%
Final simplification41.0%
(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 2023215
(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)))