
(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.6%
+-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
*-lft-identity97.6%
associate-+l+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
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+291) 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+291) {
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+291) 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+291) {
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+291: 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+291) 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+291) 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+291], 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^{+291}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) < 5.0000000000000001e291Initial program 100.0%
if 5.0000000000000001e291 < (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) Initial program 82.9%
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 -1.6e-73)
t_0
(if (<= y -6e-210)
z
(if (<= y -2.5e-220) (* y x) (if (<= y 8e-16) z t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -1.6e-73) {
tmp = t_0;
} else if (y <= -6e-210) {
tmp = z;
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 8e-16) {
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 <= (-1.6d-73)) then
tmp = t_0
else if (y <= (-6d-210)) then
tmp = z
else if (y <= (-2.5d-220)) then
tmp = y * x
else if (y <= 8d-16) 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 <= -1.6e-73) {
tmp = t_0;
} else if (y <= -6e-210) {
tmp = z;
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 8e-16) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -1.6e-73: tmp = t_0 elif y <= -6e-210: tmp = z elif y <= -2.5e-220: tmp = y * x elif y <= 8e-16: 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 <= -1.6e-73) tmp = t_0; elseif (y <= -6e-210) tmp = z; elseif (y <= -2.5e-220) tmp = Float64(y * x); elseif (y <= 8e-16) 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 <= -1.6e-73) tmp = t_0; elseif (y <= -6e-210) tmp = z; elseif (y <= -2.5e-220) tmp = y * x; elseif (y <= 8e-16) 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, -1.6e-73], t$95$0, If[LessEqual[y, -6e-210], z, If[LessEqual[y, -2.5e-220], N[(y * x), $MachinePrecision], If[LessEqual[y, 8e-16], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -1.6 \cdot 10^{-73}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-210}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-220}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-16}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.59999999999999993e-73 or 7.9999999999999998e-16 < y Initial program 95.9%
Taylor expanded in y around inf 96.0%
+-commutative96.0%
mul-1-neg96.0%
unsub-neg96.0%
Simplified96.0%
if -1.59999999999999993e-73 < y < -6.0000000000000003e-210 or -2.5000000000000001e-220 < y < 7.9999999999999998e-16Initial program 100.0%
Taylor expanded in y around 0 80.1%
if -6.0000000000000003e-210 < y < -2.5000000000000001e-220Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification89.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))) (t_1 (* z (- 1.0 y))))
(if (<= y -6.5e-69)
t_0
(if (<= y -5.7e-210)
t_1
(if (<= y -2.5e-220) (* y x) (if (<= y 380000000.0) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double t_1 = z * (1.0 - y);
double tmp;
if (y <= -6.5e-69) {
tmp = t_0;
} else if (y <= -5.7e-210) {
tmp = t_1;
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 380000000.0) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = y * (x - z)
t_1 = z * (1.0d0 - y)
if (y <= (-6.5d-69)) then
tmp = t_0
else if (y <= (-5.7d-210)) then
tmp = t_1
else if (y <= (-2.5d-220)) then
tmp = y * x
else if (y <= 380000000.0d0) then
tmp = t_1
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 t_1 = z * (1.0 - y);
double tmp;
if (y <= -6.5e-69) {
tmp = t_0;
} else if (y <= -5.7e-210) {
tmp = t_1;
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 380000000.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) t_1 = z * (1.0 - y) tmp = 0 if y <= -6.5e-69: tmp = t_0 elif y <= -5.7e-210: tmp = t_1 elif y <= -2.5e-220: tmp = y * x elif y <= 380000000.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) t_1 = Float64(z * Float64(1.0 - y)) tmp = 0.0 if (y <= -6.5e-69) tmp = t_0; elseif (y <= -5.7e-210) tmp = t_1; elseif (y <= -2.5e-220) tmp = Float64(y * x); elseif (y <= 380000000.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); t_1 = z * (1.0 - y); tmp = 0.0; if (y <= -6.5e-69) tmp = t_0; elseif (y <= -5.7e-210) tmp = t_1; elseif (y <= -2.5e-220) tmp = y * x; elseif (y <= 380000000.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.5e-69], t$95$0, If[LessEqual[y, -5.7e-210], t$95$1, If[LessEqual[y, -2.5e-220], N[(y * x), $MachinePrecision], If[LessEqual[y, 380000000.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
t_1 := z \cdot \left(1 - y\right)\\
\mathbf{if}\;y \leq -6.5 \cdot 10^{-69}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5.7 \cdot 10^{-210}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-220}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 380000000:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -6.49999999999999951e-69 or 3.8e8 < y Initial program 95.7%
Taylor expanded in y around inf 97.3%
+-commutative97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
if -6.49999999999999951e-69 < y < -5.69999999999999971e-210 or -2.5000000000000001e-220 < y < 3.8e8Initial program 100.0%
Taylor expanded in x around 0 79.3%
if -5.69999999999999971e-210 < y < -2.5000000000000001e-220Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification89.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -1.85e-70)
t_0
(if (<= y -5.7e-210)
(* z (- 1.0 y))
(if (<= y -2.5e-220)
(* y x)
(if (<= y 380000000.0) (- z (* y z)) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -1.85e-70) {
tmp = t_0;
} else if (y <= -5.7e-210) {
tmp = z * (1.0 - y);
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 380000000.0) {
tmp = z - (y * 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 <= (-1.85d-70)) then
tmp = t_0
else if (y <= (-5.7d-210)) then
tmp = z * (1.0d0 - y)
else if (y <= (-2.5d-220)) then
tmp = y * x
else if (y <= 380000000.0d0) then
tmp = z - (y * 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 <= -1.85e-70) {
tmp = t_0;
} else if (y <= -5.7e-210) {
tmp = z * (1.0 - y);
} else if (y <= -2.5e-220) {
tmp = y * x;
} else if (y <= 380000000.0) {
tmp = z - (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -1.85e-70: tmp = t_0 elif y <= -5.7e-210: tmp = z * (1.0 - y) elif y <= -2.5e-220: tmp = y * x elif y <= 380000000.0: tmp = z - (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -1.85e-70) tmp = t_0; elseif (y <= -5.7e-210) tmp = Float64(z * Float64(1.0 - y)); elseif (y <= -2.5e-220) tmp = Float64(y * x); elseif (y <= 380000000.0) tmp = Float64(z - Float64(y * 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 <= -1.85e-70) tmp = t_0; elseif (y <= -5.7e-210) tmp = z * (1.0 - y); elseif (y <= -2.5e-220) tmp = y * x; elseif (y <= 380000000.0) tmp = z - (y * 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, -1.85e-70], t$95$0, If[LessEqual[y, -5.7e-210], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.5e-220], N[(y * x), $MachinePrecision], If[LessEqual[y, 380000000.0], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -1.85 \cdot 10^{-70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5.7 \cdot 10^{-210}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-220}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 380000000:\\
\;\;\;\;z - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.85e-70 or 3.8e8 < y Initial program 95.7%
Taylor expanded in y around inf 97.3%
+-commutative97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
if -1.85e-70 < y < -5.69999999999999971e-210Initial program 100.0%
Taylor expanded in x around 0 71.3%
if -5.69999999999999971e-210 < y < -2.5000000000000001e-220Initial program 100.0%
Taylor expanded in x around inf 100.0%
if -2.5000000000000001e-220 < y < 3.8e8Initial program 100.0%
Taylor expanded in x around 0 80.8%
distribute-lft-out--80.8%
*-rgt-identity80.8%
Simplified80.8%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.5e+45) z (if (<= z 2e-76) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+45) {
tmp = z;
} else if (z <= 2e-76) {
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 (z <= (-1.5d+45)) then
tmp = z
else if (z <= 2d-76) 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 (z <= -1.5e+45) {
tmp = z;
} else if (z <= 2e-76) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5e+45: tmp = z elif z <= 2e-76: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5e+45) tmp = z; elseif (z <= 2e-76) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.5e+45) tmp = z; elseif (z <= 2e-76) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5e+45], z, If[LessEqual[z, 2e-76], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+45}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.50000000000000005e45 or 1.99999999999999985e-76 < z Initial program 95.3%
Taylor expanded in y around 0 53.7%
if -1.50000000000000005e45 < z < 1.99999999999999985e-76Initial program 100.0%
Taylor expanded in x around inf 72.6%
Final simplification63.1%
(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 35.5%
Final simplification35.5%
(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 2023230
(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))))