
(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 8 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 99.2%
*-commutative99.2%
distribute-lft-out--99.1%
*-rgt-identity99.1%
cancel-sign-sub-inv99.1%
associate-+l+99.1%
+-commutative99.1%
*-commutative99.1%
distribute-rgt-out99.9%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= x -3.6e+202)
t_0
(if (<= x -1.35e+166)
(* x z)
(if (<= x -4.3e+74)
t_0
(if (<= x -1e-47)
(* x z)
(if (<= x 5.2e-186)
y
(if (or (<= x 3e+18) (not (<= x 2.75e+100))) (* x z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -3.6e+202) {
tmp = t_0;
} else if (x <= -1.35e+166) {
tmp = x * z;
} else if (x <= -4.3e+74) {
tmp = t_0;
} else if (x <= -1e-47) {
tmp = x * z;
} else if (x <= 5.2e-186) {
tmp = y;
} else if ((x <= 3e+18) || !(x <= 2.75e+100)) {
tmp = x * z;
} 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) :: tmp
t_0 = x * -y
if (x <= (-3.6d+202)) then
tmp = t_0
else if (x <= (-1.35d+166)) then
tmp = x * z
else if (x <= (-4.3d+74)) then
tmp = t_0
else if (x <= (-1d-47)) then
tmp = x * z
else if (x <= 5.2d-186) then
tmp = y
else if ((x <= 3d+18) .or. (.not. (x <= 2.75d+100))) then
tmp = x * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -3.6e+202) {
tmp = t_0;
} else if (x <= -1.35e+166) {
tmp = x * z;
} else if (x <= -4.3e+74) {
tmp = t_0;
} else if (x <= -1e-47) {
tmp = x * z;
} else if (x <= 5.2e-186) {
tmp = y;
} else if ((x <= 3e+18) || !(x <= 2.75e+100)) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -3.6e+202: tmp = t_0 elif x <= -1.35e+166: tmp = x * z elif x <= -4.3e+74: tmp = t_0 elif x <= -1e-47: tmp = x * z elif x <= 5.2e-186: tmp = y elif (x <= 3e+18) or not (x <= 2.75e+100): tmp = x * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -3.6e+202) tmp = t_0; elseif (x <= -1.35e+166) tmp = Float64(x * z); elseif (x <= -4.3e+74) tmp = t_0; elseif (x <= -1e-47) tmp = Float64(x * z); elseif (x <= 5.2e-186) tmp = y; elseif ((x <= 3e+18) || !(x <= 2.75e+100)) tmp = Float64(x * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -3.6e+202) tmp = t_0; elseif (x <= -1.35e+166) tmp = x * z; elseif (x <= -4.3e+74) tmp = t_0; elseif (x <= -1e-47) tmp = x * z; elseif (x <= 5.2e-186) tmp = y; elseif ((x <= 3e+18) || ~((x <= 2.75e+100))) tmp = x * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -3.6e+202], t$95$0, If[LessEqual[x, -1.35e+166], N[(x * z), $MachinePrecision], If[LessEqual[x, -4.3e+74], t$95$0, If[LessEqual[x, -1e-47], N[(x * z), $MachinePrecision], If[LessEqual[x, 5.2e-186], y, If[Or[LessEqual[x, 3e+18], N[Not[LessEqual[x, 2.75e+100]], $MachinePrecision]], N[(x * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -3.6 \cdot 10^{+202}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.35 \cdot 10^{+166}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -4.3 \cdot 10^{+74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-47}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-186}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+18} \lor \neg \left(x \leq 2.75 \cdot 10^{+100}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.60000000000000008e202 or -1.35000000000000006e166 < x < -4.30000000000000001e74 or 3e18 < x < 2.7500000000000001e100Initial program 98.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 71.7%
mul-1-neg71.7%
distribute-rgt-neg-out71.7%
Simplified71.7%
if -3.60000000000000008e202 < x < -1.35000000000000006e166 or -4.30000000000000001e74 < x < -9.9999999999999997e-48 or 5.19999999999999986e-186 < x < 3e18 or 2.7500000000000001e100 < x Initial program 99.1%
Taylor expanded in y around 0 67.6%
if -9.9999999999999997e-48 < x < 5.19999999999999986e-186Initial program 100.0%
Taylor expanded in x around 0 69.9%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.2e-42) (not (<= x 1.08e-185))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e-42) || !(x <= 1.08e-185)) {
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 <= (-2.2d-42)) .or. (.not. (x <= 1.08d-185))) 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 <= -2.2e-42) || !(x <= 1.08e-185)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.2e-42) or not (x <= 1.08e-185): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.2e-42) || !(x <= 1.08e-185)) 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 <= -2.2e-42) || ~((x <= 1.08e-185))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e-42], N[Not[LessEqual[x, 1.08e-185]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-42} \lor \neg \left(x \leq 1.08 \cdot 10^{-185}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.20000000000000005e-42 or 1.08e-185 < x Initial program 98.8%
Taylor expanded in x around inf 89.1%
mul-1-neg89.1%
sub-neg89.1%
Simplified89.1%
if -2.20000000000000005e-42 < x < 1.08e-185Initial program 100.0%
Taylor expanded in x around 0 69.9%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -400000000.0) (not (<= y 2.65e+38))) (* y (- 1.0 x)) (* x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -400000000.0) || !(y <= 2.65e+38)) {
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 <= (-400000000.0d0)) .or. (.not. (y <= 2.65d+38))) 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 <= -400000000.0) || !(y <= 2.65e+38)) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -400000000.0) or not (y <= 2.65e+38): tmp = y * (1.0 - x) else: tmp = x * (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -400000000.0) || !(y <= 2.65e+38)) 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 <= -400000000.0) || ~((y <= 2.65e+38))) tmp = y * (1.0 - x); else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -400000000.0], N[Not[LessEqual[y, 2.65e+38]], $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 -400000000 \lor \neg \left(y \leq 2.65 \cdot 10^{+38}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if y < -4e8 or 2.65000000000000012e38 < y Initial program 98.2%
Taylor expanded in y around inf 86.5%
if -4e8 < y < 2.65000000000000012e38Initial program 99.9%
Taylor expanded in x around inf 82.5%
mul-1-neg82.5%
sub-neg82.5%
Simplified82.5%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.95e-16))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.95e-16)) {
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.95d-16))) 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.95e-16)) {
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.95e-16): 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.95e-16)) 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.95e-16))) 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.95e-16]], $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.95 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -1 or 1.94999999999999989e-16 < x Initial program 98.4%
Taylor expanded in x around inf 99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
if -1 < x < 1.94999999999999989e-16Initial program 99.9%
remove-double-neg99.9%
distribute-rgt-neg-out99.9%
neg-sub099.9%
neg-sub099.9%
*-commutative99.9%
distribute-lft-neg-in99.9%
remove-double-neg99.9%
distribute-rgt-out--99.9%
*-lft-identity99.9%
associate-+l-99.9%
distribute-lft-out--99.9%
Simplified99.9%
Taylor expanded in y around 0 99.3%
associate-*r*99.3%
neg-mul-199.3%
*-commutative99.3%
Simplified99.3%
sub-neg99.3%
+-commutative99.3%
distribute-rgt-neg-out99.3%
remove-double-neg99.3%
Applied egg-rr99.3%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-44) (not (<= x 1.08e-185))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-44) || !(x <= 1.08e-185)) {
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 <= (-8d-44)) .or. (.not. (x <= 1.08d-185))) 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 <= -8e-44) || !(x <= 1.08e-185)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-44) or not (x <= 1.08e-185): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-44) || !(x <= 1.08e-185)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e-44) || ~((x <= 1.08e-185))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-44], N[Not[LessEqual[x, 1.08e-185]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-44} \lor \neg \left(x \leq 1.08 \cdot 10^{-185}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -7.99999999999999962e-44 or 1.08e-185 < x Initial program 98.8%
Taylor expanded in y around 0 56.5%
if -7.99999999999999962e-44 < x < 1.08e-185Initial program 100.0%
Taylor expanded in x around 0 69.9%
Final simplification60.9%
(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 99.2%
remove-double-neg99.2%
distribute-rgt-neg-out99.2%
neg-sub099.2%
neg-sub099.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
remove-double-neg99.2%
distribute-rgt-out--99.1%
*-lft-identity99.1%
associate-+l-99.1%
distribute-lft-out--99.9%
Simplified99.9%
Final simplification99.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 99.2%
Taylor expanded in x around 0 31.2%
Final simplification31.2%
(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 2024040
(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)))