
(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.9%
sub-neg96.9%
+-commutative96.9%
distribute-rgt1-in96.9%
associate-+l+96.9%
+-commutative96.9%
*-commutative96.9%
neg-mul-196.9%
associate-*r*96.9%
*-commutative96.9%
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 (or (<= x -1e-35) (not (<= x 1.02e-72))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-35) || !(x <= 1.02e-72)) {
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 <= (-1d-35)) .or. (.not. (x <= 1.02d-72))) 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 <= -1e-35) || !(x <= 1.02e-72)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-35) or not (x <= 1.02e-72): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-35) || !(x <= 1.02e-72)) 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 <= -1e-35) || ~((x <= 1.02e-72))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-35], N[Not[LessEqual[x, 1.02e-72]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-35} \lor \neg \left(x \leq 1.02 \cdot 10^{-72}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.00000000000000001e-35 or 1.02e-72 < x Initial program 94.8%
sub-neg94.8%
+-commutative94.8%
distribute-rgt1-in94.8%
associate-+l+94.8%
+-commutative94.8%
*-commutative94.8%
neg-mul-194.8%
associate-*r*94.8%
*-commutative94.8%
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 94.9%
if -1.00000000000000001e-35 < x < 1.02e-72Initial program 100.0%
Taylor expanded in x around 0 68.5%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 8.5e-9))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 8.5e-9)) {
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.0d0)) .or. (.not. (x <= 8.5d-9))) 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.0) || !(x <= 8.5e-9)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 8.5e-9): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 8.5e-9)) 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.0) || ~((x <= 8.5e-9))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 8.5e-9]], $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 \lor \neg \left(x \leq 8.5 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -1 or 8.5e-9 < x Initial program 94.2%
sub-neg94.2%
+-commutative94.2%
distribute-rgt1-in94.2%
associate-+l+94.2%
+-commutative94.2%
*-commutative94.2%
neg-mul-194.2%
associate-*r*94.2%
*-commutative94.2%
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 98.5%
if -1 < x < 8.5e-9Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-rgt1-in100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
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%
Taylor expanded in z around inf 99.4%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= y -8e-13) y (if (<= y 7.5e+37) (* x z) (* x (- y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e-13) {
tmp = y;
} else if (y <= 7.5e+37) {
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 (y <= (-8d-13)) then
tmp = y
else if (y <= 7.5d+37) 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 (y <= -8e-13) {
tmp = y;
} else if (y <= 7.5e+37) {
tmp = x * z;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e-13: tmp = y elif y <= 7.5e+37: tmp = x * z else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e-13) tmp = y; elseif (y <= 7.5e+37) 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 (y <= -8e-13) tmp = y; elseif (y <= 7.5e+37) tmp = x * z; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e-13], y, If[LessEqual[y, 7.5e+37], N[(x * z), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-13}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+37}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -8.0000000000000002e-13Initial program 91.2%
Taylor expanded in x around 0 48.7%
if -8.0000000000000002e-13 < y < 7.5000000000000003e37Initial program 100.0%
Taylor expanded in y around 0 69.3%
if 7.5000000000000003e37 < y Initial program 94.6%
sub-neg94.6%
+-commutative94.6%
distribute-rgt1-in94.6%
associate-+l+94.6%
+-commutative94.6%
*-commutative94.6%
neg-mul-194.6%
associate-*r*94.6%
*-commutative94.6%
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 64.3%
Taylor expanded in z around 0 56.6%
associate-*r*56.6%
neg-mul-156.6%
Simplified56.6%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (if (<= y -1e-11) y (if (<= y 6.5e+24) (* x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e-11) {
tmp = y;
} else if (y <= 6.5e+24) {
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 (y <= (-1d-11)) then
tmp = y
else if (y <= 6.5d+24) 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 (y <= -1e-11) {
tmp = y;
} else if (y <= 6.5e+24) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e-11: tmp = y elif y <= 6.5e+24: tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e-11) tmp = y; elseif (y <= 6.5e+24) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1e-11) tmp = y; elseif (y <= 6.5e+24) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e-11], y, If[LessEqual[y, 6.5e+24], N[(x * z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-11}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+24}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -9.99999999999999939e-12 or 6.4999999999999996e24 < y Initial program 93.0%
Taylor expanded in x around 0 43.4%
if -9.99999999999999939e-12 < y < 6.4999999999999996e24Initial program 100.0%
Taylor expanded in y around 0 70.3%
Final simplification58.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.9%
sub-neg96.9%
+-commutative96.9%
distribute-rgt1-in96.9%
associate-+l+96.9%
+-commutative96.9%
*-commutative96.9%
neg-mul-196.9%
associate-*r*96.9%
*-commutative96.9%
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.9%
Taylor expanded in x around 0 31.0%
Final simplification31.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 2023182
(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)))