
(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 6 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 (- y z) x z))
double code(double x, double y, double z) {
return fma((y - z), x, z);
}
function code(x, y, z) return fma(Float64(y - z), x, z) end
code[x_, y_, z_] := N[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, x, z\right)
\end{array}
Initial program 97.3%
Taylor expanded in z around 0
distribute-rgt-out--N/A
*-lft-identityN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= x -1.0)
t_0
(if (<= x 1.3e-27)
(* 1.0 z)
(if (or (<= x 2.05e+30) (not (<= x 5.4e+76))) (* x y) t_0)))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.3e-27) {
tmp = 1.0 * z;
} else if ((x <= 2.05e+30) || !(x <= 5.4e+76)) {
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.0d0)) then
tmp = t_0
else if (x <= 1.3d-27) then
tmp = 1.0d0 * z
else if ((x <= 2.05d+30) .or. (.not. (x <= 5.4d+76))) 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.0) {
tmp = t_0;
} else if (x <= 1.3e-27) {
tmp = 1.0 * z;
} else if ((x <= 2.05e+30) || !(x <= 5.4e+76)) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.3e-27: tmp = 1.0 * z elif (x <= 2.05e+30) or not (x <= 5.4e+76): tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.3e-27) tmp = Float64(1.0 * z); elseif ((x <= 2.05e+30) || !(x <= 5.4e+76)) 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.0) tmp = t_0; elseif (x <= 1.3e-27) tmp = 1.0 * z; elseif ((x <= 2.05e+30) || ~((x <= 5.4e+76))) 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.0], t$95$0, If[LessEqual[x, 1.3e-27], N[(1.0 * z), $MachinePrecision], If[Or[LessEqual[x, 2.05e+30], N[Not[LessEqual[x, 5.4e+76]], $MachinePrecision]], N[(x * y), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-27}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{+30} \lor \neg \left(x \leq 5.4 \cdot 10^{+76}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 2.05000000000000003e30 < x < 5.3999999999999998e76Initial program 96.2%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.3
Applied rewrites98.3%
Taylor expanded in z around inf
Applied rewrites64.3%
if -1 < x < 1.30000000000000009e-27Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.1
Applied rewrites75.1%
Taylor expanded in x around 0
Applied rewrites75.1%
if 1.30000000000000009e-27 < x < 2.05000000000000003e30 or 5.3999999999999998e76 < x Initial program 93.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6472.1
Applied rewrites72.1%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-55) (not (<= x 1.35e-27))) (* x (- y z)) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-55) || !(x <= 1.35e-27)) {
tmp = x * (y - z);
} else {
tmp = 1.0 * 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 <= (-6.5d-55)) .or. (.not. (x <= 1.35d-27))) then
tmp = x * (y - z)
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-55) || !(x <= 1.35e-27)) {
tmp = x * (y - z);
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-55) or not (x <= 1.35e-27): tmp = x * (y - z) else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-55) || !(x <= 1.35e-27)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e-55) || ~((x <= 1.35e-27))) tmp = x * (y - z); else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-55], N[Not[LessEqual[x, 1.35e-27]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-55} \lor \neg \left(x \leq 1.35 \cdot 10^{-27}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -6.50000000000000006e-55 or 1.34999999999999994e-27 < x Initial program 95.2%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6496.7
Applied rewrites96.7%
if -6.50000000000000006e-55 < x < 1.34999999999999994e-27Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.6
Applied rewrites77.6%
Taylor expanded in x around 0
Applied rewrites77.6%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e-21) (not (<= z 4.6e-178))) (* (- 1.0 x) z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-21) || !(z <= 4.6e-178)) {
tmp = (1.0 - x) * 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 ((z <= (-1d-21)) .or. (.not. (z <= 4.6d-178))) then
tmp = (1.0d0 - x) * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-21) || !(z <= 4.6e-178)) {
tmp = (1.0 - x) * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-21) or not (z <= 4.6e-178): tmp = (1.0 - x) * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-21) || !(z <= 4.6e-178)) tmp = Float64(Float64(1.0 - x) * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1e-21) || ~((z <= 4.6e-178))) tmp = (1.0 - x) * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-21], N[Not[LessEqual[z, 4.6e-178]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-21} \lor \neg \left(z \leq 4.6 \cdot 10^{-178}\right):\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -9.99999999999999908e-22 or 4.59999999999999989e-178 < z Initial program 95.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.6
Applied rewrites80.6%
if -9.99999999999999908e-22 < z < 4.59999999999999989e-178Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-50) (not (<= x 1.3e-27))) (* x y) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-50) || !(x <= 1.3e-27)) {
tmp = x * y;
} else {
tmp = 1.0 * 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.2d-50)) .or. (.not. (x <= 1.3d-27))) then
tmp = x * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-50) || !(x <= 1.3e-27)) {
tmp = x * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-50) or not (x <= 1.3e-27): tmp = x * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-50) || !(x <= 1.3e-27)) tmp = Float64(x * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-50) || ~((x <= 1.3e-27))) tmp = x * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-50], N[Not[LessEqual[x, 1.3e-27]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-50} \lor \neg \left(x \leq 1.3 \cdot 10^{-27}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -1.20000000000000001e-50 or 1.30000000000000009e-27 < x Initial program 95.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6454.2
Applied rewrites54.2%
if -1.20000000000000001e-50 < x < 1.30000000000000009e-27Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.2
Applied rewrites77.2%
Taylor expanded in x around 0
Applied rewrites77.2%
Final simplification64.3%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 97.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6441.7
Applied rewrites41.7%
Final simplification41.7%
herbie shell --seed 2024271
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))