
(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 97.7%
+-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.7%
*-lft-identity97.7%
associate-+l+97.7%
+-commutative97.7%
*-commutative97.7%
neg-mul-197.7%
associate-*r*97.7%
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 (let* ((t_0 (+ (* z (- 1.0 y)) (* y x)))) (if (<= t_0 5e+302) t_0 (* y (- x z)))))
double code(double x, double y, double z) {
double t_0 = (z * (1.0 - y)) + (y * x);
double tmp;
if (t_0 <= 5e+302) {
tmp = t_0;
} else {
tmp = y * (x - 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) :: t_0
real(8) :: tmp
t_0 = (z * (1.0d0 - y)) + (y * x)
if (t_0 <= 5d+302) then
tmp = t_0
else
tmp = y * (x - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z * (1.0 - y)) + (y * x);
double tmp;
if (t_0 <= 5e+302) {
tmp = t_0;
} else {
tmp = y * (x - z);
}
return tmp;
}
def code(x, y, z): t_0 = (z * (1.0 - y)) + (y * x) tmp = 0 if t_0 <= 5e+302: tmp = t_0 else: tmp = y * (x - z) return tmp
function code(x, y, z) t_0 = Float64(Float64(z * Float64(1.0 - y)) + Float64(y * x)) tmp = 0.0 if (t_0 <= 5e+302) tmp = t_0; else tmp = Float64(y * Float64(x - z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z * (1.0 - y)) + (y * x); tmp = 0.0; if (t_0 <= 5e+302) tmp = t_0; else tmp = y * (x - z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+302], t$95$0, N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(1 - y\right) + y \cdot x\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) < 5e302Initial program 100.0%
if 5e302 < (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) Initial program 81.8%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -7.6e-77)
t_0
(if (<= y 9.4e-256)
z
(if (<= y 1.06e-244)
(* y x)
(if (<= y 7e-183)
z
(if (<= y 5.1e-138) (* y x) (if (<= y 3.6e-48) z t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -7.6e-77) {
tmp = t_0;
} else if (y <= 9.4e-256) {
tmp = z;
} else if (y <= 1.06e-244) {
tmp = y * x;
} else if (y <= 7e-183) {
tmp = z;
} else if (y <= 5.1e-138) {
tmp = y * x;
} else if (y <= 3.6e-48) {
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 <= (-7.6d-77)) then
tmp = t_0
else if (y <= 9.4d-256) then
tmp = z
else if (y <= 1.06d-244) then
tmp = y * x
else if (y <= 7d-183) then
tmp = z
else if (y <= 5.1d-138) then
tmp = y * x
else if (y <= 3.6d-48) 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 <= -7.6e-77) {
tmp = t_0;
} else if (y <= 9.4e-256) {
tmp = z;
} else if (y <= 1.06e-244) {
tmp = y * x;
} else if (y <= 7e-183) {
tmp = z;
} else if (y <= 5.1e-138) {
tmp = y * x;
} else if (y <= 3.6e-48) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -7.6e-77: tmp = t_0 elif y <= 9.4e-256: tmp = z elif y <= 1.06e-244: tmp = y * x elif y <= 7e-183: tmp = z elif y <= 5.1e-138: tmp = y * x elif y <= 3.6e-48: 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 <= -7.6e-77) tmp = t_0; elseif (y <= 9.4e-256) tmp = z; elseif (y <= 1.06e-244) tmp = Float64(y * x); elseif (y <= 7e-183) tmp = z; elseif (y <= 5.1e-138) tmp = Float64(y * x); elseif (y <= 3.6e-48) 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 <= -7.6e-77) tmp = t_0; elseif (y <= 9.4e-256) tmp = z; elseif (y <= 1.06e-244) tmp = y * x; elseif (y <= 7e-183) tmp = z; elseif (y <= 5.1e-138) tmp = y * x; elseif (y <= 3.6e-48) 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, -7.6e-77], t$95$0, If[LessEqual[y, 9.4e-256], z, If[LessEqual[y, 1.06e-244], N[(y * x), $MachinePrecision], If[LessEqual[y, 7e-183], z, If[LessEqual[y, 5.1e-138], N[(y * x), $MachinePrecision], If[LessEqual[y, 3.6e-48], z, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -7.6 \cdot 10^{-77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 9.4 \cdot 10^{-256}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{-244}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-183}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-138}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-48}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -7.5999999999999998e-77 or 3.6000000000000002e-48 < y Initial program 95.8%
Taylor expanded in y around inf 94.9%
+-commutative94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
if -7.5999999999999998e-77 < y < 9.39999999999999964e-256 or 1.05999999999999999e-244 < y < 6.99999999999999983e-183 or 5.1000000000000002e-138 < y < 3.6000000000000002e-48Initial program 100.0%
Taylor expanded in y around 0 84.2%
if 9.39999999999999964e-256 < y < 1.05999999999999999e-244 or 6.99999999999999983e-183 < y < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in x around inf 91.2%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e-62) z (if (<= z 1.8e+96) (* y x) (if (<= z 2.7e+213) (* z (- y)) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-62) {
tmp = z;
} else if (z <= 1.8e+96) {
tmp = y * x;
} else if (z <= 2.7e+213) {
tmp = z * -y;
} 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 (z <= (-8.5d-62)) then
tmp = z
else if (z <= 1.8d+96) then
tmp = y * x
else if (z <= 2.7d+213) then
tmp = z * -y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-62) {
tmp = z;
} else if (z <= 1.8e+96) {
tmp = y * x;
} else if (z <= 2.7e+213) {
tmp = z * -y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e-62: tmp = z elif z <= 1.8e+96: tmp = y * x elif z <= 2.7e+213: tmp = z * -y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e-62) tmp = z; elseif (z <= 1.8e+96) tmp = Float64(y * x); elseif (z <= 2.7e+213) tmp = Float64(z * Float64(-y)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e-62) tmp = z; elseif (z <= 1.8e+96) tmp = y * x; elseif (z <= 2.7e+213) tmp = z * -y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e-62], z, If[LessEqual[z, 1.8e+96], N[(y * x), $MachinePrecision], If[LessEqual[z, 2.7e+213], N[(z * (-y)), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-62}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+96}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+213}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -8.4999999999999995e-62 or 2.7000000000000001e213 < z Initial program 96.9%
Taylor expanded in y around 0 57.0%
if -8.4999999999999995e-62 < z < 1.80000000000000007e96Initial program 99.3%
Taylor expanded in x around inf 66.3%
if 1.80000000000000007e96 < z < 2.7000000000000001e213Initial program 89.5%
Taylor expanded in x around 0 95.2%
distribute-lft-out--95.2%
*-rgt-identity95.2%
Simplified95.2%
Taylor expanded in y around inf 80.4%
associate-*r*80.4%
neg-mul-180.4%
*-commutative80.4%
Simplified80.4%
Final simplification63.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1150000000000.0) (not (<= x 6e-13))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1150000000000.0) || !(x <= 6e-13)) {
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 ((x <= (-1150000000000.0d0)) .or. (.not. (x <= 6d-13))) 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 ((x <= -1150000000000.0) || !(x <= 6e-13)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1150000000000.0) or not (x <= 6e-13): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1150000000000.0) || !(x <= 6e-13)) 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 ((x <= -1150000000000.0) || ~((x <= 6e-13))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1150000000000.0], N[Not[LessEqual[x, 6e-13]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1150000000000 \lor \neg \left(x \leq 6 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if x < -1.15e12 or 5.99999999999999968e-13 < x Initial program 95.0%
Taylor expanded in y around inf 83.2%
+-commutative83.2%
mul-1-neg83.2%
unsub-neg83.2%
Simplified83.2%
if -1.15e12 < x < 5.99999999999999968e-13Initial program 100.0%
Taylor expanded in x around 0 86.3%
distribute-lft-out--86.3%
*-rgt-identity86.3%
Simplified86.3%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (<= x -4.5e+16) (* y x) (if (<= x 1.15e-12) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+16) {
tmp = y * x;
} else if (x <= 1.15e-12) {
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 (x <= (-4.5d+16)) then
tmp = y * x
else if (x <= 1.15d-12) 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 (x <= -4.5e+16) {
tmp = y * x;
} else if (x <= 1.15e-12) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e+16: tmp = y * x elif x <= 1.15e-12: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e+16) tmp = Float64(y * x); elseif (x <= 1.15e-12) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.5e+16) tmp = y * x; elseif (x <= 1.15e-12) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e+16], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.15e-12], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+16}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-12}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.5e16 or 1.14999999999999995e-12 < x Initial program 95.0%
Taylor expanded in x around inf 72.6%
if -4.5e16 < x < 1.14999999999999995e-12Initial program 100.0%
Taylor expanded in y around 0 51.5%
Final simplification61.5%
(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.7%
Taylor expanded in y around 0 36.6%
Final simplification36.6%
(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 2023257
(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))))