
(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 5 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 (+ 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 97.2%
+-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 (let* ((t_0 (* y (- x z)))) (if (<= y -7.3e+19) t_0 (if (<= y 4.5e-24) (+ z (* y x)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -7.3e+19) {
tmp = t_0;
} else if (y <= 4.5e-24) {
tmp = z + (y * x);
} 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 <= (-7.3d+19)) then
tmp = t_0
else if (y <= 4.5d-24) then
tmp = z + (y * x)
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 <= -7.3e+19) {
tmp = t_0;
} else if (y <= 4.5e-24) {
tmp = z + (y * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -7.3e+19: tmp = t_0 elif y <= 4.5e-24: tmp = z + (y * x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -7.3e+19) tmp = t_0; elseif (y <= 4.5e-24) tmp = Float64(z + Float64(y * x)); 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 <= -7.3e+19) tmp = t_0; elseif (y <= 4.5e-24) tmp = z + (y * x); 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, -7.3e+19], t$95$0, If[LessEqual[y, 4.5e-24], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -7.3 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-24}:\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.3e19 or 4.4999999999999997e-24 < y Initial program 94.5%
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.7%
Simplified98.7%
if -7.3e19 < y < 4.4999999999999997e-24Initial program 100.0%
Taylor expanded in y around 0
Simplified99.4%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -1.3e-31) t_0 (if (<= y 2.6e-42) z t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -1.3e-31) {
tmp = t_0;
} else if (y <= 2.6e-42) {
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 <= (-1.3d-31)) then
tmp = t_0
else if (y <= 2.6d-42) 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 <= -1.3e-31) {
tmp = t_0;
} else if (y <= 2.6e-42) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -1.3e-31: tmp = t_0 elif y <= 2.6e-42: 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 <= -1.3e-31) tmp = t_0; elseif (y <= 2.6e-42) 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 <= -1.3e-31) tmp = t_0; elseif (y <= 2.6e-42) 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, -1.3e-31], t$95$0, If[LessEqual[y, 2.6e-42], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -1.3 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-42}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.29999999999999998e-31 or 2.6e-42 < y Initial program 94.9%
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.3%
Simplified97.3%
if -1.29999999999999998e-31 < y < 2.6e-42Initial program 100.0%
Taylor expanded in y around 0
Simplified83.5%
(FPCore (x y z) :precision binary64 (if (<= y -2.2e-32) (* y x) (if (<= y 2.5e-41) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-32) {
tmp = y * x;
} else if (y <= 2.5e-41) {
tmp = z;
} else {
tmp = y * x;
}
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 <= (-2.2d-32)) then
tmp = y * x
else if (y <= 2.5d-41) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-32) {
tmp = y * x;
} else if (y <= 2.5e-41) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e-32: tmp = y * x elif y <= 2.5e-41: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e-32) tmp = Float64(y * x); elseif (y <= 2.5e-41) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.2e-32) tmp = y * x; elseif (y <= 2.5e-41) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e-32], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.5e-41], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-32}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-41}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.2e-32 or 2.4999999999999998e-41 < y Initial program 94.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6461.0%
Simplified61.0%
if -2.2e-32 < y < 2.4999999999999998e-41Initial program 100.0%
Taylor expanded in y around 0
Simplified83.5%
(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 97.2%
Taylor expanded in y around 0
Simplified40.6%
(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 2024145
(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))))