
(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 96.1%
+-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
*-lft-identity96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
neg-mul-196.1%
associate-*r*96.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -4.3e-8)
(* y x)
(if (<= y 6000.0)
z
(if (or (<= y 2.1e+209) (and (not (<= y 1.25e+263)) (<= y 8.5e+288)))
(* y (- z))
(* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.3e-8) {
tmp = y * x;
} else if (y <= 6000.0) {
tmp = z;
} else if ((y <= 2.1e+209) || (!(y <= 1.25e+263) && (y <= 8.5e+288))) {
tmp = y * -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 <= (-4.3d-8)) then
tmp = y * x
else if (y <= 6000.0d0) then
tmp = z
else if ((y <= 2.1d+209) .or. (.not. (y <= 1.25d+263)) .and. (y <= 8.5d+288)) then
tmp = y * -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 <= -4.3e-8) {
tmp = y * x;
} else if (y <= 6000.0) {
tmp = z;
} else if ((y <= 2.1e+209) || (!(y <= 1.25e+263) && (y <= 8.5e+288))) {
tmp = y * -z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.3e-8: tmp = y * x elif y <= 6000.0: tmp = z elif (y <= 2.1e+209) or (not (y <= 1.25e+263) and (y <= 8.5e+288)): tmp = y * -z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.3e-8) tmp = Float64(y * x); elseif (y <= 6000.0) tmp = z; elseif ((y <= 2.1e+209) || (!(y <= 1.25e+263) && (y <= 8.5e+288))) tmp = Float64(y * Float64(-z)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.3e-8) tmp = y * x; elseif (y <= 6000.0) tmp = z; elseif ((y <= 2.1e+209) || (~((y <= 1.25e+263)) && (y <= 8.5e+288))) tmp = y * -z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.3e-8], N[(y * x), $MachinePrecision], If[LessEqual[y, 6000.0], z, If[Or[LessEqual[y, 2.1e+209], And[N[Not[LessEqual[y, 1.25e+263]], $MachinePrecision], LessEqual[y, 8.5e+288]]], N[(y * (-z)), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6000:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+209} \lor \neg \left(y \leq 1.25 \cdot 10^{+263}\right) \land y \leq 8.5 \cdot 10^{+288}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.3000000000000001e-8 or 2.1e209 < y < 1.25000000000000006e263 or 8.4999999999999997e288 < y Initial program 90.9%
Taylor expanded in x around inf 59.0%
if -4.3000000000000001e-8 < y < 6e3Initial program 100.0%
Taylor expanded in y around 0 70.4%
if 6e3 < y < 2.1e209 or 1.25000000000000006e263 < y < 8.4999999999999997e288Initial program 94.6%
Taylor expanded in y around inf 98.2%
neg-mul-198.2%
+-commutative98.2%
sub-neg98.2%
Simplified98.2%
Taylor expanded in x around 0 62.1%
mul-1-neg62.1%
*-commutative62.1%
distribute-rgt-neg-in62.1%
Simplified62.1%
Final simplification65.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -6e-58) (not (<= y 0.00055))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6e-58) || !(y <= 0.00055)) {
tmp = y * (x - z);
} 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 ((y <= (-6d-58)) .or. (.not. (y <= 0.00055d0))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6e-58) || !(y <= 0.00055)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6e-58) or not (y <= 0.00055): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6e-58) || !(y <= 0.00055)) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6e-58) || ~((y <= 0.00055))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6e-58], N[Not[LessEqual[y, 0.00055]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-58} \lor \neg \left(y \leq 0.00055\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -6.00000000000000015e-58 or 5.50000000000000033e-4 < y Initial program 93.1%
Taylor expanded in y around inf 95.8%
neg-mul-195.8%
+-commutative95.8%
sub-neg95.8%
Simplified95.8%
if -6.00000000000000015e-58 < y < 5.50000000000000033e-4Initial program 100.0%
Taylor expanded in y around 0 73.9%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e-8) (not (<= y 0.053))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-8) || !(y <= 0.053)) {
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 ((y <= (-5.5d-8)) .or. (.not. (y <= 0.053d0))) 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 ((y <= -5.5e-8) || !(y <= 0.053)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e-8) or not (y <= 0.053): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e-8) || !(y <= 0.053)) 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 ((y <= -5.5e-8) || ~((y <= 0.053))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e-8], N[Not[LessEqual[y, 0.053]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-8} \lor \neg \left(y \leq 0.053\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -5.5000000000000003e-8 or 0.0529999999999999985 < y Initial program 92.6%
Taylor expanded in y around inf 98.8%
neg-mul-198.8%
+-commutative98.8%
sub-neg98.8%
Simplified98.8%
if -5.5000000000000003e-8 < y < 0.0529999999999999985Initial program 100.0%
Taylor expanded in x around 0 73.4%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7e-8) (not (<= y 0.146))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-8) || !(y <= 0.146)) {
tmp = y * (x - z);
} else {
tmp = z - (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 <= (-3.7d-8)) .or. (.not. (y <= 0.146d0))) then
tmp = y * (x - z)
else
tmp = z - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-8) || !(y <= 0.146)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e-8) or not (y <= 0.146): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e-8) || !(y <= 0.146)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.7e-8) || ~((y <= 0.146))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e-8], N[Not[LessEqual[y, 0.146]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-8} \lor \neg \left(y \leq 0.146\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if y < -3.7e-8 or 0.145999999999999991 < y Initial program 92.6%
Taylor expanded in y around inf 98.8%
neg-mul-198.8%
+-commutative98.8%
sub-neg98.8%
Simplified98.8%
if -3.7e-8 < y < 0.145999999999999991Initial program 100.0%
Taylor expanded in x around 0 73.4%
distribute-lft-out--73.4%
*-rgt-identity73.4%
Simplified73.4%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.3e-8) (* y x) (if (<= y 1.5e-26) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e-8) {
tmp = y * x;
} else if (y <= 1.5e-26) {
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.3d-8)) then
tmp = y * x
else if (y <= 1.5d-26) 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.3e-8) {
tmp = y * x;
} else if (y <= 1.5e-26) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.3e-8: tmp = y * x elif y <= 1.5e-26: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.3e-8) tmp = Float64(y * x); elseif (y <= 1.5e-26) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.3e-8) tmp = y * x; elseif (y <= 1.5e-26) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.3e-8], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.5e-26], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-26}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.3000000000000001e-8 or 1.50000000000000006e-26 < y Initial program 92.9%
Taylor expanded in x around inf 51.1%
if -2.3000000000000001e-8 < y < 1.50000000000000006e-26Initial program 100.0%
Taylor expanded in y around 0 73.3%
Final simplification61.1%
(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 96.1%
+-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
*-lft-identity96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
neg-mul-196.1%
associate-*r*96.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.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 96.1%
Taylor expanded in y around 0 35.3%
Final simplification35.3%
(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 2023278
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))