
(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.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
associate-+r+98.0%
+-commutative98.0%
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 (+ (* z (- 1.0 y)) (* y x)))) (if (<= t_0 1e+303) 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 <= 1e+303) {
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 <= 1d+303) 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 <= 1e+303) {
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 <= 1e+303: 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 <= 1e+303) 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 <= 1e+303) 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, 1e+303], 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 10^{+303}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) < 1e303Initial program 100.0%
if 1e303 < (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) Initial program 81.5%
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 (* z (- y))))
(if (<= y -2.25e+220)
t_0
(if (<= y -0.18)
(* y x)
(if (<= y 1.55e-40)
z
(if (<= y 2.65e+209) (* y x) (if (<= y 5e+235) t_0 (* y x))))))))
double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -2.25e+220) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = y * x;
} else if (y <= 1.55e-40) {
tmp = z;
} else if (y <= 2.65e+209) {
tmp = y * x;
} else if (y <= 5e+235) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * -y
if (y <= (-2.25d+220)) then
tmp = t_0
else if (y <= (-0.18d0)) then
tmp = y * x
else if (y <= 1.55d-40) then
tmp = z
else if (y <= 2.65d+209) then
tmp = y * x
else if (y <= 5d+235) then
tmp = t_0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -2.25e+220) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = y * x;
} else if (y <= 1.55e-40) {
tmp = z;
} else if (y <= 2.65e+209) {
tmp = y * x;
} else if (y <= 5e+235) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = z * -y tmp = 0 if y <= -2.25e+220: tmp = t_0 elif y <= -0.18: tmp = y * x elif y <= 1.55e-40: tmp = z elif y <= 2.65e+209: tmp = y * x elif y <= 5e+235: tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-y)) tmp = 0.0 if (y <= -2.25e+220) tmp = t_0; elseif (y <= -0.18) tmp = Float64(y * x); elseif (y <= 1.55e-40) tmp = z; elseif (y <= 2.65e+209) tmp = Float64(y * x); elseif (y <= 5e+235) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -y; tmp = 0.0; if (y <= -2.25e+220) tmp = t_0; elseif (y <= -0.18) tmp = y * x; elseif (y <= 1.55e-40) tmp = z; elseif (y <= 2.65e+209) tmp = y * x; elseif (y <= 5e+235) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -2.25e+220], t$95$0, If[LessEqual[y, -0.18], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.55e-40], z, If[LessEqual[y, 2.65e+209], N[(y * x), $MachinePrecision], If[LessEqual[y, 5e+235], t$95$0, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -2.25 \cdot 10^{+220}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.18:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-40}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+209}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+235}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.25000000000000005e220 or 2.64999999999999997e209 < y < 5.00000000000000027e235Initial program 96.7%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 71.5%
associate-*r*71.5%
neg-mul-171.5%
Simplified71.5%
if -2.25000000000000005e220 < y < -0.17999999999999999 or 1.55000000000000005e-40 < y < 2.64999999999999997e209 or 5.00000000000000027e235 < y Initial program 95.9%
Taylor expanded in x around inf 66.4%
if -0.17999999999999999 < y < 1.55000000000000005e-40Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-28) (not (<= y 4.5e-40))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-28) || !(y <= 4.5e-40)) {
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-28)) .or. (.not. (y <= 4.5d-40))) 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-28) || !(y <= 4.5e-40)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-28) or not (y <= 4.5e-40): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-28) || !(y <= 4.5e-40)) 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-28) || ~((y <= 4.5e-40))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-28], N[Not[LessEqual[y, 4.5e-40]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-28} \lor \neg \left(y \leq 4.5 \cdot 10^{-40}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.09999999999999998e-28 or 4.5000000000000001e-40 < y Initial program 96.2%
Taylor expanded in y around inf 92.8%
+-commutative92.8%
mul-1-neg92.8%
unsub-neg92.8%
Simplified92.8%
if -1.09999999999999998e-28 < y < 4.5000000000000001e-40Initial program 100.0%
Taylor expanded in y around 0 79.4%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.96) (not (<= y 1.7e-40))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.96) || !(y <= 1.7e-40)) {
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 <= (-1.96d0)) .or. (.not. (y <= 1.7d-40))) 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 <= -1.96) || !(y <= 1.7e-40)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.96) or not (y <= 1.7e-40): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.96) || !(y <= 1.7e-40)) 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 <= -1.96) || ~((y <= 1.7e-40))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.96], N[Not[LessEqual[y, 1.7e-40]], $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 -1.96 \lor \neg \left(y \leq 1.7 \cdot 10^{-40}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if y < -1.96 or 1.69999999999999992e-40 < y Initial program 96.1%
Taylor expanded in y around inf 94.6%
+-commutative94.6%
mul-1-neg94.6%
unsub-neg94.6%
Simplified94.6%
if -1.96 < y < 1.69999999999999992e-40Initial program 100.0%
Taylor expanded in x around 0 79.2%
distribute-lft-out--79.2%
*-rgt-identity79.2%
Simplified79.2%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= y -0.18) (* y x) (if (<= y 1.25e-40) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.18) {
tmp = y * x;
} else if (y <= 1.25e-40) {
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 <= (-0.18d0)) then
tmp = y * x
else if (y <= 1.25d-40) 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 <= -0.18) {
tmp = y * x;
} else if (y <= 1.25e-40) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.18: tmp = y * x elif y <= 1.25e-40: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.18) tmp = Float64(y * x); elseif (y <= 1.25e-40) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.18) tmp = y * x; elseif (y <= 1.25e-40) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.18], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.25e-40], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.18:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-40}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -0.17999999999999999 or 1.24999999999999991e-40 < y Initial program 96.1%
Taylor expanded in x around inf 59.0%
if -0.17999999999999999 < y < 1.24999999999999991e-40Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification68.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 98.0%
Taylor expanded in y around 0 41.6%
Final simplification41.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 2023268
(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))))