
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z x) (- 0.0 y) z))
double code(double x, double y, double z) {
return fma((z - x), (0.0 - y), z);
}
function code(x, y, z) return fma(Float64(z - x), Float64(0.0 - y), z) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * N[(0.0 - y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, 0 - y, z\right)
\end{array}
Initial program 98.8%
+-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
--lowering--.f64N/A
neg-sub0N/A
--lowering--.f64100.0%
Applied egg-rr100.0%
sub0-negN/A
neg-lowering-neg.f64100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -2.4) t_0 (if (<= y 0.00095) (+ z (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -2.4) {
tmp = t_0;
} else if (y <= 0.00095) {
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 = y * (x - z)
if (y <= (-2.4d0)) then
tmp = t_0
else if (y <= 0.00095d0) 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 = y * (x - z);
double tmp;
if (y <= -2.4) {
tmp = t_0;
} else if (y <= 0.00095) {
tmp = z + (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -2.4: tmp = t_0 elif y <= 0.00095: tmp = z + (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -2.4) tmp = t_0; elseif (y <= 0.00095) tmp = Float64(z + Float64(x * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -2.4) tmp = t_0; elseif (y <= 0.00095) tmp = z + (x * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.4], t$95$0, If[LessEqual[y, 0.00095], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -2.4:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00095:\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.39999999999999991 or 9.49999999999999998e-4 < y Initial program 97.6%
Taylor expanded in y 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.4%
Simplified98.4%
if -2.39999999999999991 < y < 9.49999999999999998e-4Initial program 100.0%
Taylor expanded in y around 0
Simplified99.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -2.06e-10) t_0 (if (<= y 4.6e-11) (* z (- 1.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -2.06e-10) {
tmp = t_0;
} else if (y <= 4.6e-11) {
tmp = z * (1.0 - 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 = y * (x - z)
if (y <= (-2.06d-10)) then
tmp = t_0
else if (y <= 4.6d-11) then
tmp = z * (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -2.06e-10) {
tmp = t_0;
} else if (y <= 4.6e-11) {
tmp = z * (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -2.06e-10: tmp = t_0 elif y <= 4.6e-11: tmp = z * (1.0 - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -2.06e-10) tmp = t_0; elseif (y <= 4.6e-11) tmp = Float64(z * Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -2.06e-10) tmp = t_0; elseif (y <= 4.6e-11) tmp = z * (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.06e-10], t$95$0, If[LessEqual[y, 4.6e-11], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -2.06 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{-11}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.0600000000000001e-10 or 4.60000000000000027e-11 < y Initial program 97.7%
Taylor expanded in y 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--.f6497.7%
Simplified97.7%
if -2.0600000000000001e-10 < y < 4.60000000000000027e-11Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
--lowering--.f6473.1%
Simplified73.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -4.3e-12) t_0 (if (<= y 2.6e-17) z t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -4.3e-12) {
tmp = t_0;
} else if (y <= 2.6e-17) {
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 = y * (x - z)
if (y <= (-4.3d-12)) then
tmp = t_0
else if (y <= 2.6d-17) 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 = y * (x - z);
double tmp;
if (y <= -4.3e-12) {
tmp = t_0;
} else if (y <= 2.6e-17) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -4.3e-12: tmp = t_0 elif y <= 2.6e-17: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -4.3e-12) tmp = t_0; elseif (y <= 2.6e-17) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -4.3e-12) tmp = t_0; elseif (y <= 2.6e-17) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.3e-12], t$95$0, If[LessEqual[y, 2.6e-17], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-17}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.29999999999999985e-12 or 2.60000000000000003e-17 < y Initial program 97.7%
Taylor expanded in y 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--.f6497.0%
Simplified97.0%
if -4.29999999999999985e-12 < y < 2.60000000000000003e-17Initial program 100.0%
Taylor expanded in y around 0
Simplified73.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e-12) (* x y) (if (<= y 2.1e-16) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e-12) {
tmp = x * y;
} else if (y <= 2.1e-16) {
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.1d-12)) then
tmp = x * y
else if (y <= 2.1d-16) 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.1e-12) {
tmp = x * y;
} else if (y <= 2.1e-16) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e-12: tmp = x * y elif y <= 2.1e-16: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e-12) tmp = Float64(x * y); elseif (y <= 2.1e-16) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e-12) tmp = x * y; elseif (y <= 2.1e-16) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e-12], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.1e-16], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-12}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-16}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.09999999999999996e-12 or 2.1000000000000001e-16 < y Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6450.7%
Simplified50.7%
if -1.09999999999999996e-12 < y < 2.1000000000000001e-16Initial program 100.0%
Taylor expanded in y around 0
Simplified73.3%
Final simplification61.5%
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (y * (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 = z + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 98.8%
+-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.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 98.8%
Taylor expanded in y around 0
Simplified37.4%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - 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 = z - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024150
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))