
(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 8 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 y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -4.8e-15)
(* y x)
(if (<= y 1.5e-119)
z
(if (<= y 8.5e-52)
(* y x)
(if (<= y 1.12e-33) z (if (<= y 1.7e+59) (* y x) (* y (- z))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-15) {
tmp = y * x;
} else if (y <= 1.5e-119) {
tmp = z;
} else if (y <= 8.5e-52) {
tmp = y * x;
} else if (y <= 1.12e-33) {
tmp = z;
} else if (y <= 1.7e+59) {
tmp = y * x;
} else {
tmp = y * -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 (y <= (-4.8d-15)) then
tmp = y * x
else if (y <= 1.5d-119) then
tmp = z
else if (y <= 8.5d-52) then
tmp = y * x
else if (y <= 1.12d-33) then
tmp = z
else if (y <= 1.7d+59) then
tmp = y * x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-15) {
tmp = y * x;
} else if (y <= 1.5e-119) {
tmp = z;
} else if (y <= 8.5e-52) {
tmp = y * x;
} else if (y <= 1.12e-33) {
tmp = z;
} else if (y <= 1.7e+59) {
tmp = y * x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e-15: tmp = y * x elif y <= 1.5e-119: tmp = z elif y <= 8.5e-52: tmp = y * x elif y <= 1.12e-33: tmp = z elif y <= 1.7e+59: tmp = y * x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e-15) tmp = Float64(y * x); elseif (y <= 1.5e-119) tmp = z; elseif (y <= 8.5e-52) tmp = Float64(y * x); elseif (y <= 1.12e-33) tmp = z; elseif (y <= 1.7e+59) tmp = Float64(y * x); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e-15) tmp = y * x; elseif (y <= 1.5e-119) tmp = z; elseif (y <= 8.5e-52) tmp = y * x; elseif (y <= 1.12e-33) tmp = z; elseif (y <= 1.7e+59) tmp = y * x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e-15], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.5e-119], z, If[LessEqual[y, 8.5e-52], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.12e-33], z, If[LessEqual[y, 1.7e+59], N[(y * x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-15}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-119}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-52}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.12 \cdot 10^{-33}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+59}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -4.7999999999999999e-15 or 1.5000000000000001e-119 < y < 8.50000000000000006e-52 or 1.11999999999999999e-33 < y < 1.70000000000000003e59Initial program 99.1%
Taylor expanded in x around inf 55.2%
*-commutative55.2%
Simplified55.2%
if -4.7999999999999999e-15 < y < 1.5000000000000001e-119 or 8.50000000000000006e-52 < y < 1.11999999999999999e-33Initial program 100.0%
Taylor expanded in y around 0 74.8%
if 1.70000000000000003e59 < y Initial program 92.2%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 66.4%
associate-*r*66.4%
neg-mul-166.4%
Simplified66.4%
Final simplification64.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -2.6e-14)
t_0
(if (<= y 2.2e-119)
z
(if (<= y 9.5e-52) (* y x) (if (<= y 1.9e-33) z t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -2.6e-14) {
tmp = t_0;
} else if (y <= 2.2e-119) {
tmp = z;
} else if (y <= 9.5e-52) {
tmp = y * x;
} else if (y <= 1.9e-33) {
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 <= (-2.6d-14)) then
tmp = t_0
else if (y <= 2.2d-119) then
tmp = z
else if (y <= 9.5d-52) then
tmp = y * x
else if (y <= 1.9d-33) 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 <= -2.6e-14) {
tmp = t_0;
} else if (y <= 2.2e-119) {
tmp = z;
} else if (y <= 9.5e-52) {
tmp = y * x;
} else if (y <= 1.9e-33) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -2.6e-14: tmp = t_0 elif y <= 2.2e-119: tmp = z elif y <= 9.5e-52: tmp = y * x elif y <= 1.9e-33: 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 <= -2.6e-14) tmp = t_0; elseif (y <= 2.2e-119) tmp = z; elseif (y <= 9.5e-52) tmp = Float64(y * x); elseif (y <= 1.9e-33) 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 <= -2.6e-14) tmp = t_0; elseif (y <= 2.2e-119) tmp = z; elseif (y <= 9.5e-52) tmp = y * x; elseif (y <= 1.9e-33) 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, -2.6e-14], t$95$0, If[LessEqual[y, 2.2e-119], z, If[LessEqual[y, 9.5e-52], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.9e-33], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -2.6 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-119}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-52}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-33}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.59999999999999997e-14 or 1.89999999999999997e-33 < y Initial program 96.6%
Taylor expanded in y around inf 95.0%
mul-1-neg95.0%
sub-neg95.0%
Simplified95.0%
if -2.59999999999999997e-14 < y < 2.2000000000000001e-119 or 9.50000000000000007e-52 < y < 1.89999999999999997e-33Initial program 100.0%
Taylor expanded in y around 0 74.8%
if 2.2000000000000001e-119 < y < 9.50000000000000007e-52Initial program 100.0%
Taylor expanded in x around inf 62.7%
*-commutative62.7%
Simplified62.7%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e-70) (not (<= x 9e-7))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-70) || !(x <= 9e-7)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - 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 <= (-1d-70)) .or. (.not. (x <= 9d-7))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-70) || !(x <= 9e-7)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-70) or not (x <= 9e-7): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-70) || !(x <= 9e-7)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1e-70) || ~((x <= 9e-7))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-70], N[Not[LessEqual[x, 9e-7]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-70} \lor \neg \left(x \leq 9 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -9.99999999999999996e-71 or 8.99999999999999959e-7 < x Initial program 96.4%
Taylor expanded in y around inf 83.9%
mul-1-neg83.9%
sub-neg83.9%
Simplified83.9%
if -9.99999999999999996e-71 < x < 8.99999999999999959e-7Initial program 100.0%
Taylor expanded in x around 0 92.7%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 96.2%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
if -1 < y < 1Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
distribute-lft-neg-out100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-neg-out100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 98.1%
mul-1-neg98.1%
distribute-lft-neg-out98.1%
*-commutative98.1%
Simplified98.1%
sub-neg98.1%
distribute-rgt-neg-out98.1%
remove-double-neg98.1%
+-commutative98.1%
Applied egg-rr98.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-76) (not (<= x 5.5e-16))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-76) || !(x <= 5.5e-16)) {
tmp = y * x;
} else {
tmp = 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 <= (-5.5d-76)) .or. (.not. (x <= 5.5d-16))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-76) || !(x <= 5.5e-16)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-76) or not (x <= 5.5e-16): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-76) || !(x <= 5.5e-16)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e-76) || ~((x <= 5.5e-16))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-76], N[Not[LessEqual[x, 5.5e-16]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-76} \lor \neg \left(x \leq 5.5 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.50000000000000014e-76 or 5.49999999999999964e-16 < x Initial program 96.4%
Taylor expanded in x around inf 69.1%
*-commutative69.1%
Simplified69.1%
if -5.50000000000000014e-76 < x < 5.49999999999999964e-16Initial program 100.0%
Taylor expanded in y around 0 51.4%
Final simplification61.2%
(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.0%
+-commutative98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
+-commutative98.0%
associate-+l+98.0%
distribute-lft-neg-out98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
distribute-neg-out98.0%
sub-neg98.0%
distribute-rgt-neg-out98.0%
sub-neg98.0%
distribute-rgt-out--100.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.0%
Taylor expanded in y around 0 32.0%
Final simplification32.0%
(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 2024112
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))