
(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 96.9%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft1-inN/A
associate-*r*N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= x -2.7e+288)
t_0
(if (<= x -1.6e-19)
(* x y)
(if (<= x 2.4e-22) (* 1.0 z) (if (<= x 4.1e+63) (* x y) t_0))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -2.7e+288) {
tmp = t_0;
} else if (x <= -1.6e-19) {
tmp = x * y;
} else if (x <= 2.4e-22) {
tmp = 1.0 * z;
} else if (x <= 4.1e+63) {
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 <= (-2.7d+288)) then
tmp = t_0
else if (x <= (-1.6d-19)) then
tmp = x * y
else if (x <= 2.4d-22) then
tmp = 1.0d0 * z
else if (x <= 4.1d+63) 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 <= -2.7e+288) {
tmp = t_0;
} else if (x <= -1.6e-19) {
tmp = x * y;
} else if (x <= 2.4e-22) {
tmp = 1.0 * z;
} else if (x <= 4.1e+63) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -2.7e+288: tmp = t_0 elif x <= -1.6e-19: tmp = x * y elif x <= 2.4e-22: tmp = 1.0 * z elif x <= 4.1e+63: 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 <= -2.7e+288) tmp = t_0; elseif (x <= -1.6e-19) tmp = Float64(x * y); elseif (x <= 2.4e-22) tmp = Float64(1.0 * z); elseif (x <= 4.1e+63) 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 <= -2.7e+288) tmp = t_0; elseif (x <= -1.6e-19) tmp = x * y; elseif (x <= 2.4e-22) tmp = 1.0 * z; elseif (x <= 4.1e+63) 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, -2.7e+288], t$95$0, If[LessEqual[x, -1.6e-19], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.4e-22], N[(1.0 * z), $MachinePrecision], If[LessEqual[x, 4.1e+63], N[(x * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{+288}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-19}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-22}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+63}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.7000000000000001e288 or 4.09999999999999993e63 < x Initial program 89.3%
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--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites67.2%
if -2.7000000000000001e288 < x < -1.59999999999999991e-19 or 2.40000000000000002e-22 < x < 4.09999999999999993e63Initial program 97.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6461.5
Applied rewrites61.5%
if -1.59999999999999991e-19 < x < 2.40000000000000002e-22Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.0
Applied rewrites82.0%
Taylor expanded in x around 0
Applied rewrites82.0%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.02e-19) t_0 (if (<= x 0.000215) (* (- 1.0 x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.02e-19) {
tmp = t_0;
} else if (x <= 0.000215) {
tmp = (1.0 - x) * 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.02d-19)) then
tmp = t_0
else if (x <= 0.000215d0) then
tmp = (1.0d0 - x) * 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.02e-19) {
tmp = t_0;
} else if (x <= 0.000215) {
tmp = (1.0 - x) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.02e-19: tmp = t_0 elif x <= 0.000215: tmp = (1.0 - x) * 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.02e-19) tmp = t_0; elseif (x <= 0.000215) tmp = Float64(Float64(1.0 - x) * 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.02e-19) tmp = t_0; elseif (x <= 0.000215) tmp = (1.0 - x) * 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.02e-19], t$95$0, If[LessEqual[x, 0.000215], N[(N[(1.0 - x), $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.02 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.000215:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.02000000000000004e-19 or 2.14999999999999995e-4 < x Initial program 93.9%
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.1
Applied rewrites98.1%
if -1.02000000000000004e-19 < x < 2.14999999999999995e-4Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.5
Applied rewrites81.5%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (<= y -8.8e+74) (* x y) (if (<= y 4.5e+124) (* (- 1.0 x) z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.8e+74) {
tmp = x * y;
} else if (y <= 4.5e+124) {
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 (y <= (-8.8d+74)) then
tmp = x * y
else if (y <= 4.5d+124) 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 (y <= -8.8e+74) {
tmp = x * y;
} else if (y <= 4.5e+124) {
tmp = (1.0 - x) * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.8e+74: tmp = x * y elif y <= 4.5e+124: tmp = (1.0 - x) * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.8e+74) tmp = Float64(x * y); elseif (y <= 4.5e+124) 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 (y <= -8.8e+74) tmp = x * y; elseif (y <= 4.5e+124) tmp = (1.0 - x) * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.8e+74], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.5e+124], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+74}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+124}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.8000000000000005e74 or 4.5000000000000004e124 < y Initial program 92.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6475.7
Applied rewrites75.7%
if -8.8000000000000005e74 < y < 4.5000000000000004e124Initial program 98.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.2
Applied rewrites83.2%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e-19) (* x y) (if (<= x 2.4e-22) (* 1.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e-19) {
tmp = x * y;
} else if (x <= 2.4e-22) {
tmp = 1.0 * 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 <= (-1.6d-19)) then
tmp = x * y
else if (x <= 2.4d-22) then
tmp = 1.0d0 * 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 <= -1.6e-19) {
tmp = x * y;
} else if (x <= 2.4e-22) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e-19: tmp = x * y elif x <= 2.4e-22: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e-19) tmp = Float64(x * y); elseif (x <= 2.4e-22) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e-19) tmp = x * y; elseif (x <= 2.4e-22) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e-19], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.4e-22], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-19}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-22}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.59999999999999991e-19 or 2.40000000000000002e-22 < x Initial program 94.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6453.6
Applied rewrites53.6%
if -1.59999999999999991e-19 < x < 2.40000000000000002e-22Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.0
Applied rewrites82.0%
Taylor expanded in x around 0
Applied rewrites82.0%
Final simplification67.1%
(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 96.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6438.1
Applied rewrites38.1%
Final simplification38.1%
herbie shell --seed 2024273
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))