
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (+ z (* x (- y z))))
double code(double x, double y, double z) {
return z + (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 = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - z));
}
def code(x, y, z): return z + (x * (y - z))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = z + (x * (y - z)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - z\right)
\end{array}
Initial program 98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-out--98.8%
*-lft-identity98.8%
associate-+l-98.8%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -1.15e+159)
t_0
(if (<= x -1860.0)
(* x y)
(if (<= x -1.2e-79)
z
(if (<= x -1.2e-140)
(* x y)
(if (<= x 4.2e-58)
z
(if (or (<= x 1.42e+107) (not (<= x 1.25e+137)))
(* x y)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -1.15e+159) {
tmp = t_0;
} else if (x <= -1860.0) {
tmp = x * y;
} else if (x <= -1.2e-79) {
tmp = z;
} else if (x <= -1.2e-140) {
tmp = x * y;
} else if (x <= 4.2e-58) {
tmp = z;
} else if ((x <= 1.42e+107) || !(x <= 1.25e+137)) {
tmp = x * y;
} 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 = z * -x
if (x <= (-1.15d+159)) then
tmp = t_0
else if (x <= (-1860.0d0)) then
tmp = x * y
else if (x <= (-1.2d-79)) then
tmp = z
else if (x <= (-1.2d-140)) then
tmp = x * y
else if (x <= 4.2d-58) then
tmp = z
else if ((x <= 1.42d+107) .or. (.not. (x <= 1.25d+137))) then
tmp = x * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -1.15e+159) {
tmp = t_0;
} else if (x <= -1860.0) {
tmp = x * y;
} else if (x <= -1.2e-79) {
tmp = z;
} else if (x <= -1.2e-140) {
tmp = x * y;
} else if (x <= 4.2e-58) {
tmp = z;
} else if ((x <= 1.42e+107) || !(x <= 1.25e+137)) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -1.15e+159: tmp = t_0 elif x <= -1860.0: tmp = x * y elif x <= -1.2e-79: tmp = z elif x <= -1.2e-140: tmp = x * y elif x <= 4.2e-58: tmp = z elif (x <= 1.42e+107) or not (x <= 1.25e+137): tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -1.15e+159) tmp = t_0; elseif (x <= -1860.0) tmp = Float64(x * y); elseif (x <= -1.2e-79) tmp = z; elseif (x <= -1.2e-140) tmp = Float64(x * y); elseif (x <= 4.2e-58) tmp = z; elseif ((x <= 1.42e+107) || !(x <= 1.25e+137)) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -1.15e+159) tmp = t_0; elseif (x <= -1860.0) tmp = x * y; elseif (x <= -1.2e-79) tmp = z; elseif (x <= -1.2e-140) tmp = x * y; elseif (x <= 4.2e-58) tmp = z; elseif ((x <= 1.42e+107) || ~((x <= 1.25e+137))) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -1.15e+159], t$95$0, If[LessEqual[x, -1860.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.2e-79], z, If[LessEqual[x, -1.2e-140], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.2e-58], z, If[Or[LessEqual[x, 1.42e+107], N[Not[LessEqual[x, 1.25e+137]], $MachinePrecision]], N[(x * y), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.15 \cdot 10^{+159}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1860:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{-79}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{-140}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-58}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.42 \cdot 10^{+107} \lor \neg \left(x \leq 1.25 \cdot 10^{+137}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.14999999999999998e159 or 1.42000000000000006e107 < x < 1.25e137Initial program 100.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 75.6%
associate-*r*75.6%
mul-1-neg75.6%
Simplified75.6%
if -1.14999999999999998e159 < x < -1860 or -1.20000000000000003e-79 < x < -1.19999999999999993e-140 or 4.19999999999999975e-58 < x < 1.42000000000000006e107 or 1.25e137 < x Initial program 97.4%
Taylor expanded in y around inf 67.1%
if -1860 < x < -1.20000000000000003e-79 or -1.19999999999999993e-140 < x < 4.19999999999999975e-58Initial program 100.0%
Taylor expanded in x around 0 82.6%
Final simplification74.3%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.5e-9)
(not
(or (<= x -1.45e-79) (and (not (<= x -1.2e-140)) (<= x 1.22e-32)))))
(* x (- y z))
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-9) || !((x <= -1.45e-79) || (!(x <= -1.2e-140) && (x <= 1.22e-32)))) {
tmp = x * (y - z);
} else {
tmp = 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.5d-9)) .or. (.not. (x <= (-1.45d-79)) .or. (.not. (x <= (-1.2d-140))) .and. (x <= 1.22d-32))) then
tmp = x * (y - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-9) || !((x <= -1.45e-79) || (!(x <= -1.2e-140) && (x <= 1.22e-32)))) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e-9) or not ((x <= -1.45e-79) or (not (x <= -1.2e-140) and (x <= 1.22e-32))): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e-9) || !((x <= -1.45e-79) || (!(x <= -1.2e-140) && (x <= 1.22e-32)))) tmp = Float64(x * Float64(y - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e-9) || ~(((x <= -1.45e-79) || (~((x <= -1.2e-140)) && (x <= 1.22e-32))))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e-9], N[Not[Or[LessEqual[x, -1.45e-79], And[N[Not[LessEqual[x, -1.2e-140]], $MachinePrecision], LessEqual[x, 1.22e-32]]]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-9} \lor \neg \left(x \leq -1.45 \cdot 10^{-79} \lor \neg \left(x \leq -1.2 \cdot 10^{-140}\right) \land x \leq 1.22 \cdot 10^{-32}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.49999999999999999e-9 or -1.45e-79 < x < -1.19999999999999993e-140 or 1.22e-32 < x Initial program 98.1%
Taylor expanded in x around inf 96.4%
neg-mul-196.4%
unsub-neg96.4%
Simplified96.4%
if -1.49999999999999999e-9 < x < -1.45e-79 or -1.19999999999999993e-140 < x < 1.22e-32Initial program 100.0%
Taylor expanded in x around 0 82.7%
Final simplification91.3%
(FPCore (x y z)
:precision binary64
(if (or (<= x -12000.0)
(and (not (<= x -2e-79)) (or (<= x -1.2e-140) (not (<= x 1.8e-26)))))
(* x (- y z))
(- z (* z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -12000.0) || (!(x <= -2e-79) && ((x <= -1.2e-140) || !(x <= 1.8e-26)))) {
tmp = x * (y - z);
} else {
tmp = z - (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 ((x <= (-12000.0d0)) .or. (.not. (x <= (-2d-79))) .and. (x <= (-1.2d-140)) .or. (.not. (x <= 1.8d-26))) then
tmp = x * (y - z)
else
tmp = z - (z * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -12000.0) || (!(x <= -2e-79) && ((x <= -1.2e-140) || !(x <= 1.8e-26)))) {
tmp = x * (y - z);
} else {
tmp = z - (z * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -12000.0) or (not (x <= -2e-79) and ((x <= -1.2e-140) or not (x <= 1.8e-26))): tmp = x * (y - z) else: tmp = z - (z * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -12000.0) || (!(x <= -2e-79) && ((x <= -1.2e-140) || !(x <= 1.8e-26)))) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z - Float64(z * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -12000.0) || (~((x <= -2e-79)) && ((x <= -1.2e-140) || ~((x <= 1.8e-26))))) tmp = x * (y - z); else tmp = z - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -12000.0], And[N[Not[LessEqual[x, -2e-79]], $MachinePrecision], Or[LessEqual[x, -1.2e-140], N[Not[LessEqual[x, 1.8e-26]], $MachinePrecision]]]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -12000 \lor \neg \left(x \leq -2 \cdot 10^{-79}\right) \land \left(x \leq -1.2 \cdot 10^{-140} \lor \neg \left(x \leq 1.8 \cdot 10^{-26}\right)\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot x\\
\end{array}
\end{array}
if x < -12000 or -2e-79 < x < -1.19999999999999993e-140 or 1.8000000000000001e-26 < x Initial program 98.1%
Taylor expanded in x around inf 96.8%
neg-mul-196.8%
unsub-neg96.8%
Simplified96.8%
if -12000 < x < -2e-79 or -1.19999999999999993e-140 < x < 1.8000000000000001e-26Initial program 100.0%
+-commutative100.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 z around inf 83.5%
*-commutative83.5%
Simplified83.5%
Final simplification91.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1860.0)
(and (not (<= x -2.4e-78))
(or (<= x -1.2e-140) (not (<= x 5.5e-58)))))
(* x y)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1860.0) || (!(x <= -2.4e-78) && ((x <= -1.2e-140) || !(x <= 5.5e-58)))) {
tmp = x * y;
} else {
tmp = 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 <= (-1860.0d0)) .or. (.not. (x <= (-2.4d-78))) .and. (x <= (-1.2d-140)) .or. (.not. (x <= 5.5d-58))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1860.0) || (!(x <= -2.4e-78) && ((x <= -1.2e-140) || !(x <= 5.5e-58)))) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1860.0) or (not (x <= -2.4e-78) and ((x <= -1.2e-140) or not (x <= 5.5e-58))): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1860.0) || (!(x <= -2.4e-78) && ((x <= -1.2e-140) || !(x <= 5.5e-58)))) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1860.0) || (~((x <= -2.4e-78)) && ((x <= -1.2e-140) || ~((x <= 5.5e-58))))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1860.0], And[N[Not[LessEqual[x, -2.4e-78]], $MachinePrecision], Or[LessEqual[x, -1.2e-140], N[Not[LessEqual[x, 5.5e-58]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1860 \lor \neg \left(x \leq -2.4 \cdot 10^{-78}\right) \land \left(x \leq -1.2 \cdot 10^{-140} \lor \neg \left(x \leq 5.5 \cdot 10^{-58}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1860 or -2.4e-78 < x < -1.19999999999999993e-140 or 5.49999999999999996e-58 < x Initial program 98.1%
Taylor expanded in y around inf 58.1%
if -1860 < x < -2.4e-78 or -1.19999999999999993e-140 < x < 5.49999999999999996e-58Initial program 100.0%
Taylor expanded in x around 0 82.6%
Final simplification67.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.66))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.66)) {
tmp = x * (y - z);
} else {
tmp = z + (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 ((x <= (-1.0d0)) .or. (.not. (x <= 0.66d0))) then
tmp = x * (y - z)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.66)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.66): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.66)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.66))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.66]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.66\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 0.660000000000000031 < x Initial program 97.8%
Taylor expanded in x around inf 99.3%
neg-mul-199.3%
unsub-neg99.3%
Simplified99.3%
if -1 < x < 0.660000000000000031Initial program 100.0%
+-commutative100.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 z around 0 99.0%
associate-*r*99.0%
neg-mul-199.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0 34.2%
Final simplification34.2%
herbie shell --seed 2024018
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))