
(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 5 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 (+ 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 99.2%
+-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.0) t_0 (if (<= x 4.6e-5) (+ z (* x y)) 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 <= 4.6e-5) {
tmp = z + (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 = x * (y - z)
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 4.6d-5) then
tmp = z + (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 = x * (y - z);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 4.6e-5) {
tmp = z + (x * y);
} 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 <= 4.6e-5: tmp = z + (x * y) 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 <= 4.6e-5) tmp = Float64(z + Float64(x * y)); 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 <= 4.6e-5) tmp = z + (x * y); 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, 4.6e-5], N[(z + N[(x * y), $MachinePrecision]), $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 4.6 \cdot 10^{-5}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 4.6e-5 < x Initial program 98.4%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6498.8%
Simplified98.8%
if -1 < x < 4.6e-5Initial program 100.0%
Taylor expanded in x around 0
Simplified99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.35e-128) t_0 (if (<= x 2e-8) z t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.35e-128) {
tmp = t_0;
} else if (x <= 2e-8) {
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.35d-128)) then
tmp = t_0
else if (x <= 2d-8) 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.35e-128) {
tmp = t_0;
} else if (x <= 2e-8) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.35e-128: tmp = t_0 elif x <= 2e-8: 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.35e-128) tmp = t_0; elseif (x <= 2e-8) 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.35e-128) tmp = t_0; elseif (x <= 2e-8) 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.35e-128], t$95$0, If[LessEqual[x, 2e-8], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-128}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-8}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.35000000000000003e-128 or 2e-8 < x Initial program 98.7%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6490.7%
Simplified90.7%
if -1.35000000000000003e-128 < x < 2e-8Initial program 100.0%
Taylor expanded in x around 0
Simplified71.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e-12) (* x y) (if (<= y 8.8e-17) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-12) {
tmp = x * y;
} else if (y <= 8.8e-17) {
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 (y <= (-1.4d-12)) then
tmp = x * y
else if (y <= 8.8d-17) 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 (y <= -1.4e-12) {
tmp = x * y;
} else if (y <= 8.8e-17) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-12: tmp = x * y elif y <= 8.8e-17: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-12) tmp = Float64(x * y); elseif (y <= 8.8e-17) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-12) tmp = x * y; elseif (y <= 8.8e-17) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-12], N[(x * y), $MachinePrecision], If[LessEqual[y, 8.8e-17], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-12}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{-17}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.4000000000000001e-12 or 8.8e-17 < y Initial program 98.5%
Taylor expanded in y around inf
*-lowering-*.f6466.1%
Simplified66.1%
if -1.4000000000000001e-12 < y < 8.8e-17Initial program 100.0%
Taylor expanded in x around 0
Simplified48.8%
(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 99.2%
Taylor expanded in x around 0
Simplified34.6%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))