
(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 (+ 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.6%
+-commutative97.6%
+-lft-identity97.6%
cancel-sign-sub97.6%
cancel-sign-sub97.6%
+-lft-identity97.6%
distribute-lft-out--97.6%
*-rgt-identity97.6%
associate-+l-97.6%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -8.5e+164)
t_0
(if (<= y -9.2e-39)
(* y x)
(if (<= y -1.15e-108)
z
(if (<= y -1.44e-164)
(* y x)
(if (<= y 5.4e-37)
z
(if (or (<= y 1.26e+116) (not (<= y 7.8e+167)))
(* y x)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -8.5e+164) {
tmp = t_0;
} else if (y <= -9.2e-39) {
tmp = y * x;
} else if (y <= -1.15e-108) {
tmp = z;
} else if (y <= -1.44e-164) {
tmp = y * x;
} else if (y <= 5.4e-37) {
tmp = z;
} else if ((y <= 1.26e+116) || !(y <= 7.8e+167)) {
tmp = 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 * -z
if (y <= (-8.5d+164)) then
tmp = t_0
else if (y <= (-9.2d-39)) then
tmp = y * x
else if (y <= (-1.15d-108)) then
tmp = z
else if (y <= (-1.44d-164)) then
tmp = y * x
else if (y <= 5.4d-37) then
tmp = z
else if ((y <= 1.26d+116) .or. (.not. (y <= 7.8d+167))) then
tmp = 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 * -z;
double tmp;
if (y <= -8.5e+164) {
tmp = t_0;
} else if (y <= -9.2e-39) {
tmp = y * x;
} else if (y <= -1.15e-108) {
tmp = z;
} else if (y <= -1.44e-164) {
tmp = y * x;
} else if (y <= 5.4e-37) {
tmp = z;
} else if ((y <= 1.26e+116) || !(y <= 7.8e+167)) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -8.5e+164: tmp = t_0 elif y <= -9.2e-39: tmp = y * x elif y <= -1.15e-108: tmp = z elif y <= -1.44e-164: tmp = y * x elif y <= 5.4e-37: tmp = z elif (y <= 1.26e+116) or not (y <= 7.8e+167): tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -8.5e+164) tmp = t_0; elseif (y <= -9.2e-39) tmp = Float64(y * x); elseif (y <= -1.15e-108) tmp = z; elseif (y <= -1.44e-164) tmp = Float64(y * x); elseif (y <= 5.4e-37) tmp = z; elseif ((y <= 1.26e+116) || !(y <= 7.8e+167)) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (y <= -8.5e+164) tmp = t_0; elseif (y <= -9.2e-39) tmp = y * x; elseif (y <= -1.15e-108) tmp = z; elseif (y <= -1.44e-164) tmp = y * x; elseif (y <= 5.4e-37) tmp = z; elseif ((y <= 1.26e+116) || ~((y <= 7.8e+167))) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -8.5e+164], t$95$0, If[LessEqual[y, -9.2e-39], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.15e-108], z, If[LessEqual[y, -1.44e-164], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.4e-37], z, If[Or[LessEqual[y, 1.26e+116], N[Not[LessEqual[y, 7.8e+167]], $MachinePrecision]], N[(y * x), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+164}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-39}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-108}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.44 \cdot 10^{-164}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-37}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{+116} \lor \neg \left(y \leq 7.8 \cdot 10^{+167}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.50000000000000027e164 or 1.2599999999999999e116 < y < 7.7999999999999996e167Initial program 95.7%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 68.8%
associate-*r*68.8%
*-commutative68.8%
mul-1-neg68.8%
Simplified68.8%
if -8.50000000000000027e164 < y < -9.20000000000000033e-39 or -1.14999999999999998e-108 < y < -1.43999999999999994e-164 or 5.40000000000000032e-37 < y < 1.2599999999999999e116 or 7.7999999999999996e167 < y Initial program 96.7%
Taylor expanded in x around inf 63.7%
*-commutative63.7%
Simplified63.7%
if -9.20000000000000033e-39 < y < -1.14999999999999998e-108 or -1.43999999999999994e-164 < y < 5.40000000000000032e-37Initial program 100.0%
Taylor expanded in y around 0 81.0%
Final simplification70.4%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.1e-38)
(and (not (<= y -6.1e-117))
(or (<= y -1.55e-164) (not (<= y 8.5e-39)))))
(* y (- x z))
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-38) || (!(y <= -6.1e-117) && ((y <= -1.55e-164) || !(y <= 8.5e-39)))) {
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.1d-38)) .or. (.not. (y <= (-6.1d-117))) .and. (y <= (-1.55d-164)) .or. (.not. (y <= 8.5d-39))) 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.1e-38) || (!(y <= -6.1e-117) && ((y <= -1.55e-164) || !(y <= 8.5e-39)))) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-38) or (not (y <= -6.1e-117) and ((y <= -1.55e-164) or not (y <= 8.5e-39))): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-38) || (!(y <= -6.1e-117) && ((y <= -1.55e-164) || !(y <= 8.5e-39)))) 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.1e-38) || (~((y <= -6.1e-117)) && ((y <= -1.55e-164) || ~((y <= 8.5e-39))))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-38], And[N[Not[LessEqual[y, -6.1e-117]], $MachinePrecision], Or[LessEqual[y, -1.55e-164], N[Not[LessEqual[y, 8.5e-39]], $MachinePrecision]]]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-38} \lor \neg \left(y \leq -6.1 \cdot 10^{-117}\right) \land \left(y \leq -1.55 \cdot 10^{-164} \lor \neg \left(y \leq 8.5 \cdot 10^{-39}\right)\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.10000000000000004e-38 or -6.10000000000000002e-117 < y < -1.55e-164 or 8.5000000000000005e-39 < y Initial program 96.5%
Taylor expanded in y around inf 92.9%
mul-1-neg92.9%
sub-neg92.9%
Simplified92.9%
if -1.10000000000000004e-38 < y < -6.10000000000000002e-117 or -1.55e-164 < y < 8.5000000000000005e-39Initial program 100.0%
Taylor expanded in y around 0 81.0%
Final simplification88.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.02e-38)
(and (not (<= y -5.5e-112))
(or (<= y -1.55e-164) (not (<= y 6.2e+15)))))
(* y (- x z))
(* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e-38) || (!(y <= -5.5e-112) && ((y <= -1.55e-164) || !(y <= 6.2e+15)))) {
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.02d-38)) .or. (.not. (y <= (-5.5d-112))) .and. (y <= (-1.55d-164)) .or. (.not. (y <= 6.2d+15))) 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.02e-38) || (!(y <= -5.5e-112) && ((y <= -1.55e-164) || !(y <= 6.2e+15)))) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.02e-38) or (not (y <= -5.5e-112) and ((y <= -1.55e-164) or not (y <= 6.2e+15))): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.02e-38) || (!(y <= -5.5e-112) && ((y <= -1.55e-164) || !(y <= 6.2e+15)))) 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.02e-38) || (~((y <= -5.5e-112)) && ((y <= -1.55e-164) || ~((y <= 6.2e+15))))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.02e-38], And[N[Not[LessEqual[y, -5.5e-112]], $MachinePrecision], Or[LessEqual[y, -1.55e-164], N[Not[LessEqual[y, 6.2e+15]], $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.02 \cdot 10^{-38} \lor \neg \left(y \leq -5.5 \cdot 10^{-112}\right) \land \left(y \leq -1.55 \cdot 10^{-164} \lor \neg \left(y \leq 6.2 \cdot 10^{+15}\right)\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.01999999999999998e-38 or -5.5e-112 < y < -1.55e-164 or 6.2e15 < y Initial program 96.1%
Taylor expanded in y around inf 96.1%
mul-1-neg96.1%
sub-neg96.1%
Simplified96.1%
if -1.01999999999999998e-38 < y < -5.5e-112 or -1.55e-164 < y < 6.2e15Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification89.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.06e-38)
(not
(or (<= y -1.45e-118) (and (not (<= y -1.32e-164)) (<= y 1.8e-36)))))
(* y x)
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.06e-38) || !((y <= -1.45e-118) || (!(y <= -1.32e-164) && (y <= 1.8e-36)))) {
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 <= (-1.06d-38)) .or. (.not. (y <= (-1.45d-118)) .or. (.not. (y <= (-1.32d-164))) .and. (y <= 1.8d-36))) 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 <= -1.06e-38) || !((y <= -1.45e-118) || (!(y <= -1.32e-164) && (y <= 1.8e-36)))) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.06e-38) or not ((y <= -1.45e-118) or (not (y <= -1.32e-164) and (y <= 1.8e-36))): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.06e-38) || !((y <= -1.45e-118) || (!(y <= -1.32e-164) && (y <= 1.8e-36)))) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.06e-38) || ~(((y <= -1.45e-118) || (~((y <= -1.32e-164)) && (y <= 1.8e-36))))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.06e-38], N[Not[Or[LessEqual[y, -1.45e-118], And[N[Not[LessEqual[y, -1.32e-164]], $MachinePrecision], LessEqual[y, 1.8e-36]]]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-38} \lor \neg \left(y \leq -1.45 \cdot 10^{-118} \lor \neg \left(y \leq -1.32 \cdot 10^{-164}\right) \land y \leq 1.8 \cdot 10^{-36}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.06000000000000001e-38 or -1.4499999999999999e-118 < y < -1.3199999999999999e-164 or 1.80000000000000016e-36 < y Initial program 96.5%
Taylor expanded in x around inf 56.1%
*-commutative56.1%
Simplified56.1%
if -1.06000000000000001e-38 < y < -1.4499999999999999e-118 or -1.3199999999999999e-164 < y < 1.80000000000000016e-36Initial program 100.0%
Taylor expanded in y around 0 81.0%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.16))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.16)) {
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 <= 0.16d0))) 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 <= 0.16)) {
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 <= 0.16): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.16)) 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 <= 0.16))) 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, 0.16]], $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 0.16\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 0.160000000000000003 < y Initial program 95.8%
Taylor expanded in y around inf 96.9%
mul-1-neg96.9%
sub-neg96.9%
Simplified96.9%
if -1 < y < 0.160000000000000003Initial 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 98.9%
mul-1-neg98.9%
distribute-lft-neg-out98.9%
*-commutative98.9%
Simplified98.9%
Final simplification97.7%
(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.6%
Taylor expanded in y around 0 31.4%
Final simplification31.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 2024041
(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))))