
(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.8%
*-commutative98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
associate-+r+98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y z))))
(if (<= x -1.9e-81)
t_0
(if (<= x -4.05e-128)
z
(if (<= x -2.5e-174) t_0 (if (<= x 2.55e-116) z t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.9e-81) {
tmp = t_0;
} else if (x <= -4.05e-128) {
tmp = z;
} else if (x <= -2.5e-174) {
tmp = t_0;
} else if (x <= 2.55e-116) {
tmp = 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 - z)
if (x <= (-1.9d-81)) then
tmp = t_0
else if (x <= (-4.05d-128)) then
tmp = z
else if (x <= (-2.5d-174)) then
tmp = t_0
else if (x <= 2.55d-116) then
tmp = 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 - z);
double tmp;
if (x <= -1.9e-81) {
tmp = t_0;
} else if (x <= -4.05e-128) {
tmp = z;
} else if (x <= -2.5e-174) {
tmp = t_0;
} else if (x <= 2.55e-116) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.9e-81: tmp = t_0 elif x <= -4.05e-128: tmp = z elif x <= -2.5e-174: tmp = t_0 elif x <= 2.55e-116: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -1.9e-81) tmp = t_0; elseif (x <= -4.05e-128) tmp = z; elseif (x <= -2.5e-174) tmp = t_0; elseif (x <= 2.55e-116) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -1.9e-81) tmp = t_0; elseif (x <= -4.05e-128) tmp = z; elseif (x <= -2.5e-174) tmp = t_0; elseif (x <= 2.55e-116) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.9e-81], t$95$0, If[LessEqual[x, -4.05e-128], z, If[LessEqual[x, -2.5e-174], t$95$0, If[LessEqual[x, 2.55e-116], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.05 \cdot 10^{-128}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{-174}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{-116}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8999999999999999e-81 or -4.04999999999999983e-128 < x < -2.5000000000000001e-174 or 2.5500000000000001e-116 < x Initial program 98.3%
+-commutative98.3%
remove-double-neg98.3%
distribute-rgt-neg-out98.3%
neg-sub098.3%
neg-sub098.3%
*-commutative98.3%
distribute-lft-neg-in98.3%
remove-double-neg98.3%
distribute-rgt-out--98.3%
*-lft-identity98.3%
associate-+l-98.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 89.3%
if -1.8999999999999999e-81 < x < -4.04999999999999983e-128 or -2.5000000000000001e-174 < x < 2.5500000000000001e-116Initial program 100.0%
Taylor expanded in x around 0 77.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y z))) (t_1 (* z (- 1.0 x))))
(if (<= x -340000.0)
t_0
(if (<= x -4.05e-128)
t_1
(if (<= x -2.5e-174) t_0 (if (<= x 2.55e-116) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double t_1 = z * (1.0 - x);
double tmp;
if (x <= -340000.0) {
tmp = t_0;
} else if (x <= -4.05e-128) {
tmp = t_1;
} else if (x <= -2.5e-174) {
tmp = t_0;
} else if (x <= 2.55e-116) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = x * (y - z)
t_1 = z * (1.0d0 - x)
if (x <= (-340000.0d0)) then
tmp = t_0
else if (x <= (-4.05d-128)) then
tmp = t_1
else if (x <= (-2.5d-174)) then
tmp = t_0
else if (x <= 2.55d-116) then
tmp = t_1
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 - z);
double t_1 = z * (1.0 - x);
double tmp;
if (x <= -340000.0) {
tmp = t_0;
} else if (x <= -4.05e-128) {
tmp = t_1;
} else if (x <= -2.5e-174) {
tmp = t_0;
} else if (x <= 2.55e-116) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) t_1 = z * (1.0 - x) tmp = 0 if x <= -340000.0: tmp = t_0 elif x <= -4.05e-128: tmp = t_1 elif x <= -2.5e-174: tmp = t_0 elif x <= 2.55e-116: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) t_1 = Float64(z * Float64(1.0 - x)) tmp = 0.0 if (x <= -340000.0) tmp = t_0; elseif (x <= -4.05e-128) tmp = t_1; elseif (x <= -2.5e-174) tmp = t_0; elseif (x <= 2.55e-116) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); t_1 = z * (1.0 - x); tmp = 0.0; if (x <= -340000.0) tmp = t_0; elseif (x <= -4.05e-128) tmp = t_1; elseif (x <= -2.5e-174) tmp = t_0; elseif (x <= 2.55e-116) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -340000.0], t$95$0, If[LessEqual[x, -4.05e-128], t$95$1, If[LessEqual[x, -2.5e-174], t$95$0, If[LessEqual[x, 2.55e-116], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
t_1 := z \cdot \left(1 - x\right)\\
\mathbf{if}\;x \leq -340000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.05 \cdot 10^{-128}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{-174}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{-116}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.4e5 or -4.04999999999999983e-128 < x < -2.5000000000000001e-174 or 2.5500000000000001e-116 < x Initial program 98.2%
+-commutative98.2%
remove-double-neg98.2%
distribute-rgt-neg-out98.2%
neg-sub098.2%
neg-sub098.2%
*-commutative98.2%
distribute-lft-neg-in98.2%
remove-double-neg98.2%
distribute-rgt-out--98.2%
*-lft-identity98.2%
associate-+l-98.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 92.2%
if -3.4e5 < x < -4.04999999999999983e-128 or -2.5000000000000001e-174 < x < 2.5500000000000001e-116Initial program 100.0%
Taylor expanded in y around 0 73.5%
(FPCore (x y z)
:precision binary64
(if (<= x -6e-82)
(* x y)
(if (<= x -4.8e-128)
z
(if (<= x -2.5e-174) (* x y) (if (<= x 2.55e-116) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-82) {
tmp = x * y;
} else if (x <= -4.8e-128) {
tmp = z;
} else if (x <= -2.5e-174) {
tmp = x * y;
} else if (x <= 2.55e-116) {
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) :: tmp
if (x <= (-6d-82)) then
tmp = x * y
else if (x <= (-4.8d-128)) then
tmp = z
else if (x <= (-2.5d-174)) then
tmp = x * y
else if (x <= 2.55d-116) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6e-82) {
tmp = x * y;
} else if (x <= -4.8e-128) {
tmp = z;
} else if (x <= -2.5e-174) {
tmp = x * y;
} else if (x <= 2.55e-116) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6e-82: tmp = x * y elif x <= -4.8e-128: tmp = z elif x <= -2.5e-174: tmp = x * y elif x <= 2.55e-116: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6e-82) tmp = Float64(x * y); elseif (x <= -4.8e-128) tmp = z; elseif (x <= -2.5e-174) tmp = Float64(x * y); elseif (x <= 2.55e-116) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6e-82) tmp = x * y; elseif (x <= -4.8e-128) tmp = z; elseif (x <= -2.5e-174) tmp = x * y; elseif (x <= 2.55e-116) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6e-82], N[(x * y), $MachinePrecision], If[LessEqual[x, -4.8e-128], z, If[LessEqual[x, -2.5e-174], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.55e-116], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-82}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{-128}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{-174}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{-116}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.9999999999999998e-82 or -4.7999999999999996e-128 < x < -2.5000000000000001e-174 or 2.5500000000000001e-116 < x Initial program 98.3%
Taylor expanded in y around inf 54.0%
if -5.9999999999999998e-82 < x < -4.7999999999999996e-128 or -2.5000000000000001e-174 < x < 2.5500000000000001e-116Initial program 100.0%
Taylor expanded in x around 0 77.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.0) t_0 (if (<= x 0.26) (+ (* x y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 0.26) {
tmp = (x * y) + 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 - z)
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 0.26d0) then
tmp = (x * y) + 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 - z);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 0.26) {
tmp = (x * y) + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 0.26: tmp = (x * y) + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 0.26) tmp = Float64(Float64(x * y) + z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 0.26) tmp = (x * y) + z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 0.26], N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.26:\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 0.26000000000000001 < x Initial program 97.8%
+-commutative97.8%
remove-double-neg97.8%
distribute-rgt-neg-out97.8%
neg-sub097.8%
neg-sub097.8%
*-commutative97.8%
distribute-lft-neg-in97.8%
remove-double-neg97.8%
distribute-rgt-out--97.8%
*-lft-identity97.8%
associate-+l-97.8%
distribute-lft-out--99.9%
Simplified99.9%
Taylor expanded in x around inf 98.0%
if -1 < x < 0.26000000000000001Initial program 100.0%
Taylor expanded in x around 0 98.8%
(FPCore (x y z) :precision binary64 (- z (* x (- z y))))
double code(double x, double y, double z) {
return z - (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 = z - (x * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\right)
\end{array}
Initial program 98.8%
+-commutative98.8%
remove-double-neg98.8%
distribute-rgt-neg-out98.8%
neg-sub098.8%
neg-sub098.8%
*-commutative98.8%
distribute-lft-neg-in98.8%
remove-double-neg98.8%
distribute-rgt-out--98.8%
*-lft-identity98.8%
associate-+l-98.8%
distribute-lft-out--100.0%
Simplified100.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.8%
Taylor expanded in x around 0 29.3%
herbie shell --seed 2024052 -o generate:simplify
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))