
(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 (+ 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.8%
*-commutative98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
associate-+l+98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-undefine100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -6.6e+101)
(and (not (<= y -5.4e+46))
(or (<= y -1.8e-149) (not (<= y 3.3e-53)))))
(* y (- 1.0 x))
(* x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e+101) || (!(y <= -5.4e+46) && ((y <= -1.8e-149) || !(y <= 3.3e-53)))) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - 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 <= (-6.6d+101)) .or. (.not. (y <= (-5.4d+46))) .and. (y <= (-1.8d-149)) .or. (.not. (y <= 3.3d-53))) then
tmp = y * (1.0d0 - x)
else
tmp = x * (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e+101) || (!(y <= -5.4e+46) && ((y <= -1.8e-149) || !(y <= 3.3e-53)))) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.6e+101) or (not (y <= -5.4e+46) and ((y <= -1.8e-149) or not (y <= 3.3e-53))): tmp = y * (1.0 - x) else: tmp = x * (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.6e+101) || (!(y <= -5.4e+46) && ((y <= -1.8e-149) || !(y <= 3.3e-53)))) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(x * Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.6e+101) || (~((y <= -5.4e+46)) && ((y <= -1.8e-149) || ~((y <= 3.3e-53))))) tmp = y * (1.0 - x); else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.6e+101], And[N[Not[LessEqual[y, -5.4e+46]], $MachinePrecision], Or[LessEqual[y, -1.8e-149], N[Not[LessEqual[y, 3.3e-53]], $MachinePrecision]]]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{+101} \lor \neg \left(y \leq -5.4 \cdot 10^{+46}\right) \land \left(y \leq -1.8 \cdot 10^{-149} \lor \neg \left(y \leq 3.3 \cdot 10^{-53}\right)\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if y < -6.60000000000000022e101 or -5.4000000000000003e46 < y < -1.8000000000000001e-149 or 3.30000000000000004e-53 < y Initial program 98.0%
Taylor expanded in y around inf 83.5%
if -6.60000000000000022e101 < y < -5.4000000000000003e46 or -1.8000000000000001e-149 < y < 3.30000000000000004e-53Initial program 99.9%
Taylor expanded in x around inf 91.8%
mul-1-neg91.8%
sub-neg91.8%
Simplified91.8%
Final simplification86.9%
(FPCore (x y z)
:precision binary64
(if (<= x -1.95e+209)
(* x z)
(if (<= x -1.3e+41)
(* x (- y))
(if (or (<= x -3.2e-32) (not (<= x 8.6e-84))) (* x z) y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+209) {
tmp = x * z;
} else if (x <= -1.3e+41) {
tmp = x * -y;
} else if ((x <= -3.2e-32) || !(x <= 8.6e-84)) {
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.95d+209)) then
tmp = x * z
else if (x <= (-1.3d+41)) then
tmp = x * -y
else if ((x <= (-3.2d-32)) .or. (.not. (x <= 8.6d-84))) 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.95e+209) {
tmp = x * z;
} else if (x <= -1.3e+41) {
tmp = x * -y;
} else if ((x <= -3.2e-32) || !(x <= 8.6e-84)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e+209: tmp = x * z elif x <= -1.3e+41: tmp = x * -y elif (x <= -3.2e-32) or not (x <= 8.6e-84): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+209) tmp = Float64(x * z); elseif (x <= -1.3e+41) tmp = Float64(x * Float64(-y)); elseif ((x <= -3.2e-32) || !(x <= 8.6e-84)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e+209) tmp = x * z; elseif (x <= -1.3e+41) tmp = x * -y; elseif ((x <= -3.2e-32) || ~((x <= 8.6e-84))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+209], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.3e+41], N[(x * (-y)), $MachinePrecision], If[Or[LessEqual[x, -3.2e-32], N[Not[LessEqual[x, 8.6e-84]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+209}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+41}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{-32} \lor \neg \left(x \leq 8.6 \cdot 10^{-84}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.9499999999999999e209 or -1.3e41 < x < -3.2000000000000002e-32 or 8.6000000000000007e-84 < x Initial program 97.6%
Taylor expanded in y around 0 63.6%
if -1.9499999999999999e209 < x < -1.3e41Initial 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 67.8%
mul-1-neg67.8%
distribute-lft-neg-out67.8%
*-commutative67.8%
Simplified67.8%
if -3.2000000000000002e-32 < x < 8.6000000000000007e-84Initial program 100.0%
Taylor expanded in x around 0 71.6%
Final simplification67.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(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.0d0)) .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.0) || !(x <= 1.0)) {
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 <= 1.0): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(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.0) || ~((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.0], 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 \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 or 1 < x Initial program 97.6%
Taylor expanded in x around inf 99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
if -1 < x < 1Initial program 100.0%
*-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e-32) (not (<= x 3.1e-82))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-32) || !(x <= 3.1e-82)) {
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 <= (-1.65d-32)) .or. (.not. (x <= 3.1d-82))) 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 <= -1.65e-32) || !(x <= 3.1e-82)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e-32) or not (x <= 3.1e-82): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e-32) || !(x <= 3.1e-82)) 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 <= -1.65e-32) || ~((x <= 3.1e-82))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e-32], N[Not[LessEqual[x, 3.1e-82]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-32} \lor \neg \left(x \leq 3.1 \cdot 10^{-82}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.65000000000000013e-32 or 3.1e-82 < x Initial program 98.1%
Taylor expanded in x around inf 90.5%
mul-1-neg90.5%
sub-neg90.5%
Simplified90.5%
if -1.65000000000000013e-32 < x < 3.1e-82Initial program 100.0%
Taylor expanded in x around 0 71.6%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.15e-32) (not (<= x 1.65e-81))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.15e-32) || !(x <= 1.65e-81)) {
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 <= (-2.15d-32)) .or. (.not. (x <= 1.65d-81))) 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 <= -2.15e-32) || !(x <= 1.65e-81)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.15e-32) or not (x <= 1.65e-81): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.15e-32) || !(x <= 1.65e-81)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.15e-32) || ~((x <= 1.65e-81))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.15e-32], N[Not[LessEqual[x, 1.65e-81]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-32} \lor \neg \left(x \leq 1.65 \cdot 10^{-81}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.14999999999999995e-32 or 1.64999999999999994e-81 < x Initial program 98.1%
Taylor expanded in y around 0 59.5%
if -2.14999999999999995e-32 < x < 1.64999999999999994e-81Initial program 100.0%
Taylor expanded in x around 0 71.6%
Final simplification63.9%
(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.8%
Taylor expanded in x around 0 32.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 2024096
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))