
(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 (fma x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 98.4%
*-commutative98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
+-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
*-commutative98.4%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= y -1.15)
(* x y)
(if (<= y -6e-214)
z
(if (<= y -4e-273)
t_0
(if (<= y -3.1e-295)
z
(if (<= y 3.15e-302)
t_0
(if (<= y 6.2e-192)
z
(if (<= y 1.26e-134) t_0 (if (<= y 5e-37) z (* x y)))))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (y <= -1.15) {
tmp = x * y;
} else if (y <= -6e-214) {
tmp = z;
} else if (y <= -4e-273) {
tmp = t_0;
} else if (y <= -3.1e-295) {
tmp = z;
} else if (y <= 3.15e-302) {
tmp = t_0;
} else if (y <= 6.2e-192) {
tmp = z;
} else if (y <= 1.26e-134) {
tmp = t_0;
} else if (y <= 5e-37) {
tmp = z;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (y <= (-1.15d0)) then
tmp = x * y
else if (y <= (-6d-214)) then
tmp = z
else if (y <= (-4d-273)) then
tmp = t_0
else if (y <= (-3.1d-295)) then
tmp = z
else if (y <= 3.15d-302) then
tmp = t_0
else if (y <= 6.2d-192) then
tmp = z
else if (y <= 1.26d-134) then
tmp = t_0
else if (y <= 5d-37) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (y <= -1.15) {
tmp = x * y;
} else if (y <= -6e-214) {
tmp = z;
} else if (y <= -4e-273) {
tmp = t_0;
} else if (y <= -3.1e-295) {
tmp = z;
} else if (y <= 3.15e-302) {
tmp = t_0;
} else if (y <= 6.2e-192) {
tmp = z;
} else if (y <= 1.26e-134) {
tmp = t_0;
} else if (y <= 5e-37) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if y <= -1.15: tmp = x * y elif y <= -6e-214: tmp = z elif y <= -4e-273: tmp = t_0 elif y <= -3.1e-295: tmp = z elif y <= 3.15e-302: tmp = t_0 elif y <= 6.2e-192: tmp = z elif y <= 1.26e-134: tmp = t_0 elif y <= 5e-37: tmp = z else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (y <= -1.15) tmp = Float64(x * y); elseif (y <= -6e-214) tmp = z; elseif (y <= -4e-273) tmp = t_0; elseif (y <= -3.1e-295) tmp = z; elseif (y <= 3.15e-302) tmp = t_0; elseif (y <= 6.2e-192) tmp = z; elseif (y <= 1.26e-134) tmp = t_0; elseif (y <= 5e-37) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (y <= -1.15) tmp = x * y; elseif (y <= -6e-214) tmp = z; elseif (y <= -4e-273) tmp = t_0; elseif (y <= -3.1e-295) tmp = z; elseif (y <= 3.15e-302) tmp = t_0; elseif (y <= 6.2e-192) tmp = z; elseif (y <= 1.26e-134) tmp = t_0; elseif (y <= 5e-37) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.15], N[(x * y), $MachinePrecision], If[LessEqual[y, -6e-214], z, If[LessEqual[y, -4e-273], t$95$0, If[LessEqual[y, -3.1e-295], z, If[LessEqual[y, 3.15e-302], t$95$0, If[LessEqual[y, 6.2e-192], z, If[LessEqual[y, 1.26e-134], t$95$0, If[LessEqual[y, 5e-37], z, N[(x * y), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.15:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-214}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -4 \cdot 10^{-273}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-295}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.15 \cdot 10^{-302}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-192}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-37}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1499999999999999 or 4.9999999999999997e-37 < y Initial program 96.9%
Taylor expanded in y around inf 76.2%
if -1.1499999999999999 < y < -5.99999999999999989e-214 or -4e-273 < y < -3.1000000000000002e-295 or 3.1499999999999998e-302 < y < 6.2000000000000001e-192 or 1.25999999999999989e-134 < y < 4.9999999999999997e-37Initial program 100.0%
Taylor expanded in x around 0 62.6%
if -5.99999999999999989e-214 < y < -4e-273 or -3.1000000000000002e-295 < y < 3.1499999999999998e-302 or 6.2000000000000001e-192 < y < 1.25999999999999989e-134Initial program 100.0%
Taylor expanded in x around inf 81.3%
mul-1-neg81.3%
sub-neg81.3%
Simplified81.3%
Taylor expanded in y around 0 69.6%
mul-1-neg69.6%
distribute-lft-neg-out69.6%
*-commutative69.6%
Simplified69.6%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-52) (not (<= x 1.05e-14))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-52) || !(x <= 1.05e-14)) {
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 <= (-5.5d-52)) .or. (.not. (x <= 1.05d-14))) 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 <= -5.5e-52) || !(x <= 1.05e-14)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-52) or not (x <= 1.05e-14): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-52) || !(x <= 1.05e-14)) 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 <= -5.5e-52) || ~((x <= 1.05e-14))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-52], N[Not[LessEqual[x, 1.05e-14]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-52} \lor \neg \left(x \leq 1.05 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.5e-52 or 1.0499999999999999e-14 < x Initial program 97.2%
Taylor expanded in x around inf 96.2%
mul-1-neg96.2%
sub-neg96.2%
Simplified96.2%
if -5.5e-52 < x < 1.0499999999999999e-14Initial program 100.0%
Taylor expanded in x around 0 72.5%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.53))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.53)) {
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.53d0))) 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.53)) {
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.53): 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.53)) 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.53))) 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.53]], $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.53\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 0.53000000000000003 < x Initial program 96.9%
Taylor expanded in x around inf 99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
if -1 < x < 0.53000000000000003Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.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.1%
mul-1-neg99.1%
distribute-rgt-neg-out99.1%
Simplified99.1%
*-commutative99.1%
cancel-sign-sub99.1%
+-commutative99.1%
Applied egg-rr99.1%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.44) (not (<= y 1.3e-28))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.44) || !(y <= 1.3e-28)) {
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 ((y <= (-0.44d0)) .or. (.not. (y <= 1.3d-28))) 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 ((y <= -0.44) || !(y <= 1.3e-28)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.44) or not (y <= 1.3e-28): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.44) || !(y <= 1.3e-28)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.44) || ~((y <= 1.3e-28))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.44], N[Not[LessEqual[y, 1.3e-28]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.44 \lor \neg \left(y \leq 1.3 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -0.440000000000000002 or 1.3e-28 < y Initial program 96.9%
Taylor expanded in y around inf 76.2%
if -0.440000000000000002 < y < 1.3e-28Initial program 100.0%
Taylor expanded in x around 0 52.2%
Final simplification64.3%
(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.4%
+-commutative98.4%
remove-double-neg98.4%
distribute-rgt-neg-out98.4%
neg-sub098.4%
neg-sub098.4%
*-commutative98.4%
distribute-lft-neg-in98.4%
remove-double-neg98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(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.4%
Taylor expanded in x around 0 34.2%
Final simplification34.2%
herbie shell --seed 2024060
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))