
(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 96.5%
*-commutative96.5%
distribute-lft-out--96.5%
*-rgt-identity96.5%
cancel-sign-sub-inv96.5%
+-commutative96.5%
associate-+r+96.5%
+-commutative96.5%
*-commutative96.5%
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.2e-22)
(* x y)
(if (<= y -2.15e-91)
z
(if (<= y -1.35e-144)
t_0
(if (<= y -4.1e-196)
z
(if (<= y 5.2e-188) t_0 (if (<= y 2.9e-43) z (* x y)))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (y <= -1.2e-22) {
tmp = x * y;
} else if (y <= -2.15e-91) {
tmp = z;
} else if (y <= -1.35e-144) {
tmp = t_0;
} else if (y <= -4.1e-196) {
tmp = z;
} else if (y <= 5.2e-188) {
tmp = t_0;
} else if (y <= 2.9e-43) {
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.2d-22)) then
tmp = x * y
else if (y <= (-2.15d-91)) then
tmp = z
else if (y <= (-1.35d-144)) then
tmp = t_0
else if (y <= (-4.1d-196)) then
tmp = z
else if (y <= 5.2d-188) then
tmp = t_0
else if (y <= 2.9d-43) 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.2e-22) {
tmp = x * y;
} else if (y <= -2.15e-91) {
tmp = z;
} else if (y <= -1.35e-144) {
tmp = t_0;
} else if (y <= -4.1e-196) {
tmp = z;
} else if (y <= 5.2e-188) {
tmp = t_0;
} else if (y <= 2.9e-43) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if y <= -1.2e-22: tmp = x * y elif y <= -2.15e-91: tmp = z elif y <= -1.35e-144: tmp = t_0 elif y <= -4.1e-196: tmp = z elif y <= 5.2e-188: tmp = t_0 elif y <= 2.9e-43: 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.2e-22) tmp = Float64(x * y); elseif (y <= -2.15e-91) tmp = z; elseif (y <= -1.35e-144) tmp = t_0; elseif (y <= -4.1e-196) tmp = z; elseif (y <= 5.2e-188) tmp = t_0; elseif (y <= 2.9e-43) 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.2e-22) tmp = x * y; elseif (y <= -2.15e-91) tmp = z; elseif (y <= -1.35e-144) tmp = t_0; elseif (y <= -4.1e-196) tmp = z; elseif (y <= 5.2e-188) tmp = t_0; elseif (y <= 2.9e-43) 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.2e-22], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.15e-91], z, If[LessEqual[y, -1.35e-144], t$95$0, If[LessEqual[y, -4.1e-196], z, If[LessEqual[y, 5.2e-188], t$95$0, If[LessEqual[y, 2.9e-43], z, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.2 \cdot 10^{-22}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.15 \cdot 10^{-91}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-144}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -4.1 \cdot 10^{-196}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-43}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.20000000000000001e-22 or 2.9000000000000001e-43 < y Initial program 93.6%
Taylor expanded in y around inf 72.5%
if -1.20000000000000001e-22 < y < -2.15e-91 or -1.34999999999999988e-144 < y < -4.10000000000000021e-196 or 5.2000000000000001e-188 < y < 2.9000000000000001e-43Initial program 100.0%
Taylor expanded in x around 0 60.2%
if -2.15e-91 < y < -1.34999999999999988e-144 or -4.10000000000000021e-196 < y < 5.2000000000000001e-188Initial program 100.0%
Taylor expanded in x around inf 73.6%
mul-1-neg73.6%
sub-neg73.6%
Simplified73.6%
Taylor expanded in y around 0 65.9%
mul-1-neg65.9%
distribute-lft-neg-out65.9%
*-commutative65.9%
Simplified65.9%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-105) (not (<= x 6.5e-134))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-105) || !(x <= 6.5e-134)) {
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.7d-105)) .or. (.not. (x <= 6.5d-134))) 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.7e-105) || !(x <= 6.5e-134)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-105) or not (x <= 6.5e-134): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-105) || !(x <= 6.5e-134)) 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.7e-105) || ~((x <= 6.5e-134))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-105], N[Not[LessEqual[x, 6.5e-134]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-105} \lor \neg \left(x \leq 6.5 \cdot 10^{-134}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.69999999999999996e-105 or 6.4999999999999998e-134 < x Initial program 95.2%
Taylor expanded in x around inf 91.7%
mul-1-neg91.7%
sub-neg91.7%
Simplified91.7%
if -1.69999999999999996e-105 < x < 6.4999999999999998e-134Initial program 100.0%
Taylor expanded in x around 0 80.4%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.26e+22) (not (<= x 1.0))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.26e+22) || !(x <= 1.0)) {
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.26d+22)) .or. (.not. (x <= 1.0d0))) 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.26e+22) || !(x <= 1.0)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.26e+22) or not (x <= 1.0): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.26e+22) || !(x <= 1.0)) 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.26e+22) || ~((x <= 1.0))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.26e+22], N[Not[LessEqual[x, 1.0]], $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.26 \cdot 10^{+22} \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1.26e22 or 1 < x Initial program 93.6%
Taylor expanded in x around inf 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
if -1.26e22 < x < 1Initial 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 98.7%
mul-1-neg98.7%
distribute-rgt-neg-out98.7%
Simplified98.7%
*-commutative98.7%
cancel-sign-sub98.7%
+-commutative98.7%
Applied egg-rr98.7%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e-71) (not (<= x 4e-134))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-71) || !(x <= 4e-134)) {
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 <= (-7.2d-71)) .or. (.not. (x <= 4d-134))) 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 <= -7.2e-71) || !(x <= 4e-134)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e-71) or not (x <= 4e-134): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e-71) || !(x <= 4e-134)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e-71) || ~((x <= 4e-134))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-71], N[Not[LessEqual[x, 4e-134]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-71} \lor \neg \left(x \leq 4 \cdot 10^{-134}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -7.2e-71 or 4.00000000000000016e-134 < x Initial program 95.0%
Taylor expanded in y around inf 55.8%
if -7.2e-71 < x < 4.00000000000000016e-134Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification62.2%
(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 96.5%
+-commutative96.5%
remove-double-neg96.5%
distribute-rgt-neg-out96.5%
neg-sub096.5%
neg-sub096.5%
*-commutative96.5%
distribute-lft-neg-in96.5%
remove-double-neg96.5%
distribute-rgt-out--96.5%
*-lft-identity96.5%
associate-+l-96.5%
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 96.5%
Taylor expanded in x around 0 28.7%
Final simplification28.7%
herbie shell --seed 2024072
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))