
(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 (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.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
+-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -215000.0)
t_0
(if (<= y -1.28e-42)
(* y x)
(if (<= y 5.6e-45)
z
(if (or (<= y 5.5e+97) (not (<= y 4.3e+257))) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -215000.0) {
tmp = t_0;
} else if (y <= -1.28e-42) {
tmp = y * x;
} else if (y <= 5.6e-45) {
tmp = z;
} else if ((y <= 5.5e+97) || !(y <= 4.3e+257)) {
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 <= (-215000.0d0)) then
tmp = t_0
else if (y <= (-1.28d-42)) then
tmp = y * x
else if (y <= 5.6d-45) then
tmp = z
else if ((y <= 5.5d+97) .or. (.not. (y <= 4.3d+257))) 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 <= -215000.0) {
tmp = t_0;
} else if (y <= -1.28e-42) {
tmp = y * x;
} else if (y <= 5.6e-45) {
tmp = z;
} else if ((y <= 5.5e+97) || !(y <= 4.3e+257)) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -215000.0: tmp = t_0 elif y <= -1.28e-42: tmp = y * x elif y <= 5.6e-45: tmp = z elif (y <= 5.5e+97) or not (y <= 4.3e+257): 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 <= -215000.0) tmp = t_0; elseif (y <= -1.28e-42) tmp = Float64(y * x); elseif (y <= 5.6e-45) tmp = z; elseif ((y <= 5.5e+97) || !(y <= 4.3e+257)) 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 <= -215000.0) tmp = t_0; elseif (y <= -1.28e-42) tmp = y * x; elseif (y <= 5.6e-45) tmp = z; elseif ((y <= 5.5e+97) || ~((y <= 4.3e+257))) 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, -215000.0], t$95$0, If[LessEqual[y, -1.28e-42], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.6e-45], z, If[Or[LessEqual[y, 5.5e+97], N[Not[LessEqual[y, 4.3e+257]], $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 -215000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.28 \cdot 10^{-42}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-45}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+97} \lor \neg \left(y \leq 4.3 \cdot 10^{+257}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -215000 or 5.50000000000000021e97 < y < 4.2999999999999998e257Initial program 97.7%
Taylor expanded in x around 0 60.5%
Taylor expanded in y around inf 59.2%
mul-1-neg59.2%
distribute-lft-neg-out59.2%
*-commutative59.2%
Simplified59.2%
if -215000 < y < -1.27999999999999994e-42 or 5.6000000000000003e-45 < y < 5.50000000000000021e97 or 4.2999999999999998e257 < y Initial program 96.2%
Taylor expanded in x around inf 79.1%
*-commutative79.1%
Simplified79.1%
if -1.27999999999999994e-42 < y < 5.6000000000000003e-45Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.1e-43) (not (<= y 8e-45))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1e-43) || !(y <= 8e-45)) {
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 <= (-3.1d-43)) .or. (.not. (y <= 8d-45))) 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 <= -3.1e-43) || !(y <= 8e-45)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.1e-43) or not (y <= 8e-45): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.1e-43) || !(y <= 8e-45)) 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 <= -3.1e-43) || ~((y <= 8e-45))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.1e-43], N[Not[LessEqual[y, 8e-45]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-43} \lor \neg \left(y \leq 8 \cdot 10^{-45}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.0999999999999999e-43 or 7.99999999999999987e-45 < y Initial program 97.1%
Taylor expanded in y around inf 95.1%
mul-1-neg95.1%
sub-neg95.1%
Simplified95.1%
if -3.0999999999999999e-43 < y < 7.99999999999999987e-45Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -64000.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -64000.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 <= (-64000.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 <= -64000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -64000.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 <= -64000.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 <= -64000.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, -64000.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 -64000 \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 < -64000 or 1 < y Initial program 96.7%
Taylor expanded in y around inf 98.6%
mul-1-neg98.6%
sub-neg98.6%
Simplified98.6%
if -64000 < 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.0%
mul-1-neg99.0%
distribute-lft-neg-out99.0%
*-commutative99.0%
Simplified99.0%
sub-neg99.0%
+-commutative99.0%
distribute-rgt-neg-out99.0%
remove-double-neg99.0%
Applied egg-rr99.0%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.2e-45) (not (<= y 3.2e-45))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-45) || !(y <= 3.2e-45)) {
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 <= (-6.2d-45)) .or. (.not. (y <= 3.2d-45))) 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 <= -6.2e-45) || !(y <= 3.2e-45)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-45) or not (y <= 3.2e-45): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-45) || !(y <= 3.2e-45)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-45) || ~((y <= 3.2e-45))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-45], N[Not[LessEqual[y, 3.2e-45]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-45} \lor \neg \left(y \leq 3.2 \cdot 10^{-45}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -6.2000000000000002e-45 or 3.20000000000000007e-45 < y Initial program 97.1%
Taylor expanded in x around inf 56.0%
*-commutative56.0%
Simplified56.0%
if -6.2000000000000002e-45 < y < 3.20000000000000007e-45Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification64.7%
(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.4%
+-commutative98.4%
+-lft-identity98.4%
cancel-sign-sub98.4%
cancel-sign-sub98.4%
+-lft-identity98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
associate-+l-98.4%
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.4%
Taylor expanded in y around 0 37.0%
Final simplification37.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 2024031
(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))))