
(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 (- 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}
Initial program 96.5%
*-commutative96.5%
distribute-rgt-out--96.5%
*-lft-identity96.5%
associate-+l-96.5%
distribute-lft-out--100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.4e+221)
(* x z)
(if (<= x -7.6e+113)
(* y (- x))
(if (or (<= x -8.6e-59) (not (<= x 2.8e-34))) (* x z) y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+221) {
tmp = x * z;
} else if (x <= -7.6e+113) {
tmp = y * -x;
} else if ((x <= -8.6e-59) || !(x <= 2.8e-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 <= (-2.4d+221)) then
tmp = x * z
else if (x <= (-7.6d+113)) then
tmp = y * -x
else if ((x <= (-8.6d-59)) .or. (.not. (x <= 2.8d-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 <= -2.4e+221) {
tmp = x * z;
} else if (x <= -7.6e+113) {
tmp = y * -x;
} else if ((x <= -8.6e-59) || !(x <= 2.8e-34)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e+221: tmp = x * z elif x <= -7.6e+113: tmp = y * -x elif (x <= -8.6e-59) or not (x <= 2.8e-34): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e+221) tmp = Float64(x * z); elseif (x <= -7.6e+113) tmp = Float64(y * Float64(-x)); elseif ((x <= -8.6e-59) || !(x <= 2.8e-34)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e+221) tmp = x * z; elseif (x <= -7.6e+113) tmp = y * -x; elseif ((x <= -8.6e-59) || ~((x <= 2.8e-34))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e+221], N[(x * z), $MachinePrecision], If[LessEqual[x, -7.6e+113], N[(y * (-x)), $MachinePrecision], If[Or[LessEqual[x, -8.6e-59], N[Not[LessEqual[x, 2.8e-34]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+221}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7.6 \cdot 10^{+113}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;x \leq -8.6 \cdot 10^{-59} \lor \neg \left(x \leq 2.8 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.40000000000000019e221 or -7.6000000000000007e113 < x < -8.6000000000000006e-59 or 2.79999999999999997e-34 < x Initial program 94.4%
Taylor expanded in y around 0 65.6%
if -2.40000000000000019e221 < x < -7.6000000000000007e113Initial program 91.3%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 76.7%
associate-*r*76.7%
mul-1-neg76.7%
Simplified76.7%
if -8.6000000000000006e-59 < x < 2.79999999999999997e-34Initial program 100.0%
Taylor expanded in x around 0 72.5%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.4e-34))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 4.4e-34)) {
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 <= 4.4d-34))) 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 <= 4.4e-34)) {
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 <= 4.4e-34): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.4e-34)) 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 <= 4.4e-34))) 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, 4.4e-34]], $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 4.4 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -1 or 4.3999999999999998e-34 < x Initial program 93.4%
Taylor expanded in x around inf 98.8%
mul-1-neg98.8%
sub-neg98.8%
Simplified98.8%
if -1 < x < 4.3999999999999998e-34Initial program 100.0%
*-commutative100.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 99.3%
neg-mul-199.3%
distribute-lft-neg-in99.3%
Simplified99.3%
cancel-sign-sub99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e-61) (not (<= x 2.8e-34))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-61) || !(x <= 2.8e-34)) {
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 <= (-5.6d-61)) .or. (.not. (x <= 2.8d-34))) 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 <= -5.6e-61) || !(x <= 2.8e-34)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e-61) or not (x <= 2.8e-34): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-61) || !(x <= 2.8e-34)) 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 <= -5.6e-61) || ~((x <= 2.8e-34))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-61], N[Not[LessEqual[x, 2.8e-34]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-61} \lor \neg \left(x \leq 2.8 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.6000000000000002e-61 or 2.79999999999999997e-34 < x Initial program 93.9%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
sub-neg96.5%
Simplified96.5%
if -5.6000000000000002e-61 < x < 2.79999999999999997e-34Initial program 100.0%
Taylor expanded in x around 0 72.5%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e-58) (not (<= x 3.25e-34))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e-58) || !(x <= 3.25e-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 <= (-1.25d-58)) .or. (.not. (x <= 3.25d-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 <= -1.25e-58) || !(x <= 3.25e-34)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e-58) or not (x <= 3.25e-34): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e-58) || !(x <= 3.25e-34)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.25e-58) || ~((x <= 3.25e-34))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e-58], N[Not[LessEqual[x, 3.25e-34]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-58} \lor \neg \left(x \leq 3.25 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.24999999999999994e-58 or 3.24999999999999993e-34 < x Initial program 93.9%
Taylor expanded in y around 0 59.8%
if -1.24999999999999994e-58 < x < 3.24999999999999993e-34Initial program 100.0%
Taylor expanded in x around 0 72.5%
Final simplification65.1%
(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.5%
Taylor expanded in x around 0 33.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 2024131
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(! :herbie-platform default (- y (* x (- y z))))
(+ (* (- 1.0 x) y) (* x z)))