
(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.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.8e-22)
(* y x)
(if (<= y 3.9e-17)
z
(if (or (<= y 1.15e+70) (and (not (<= y 3.8e+245)) (<= y 2.85e+293)))
(* y x)
(* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e-22) {
tmp = y * x;
} else if (y <= 3.9e-17) {
tmp = z;
} else if ((y <= 1.15e+70) || (!(y <= 3.8e+245) && (y <= 2.85e+293))) {
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 <= (-1.8d-22)) then
tmp = y * x
else if (y <= 3.9d-17) then
tmp = z
else if ((y <= 1.15d+70) .or. (.not. (y <= 3.8d+245)) .and. (y <= 2.85d+293)) 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 <= -1.8e-22) {
tmp = y * x;
} else if (y <= 3.9e-17) {
tmp = z;
} else if ((y <= 1.15e+70) || (!(y <= 3.8e+245) && (y <= 2.85e+293))) {
tmp = y * x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.8e-22: tmp = y * x elif y <= 3.9e-17: tmp = z elif (y <= 1.15e+70) or (not (y <= 3.8e+245) and (y <= 2.85e+293)): tmp = y * x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.8e-22) tmp = Float64(y * x); elseif (y <= 3.9e-17) tmp = z; elseif ((y <= 1.15e+70) || (!(y <= 3.8e+245) && (y <= 2.85e+293))) 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 <= -1.8e-22) tmp = y * x; elseif (y <= 3.9e-17) tmp = z; elseif ((y <= 1.15e+70) || (~((y <= 3.8e+245)) && (y <= 2.85e+293))) tmp = y * x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.8e-22], N[(y * x), $MachinePrecision], If[LessEqual[y, 3.9e-17], z, If[Or[LessEqual[y, 1.15e+70], And[N[Not[LessEqual[y, 3.8e+245]], $MachinePrecision], LessEqual[y, 2.85e+293]]], N[(y * x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-22}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{-17}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+70} \lor \neg \left(y \leq 3.8 \cdot 10^{+245}\right) \land y \leq 2.85 \cdot 10^{+293}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -1.7999999999999999e-22 or 3.89999999999999989e-17 < y < 1.14999999999999997e70 or 3.8e245 < y < 2.84999999999999993e293Initial program 97.8%
Taylor expanded in x around inf 73.6%
*-commutative73.6%
Simplified73.6%
if -1.7999999999999999e-22 < y < 3.89999999999999989e-17Initial program 100.0%
Taylor expanded in y around 0 70.5%
if 1.14999999999999997e70 < y < 3.8e245 or 2.84999999999999993e293 < y Initial program 97.6%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 74.5%
associate-*r*74.5%
neg-mul-174.5%
*-commutative74.5%
Simplified74.5%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e-22) (not (<= y 1.52e-16))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-22) || !(y <= 1.52e-16)) {
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 <= (-1.4d-22)) .or. (.not. (y <= 1.52d-16))) 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 <= -1.4e-22) || !(y <= 1.52e-16)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e-22) or not (y <= 1.52e-16): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e-22) || !(y <= 1.52e-16)) 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 <= -1.4e-22) || ~((y <= 1.52e-16))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e-22], N[Not[LessEqual[y, 1.52e-16]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-22} \lor \neg \left(y \leq 1.52 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.39999999999999997e-22 or 1.52e-16 < y Initial program 97.7%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
if -1.39999999999999997e-22 < y < 1.52e-16Initial program 100.0%
Taylor expanded in y around 0 70.5%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-22) (not (<= y 2.8e-17))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-22) || !(y <= 2.8e-17)) {
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 <= (-1.5d-22)) .or. (.not. (y <= 2.8d-17))) 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 <= -1.5e-22) || !(y <= 2.8e-17)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-22) or not (y <= 2.8e-17): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-22) || !(y <= 2.8e-17)) 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 <= -1.5e-22) || ~((y <= 2.8e-17))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-22], N[Not[LessEqual[y, 2.8e-17]], $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 -1.5 \cdot 10^{-22} \lor \neg \left(y \leq 2.8 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.5e-22 or 2.7999999999999999e-17 < y Initial program 97.7%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
if -1.5e-22 < y < 2.7999999999999999e-17Initial program 100.0%
Taylor expanded in x around 0 70.5%
Final simplification84.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 97.5%
Taylor expanded in y around inf 99.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
if -1 < y < 1Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.7%
mul-1-neg99.7%
distribute-lft-neg-out99.7%
*-commutative99.7%
Simplified99.7%
sub-neg99.7%
+-commutative99.7%
distribute-rgt-neg-out99.7%
remove-double-neg99.7%
Applied egg-rr99.7%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-23) (not (<= y 5.3e-17))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-23) || !(y <= 5.3e-17)) {
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 ((y <= (-9d-23)) .or. (.not. (y <= 5.3d-17))) 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 ((y <= -9e-23) || !(y <= 5.3e-17)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-23) or not (y <= 5.3e-17): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-23) || !(y <= 5.3e-17)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e-23) || ~((y <= 5.3e-17))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-23], N[Not[LessEqual[y, 5.3e-17]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-23} \lor \neg \left(y \leq 5.3 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -8.9999999999999995e-23 or 5.2999999999999998e-17 < y Initial program 97.7%
Taylor expanded in x around inf 60.4%
*-commutative60.4%
Simplified60.4%
if -8.9999999999999995e-23 < y < 5.2999999999999998e-17Initial program 100.0%
Taylor expanded in y around 0 70.5%
Final simplification65.3%
(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%
+-commutative98.8%
+-lft-identity98.8%
cancel-sign-sub98.8%
cancel-sign-sub98.8%
+-lft-identity98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
associate-+l-98.8%
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.8%
Taylor expanded in y around 0 36.0%
Final simplification36.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 2024059
(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))))