
(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 5 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 (- z y) x y))
double code(double x, double y, double z) {
return fma((z - y), x, y);
}
function code(x, y, z) return fma(Float64(z - y), x, y) end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - y, x, y\right)
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-111) (not (<= x 3.2e-74))) (* (- z y) x) (* y (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-111) || !(x <= 3.2e-74)) {
tmp = (z - y) * x;
} else {
tmp = y * (1.0 - x);
}
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 <= (-3d-111)) .or. (.not. (x <= 3.2d-74))) then
tmp = (z - y) * x
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-111) || !(x <= 3.2e-74)) {
tmp = (z - y) * x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-111) or not (x <= 3.2e-74): tmp = (z - y) * x else: tmp = y * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-111) || !(x <= 3.2e-74)) tmp = Float64(Float64(z - y) * x); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3e-111) || ~((x <= 3.2e-74))) tmp = (z - y) * x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-111], N[Not[LessEqual[x, 3.2e-74]], $MachinePrecision]], N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-111} \lor \neg \left(x \leq 3.2 \cdot 10^{-74}\right):\\
\;\;\;\;\left(z - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -3.00000000000000008e-111 or 3.1999999999999999e-74 < x Initial program 97.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6492.2
Applied rewrites92.2%
if -3.00000000000000008e-111 < x < 3.1999999999999999e-74Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites80.9%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.8e-103) (not (<= y 2.95e-131))) (* y (- 1.0 x)) (* z x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.8e-103) || !(y <= 2.95e-131)) {
tmp = y * (1.0 - x);
} else {
tmp = z * x;
}
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 <= (-7.8d-103)) .or. (.not. (y <= 2.95d-131))) then
tmp = y * (1.0d0 - x)
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.8e-103) || !(y <= 2.95e-131)) {
tmp = y * (1.0 - x);
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.8e-103) or not (y <= 2.95e-131): tmp = y * (1.0 - x) else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.8e-103) || !(y <= 2.95e-131)) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.8e-103) || ~((y <= 2.95e-131))) tmp = y * (1.0 - x); else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.8e-103], N[Not[LessEqual[y, 2.95e-131]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(z * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{-103} \lor \neg \left(y \leq 2.95 \cdot 10^{-131}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if y < -7.8000000000000004e-103 or 2.94999999999999983e-131 < y Initial program 97.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites80.5%
if -7.8000000000000004e-103 < y < 2.94999999999999983e-131Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6482.6
Applied rewrites82.6%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6474.1
Applied rewrites74.1%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1e+116) (not (<= y 1.15))) (* (- y) x) (* z x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+116) || !(y <= 1.15)) {
tmp = -y * x;
} else {
tmp = z * x;
}
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+116)) .or. (.not. (y <= 1.15d0))) then
tmp = -y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+116) || !(y <= 1.15)) {
tmp = -y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e+116) or not (y <= 1.15): tmp = -y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e+116) || !(y <= 1.15)) tmp = Float64(Float64(-y) * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1e+116) || ~((y <= 1.15))) tmp = -y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e+116], N[Not[LessEqual[y, 1.15]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(z * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+116} \lor \neg \left(y \leq 1.15\right):\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if y < -1.00000000000000002e116 or 1.1499999999999999 < y Initial program 96.5%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6457.7
Applied rewrites57.7%
Taylor expanded in y around inf
Applied rewrites50.5%
if -1.00000000000000002e116 < y < 1.1499999999999999Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6475.4
Applied rewrites75.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6459.1
Applied rewrites59.1%
Final simplification55.2%
(FPCore (x y z) :precision binary64 (* z x))
double code(double x, double y, double z) {
return z * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * x
end function
public static double code(double x, double y, double z) {
return z * x;
}
def code(x, y, z): return z * x
function code(x, y, z) return Float64(z * x) end
function tmp = code(x, y, z) tmp = z * x; end
code[x_, y_, z_] := N[(z * x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot x
\end{array}
Initial program 98.4%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6467.4
Applied rewrites67.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6439.8
Applied rewrites39.8%
(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 2024313
(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)))