
(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 8 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%
+-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
*-lft-identity98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
neg-mul-198.0%
associate-*r*98.0%
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 1e+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 <= 1e+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 <= 1d+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 <= 1e+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 <= 1e+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 <= 1e+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 <= 1e+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, 1e+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 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))) < 1.0000000000000001e302Initial program 100.0%
if 1.0000000000000001e302 < (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) Initial program 82.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 (- z))))
(if (<= y -5.1e+54)
t_0
(if (<= y -1.4e-14)
(* y x)
(if (<= y 2.1e-118)
z
(if (<= y 2.2e-67)
(* y x)
(if (<= y 0.215) z (if (<= y 4.8e+42) (* y x) t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -5.1e+54) {
tmp = t_0;
} else if (y <= -1.4e-14) {
tmp = y * x;
} else if (y <= 2.1e-118) {
tmp = z;
} else if (y <= 2.2e-67) {
tmp = y * x;
} else if (y <= 0.215) {
tmp = z;
} else if (y <= 4.8e+42) {
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 <= (-5.1d+54)) then
tmp = t_0
else if (y <= (-1.4d-14)) then
tmp = y * x
else if (y <= 2.1d-118) then
tmp = z
else if (y <= 2.2d-67) then
tmp = y * x
else if (y <= 0.215d0) then
tmp = z
else if (y <= 4.8d+42) 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 <= -5.1e+54) {
tmp = t_0;
} else if (y <= -1.4e-14) {
tmp = y * x;
} else if (y <= 2.1e-118) {
tmp = z;
} else if (y <= 2.2e-67) {
tmp = y * x;
} else if (y <= 0.215) {
tmp = z;
} else if (y <= 4.8e+42) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -5.1e+54: tmp = t_0 elif y <= -1.4e-14: tmp = y * x elif y <= 2.1e-118: tmp = z elif y <= 2.2e-67: tmp = y * x elif y <= 0.215: tmp = z elif y <= 4.8e+42: 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 <= -5.1e+54) tmp = t_0; elseif (y <= -1.4e-14) tmp = Float64(y * x); elseif (y <= 2.1e-118) tmp = z; elseif (y <= 2.2e-67) tmp = Float64(y * x); elseif (y <= 0.215) tmp = z; elseif (y <= 4.8e+42) 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 <= -5.1e+54) tmp = t_0; elseif (y <= -1.4e-14) tmp = y * x; elseif (y <= 2.1e-118) tmp = z; elseif (y <= 2.2e-67) tmp = y * x; elseif (y <= 0.215) tmp = z; elseif (y <= 4.8e+42) 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, -5.1e+54], t$95$0, If[LessEqual[y, -1.4e-14], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.1e-118], z, If[LessEqual[y, 2.2e-67], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.215], z, If[LessEqual[y, 4.8e+42], N[(y * x), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -5.1 \cdot 10^{+54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-14}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-118}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-67}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.215:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+42}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -5.10000000000000009e54 or 4.7999999999999997e42 < y Initial program 95.0%
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 69.9%
mul-1-neg69.9%
distribute-rgt-neg-out69.9%
Simplified69.9%
if -5.10000000000000009e54 < y < -1.4e-14 or 2.1e-118 < y < 2.2000000000000001e-67 or 0.214999999999999997 < y < 4.7999999999999997e42Initial program 100.0%
Taylor expanded in x around inf 68.3%
if -1.4e-14 < y < 2.1e-118 or 2.2000000000000001e-67 < y < 0.214999999999999997Initial program 100.0%
Taylor expanded in y around 0 67.4%
Final simplification68.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -4.2e-15)
t_0
(if (<= y 1.05e-117)
z
(if (<= y 4.3e-67) (* y x) (if (<= y 0.215) z t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -4.2e-15) {
tmp = t_0;
} else if (y <= 1.05e-117) {
tmp = z;
} else if (y <= 4.3e-67) {
tmp = y * x;
} else if (y <= 0.215) {
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 <= (-4.2d-15)) then
tmp = t_0
else if (y <= 1.05d-117) then
tmp = z
else if (y <= 4.3d-67) then
tmp = y * x
else if (y <= 0.215d0) 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 <= -4.2e-15) {
tmp = t_0;
} else if (y <= 1.05e-117) {
tmp = z;
} else if (y <= 4.3e-67) {
tmp = y * x;
} else if (y <= 0.215) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -4.2e-15: tmp = t_0 elif y <= 1.05e-117: tmp = z elif y <= 4.3e-67: tmp = y * x elif y <= 0.215: 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 <= -4.2e-15) tmp = t_0; elseif (y <= 1.05e-117) tmp = z; elseif (y <= 4.3e-67) tmp = Float64(y * x); elseif (y <= 0.215) 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 <= -4.2e-15) tmp = t_0; elseif (y <= 1.05e-117) tmp = z; elseif (y <= 4.3e-67) tmp = y * x; elseif (y <= 0.215) 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, -4.2e-15], t$95$0, If[LessEqual[y, 1.05e-117], z, If[LessEqual[y, 4.3e-67], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.215], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -4.2 \cdot 10^{-15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-117}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-67}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.215:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.19999999999999962e-15 or 0.214999999999999997 < y Initial program 95.9%
Taylor expanded in y around inf 98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
Simplified98.9%
if -4.19999999999999962e-15 < y < 1.05e-117 or 4.30000000000000027e-67 < y < 0.214999999999999997Initial program 100.0%
Taylor expanded in y around 0 67.4%
if 1.05e-117 < y < 4.30000000000000027e-67Initial program 100.0%
Taylor expanded in x around inf 61.2%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e+81) (not (<= x 9e-72))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+81) || !(x <= 9e-72)) {
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 ((x <= (-8d+81)) .or. (.not. (x <= 9d-72))) 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 ((x <= -8e+81) || !(x <= 9e-72)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e+81) or not (x <= 9e-72): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e+81) || !(x <= 9e-72)) 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 ((x <= -8e+81) || ~((x <= 9e-72))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e+81], N[Not[LessEqual[x, 9e-72]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+81} \lor \neg \left(x \leq 9 \cdot 10^{-72}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -7.99999999999999937e81 or 9e-72 < x Initial program 96.1%
Taylor expanded in y around inf 79.6%
+-commutative79.6%
mul-1-neg79.6%
unsub-neg79.6%
Simplified79.6%
if -7.99999999999999937e81 < x < 9e-72Initial program 100.0%
Taylor expanded in x around 0 85.2%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e+81) (not (<= x 9e-72))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+81) || !(x <= 9e-72)) {
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 <= (-9.5d+81)) .or. (.not. (x <= 9d-72))) 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 <= -9.5e+81) || !(x <= 9e-72)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e+81) or not (x <= 9e-72): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e+81) || !(x <= 9e-72)) 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 <= -9.5e+81) || ~((x <= 9e-72))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+81], N[Not[LessEqual[x, 9e-72]], $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 -9.5 \cdot 10^{+81} \lor \neg \left(x \leq 9 \cdot 10^{-72}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if x < -9.50000000000000083e81 or 9e-72 < x Initial program 96.1%
Taylor expanded in y around inf 79.6%
+-commutative79.6%
mul-1-neg79.6%
unsub-neg79.6%
Simplified79.6%
if -9.50000000000000083e81 < x < 9e-72Initial program 100.0%
Taylor expanded in x around 0 85.2%
distribute-lft-out--85.2%
*-rgt-identity85.2%
Simplified85.2%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e+82) (* y x) (if (<= x 7.8e-72) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+82) {
tmp = y * x;
} else if (x <= 7.8e-72) {
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 <= (-2.4d+82)) then
tmp = y * x
else if (x <= 7.8d-72) 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 <= -2.4e+82) {
tmp = y * x;
} else if (x <= 7.8e-72) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e+82: tmp = y * x elif x <= 7.8e-72: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e+82) tmp = Float64(y * x); elseif (x <= 7.8e-72) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e+82) tmp = y * x; elseif (x <= 7.8e-72) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e+82], N[(y * x), $MachinePrecision], If[LessEqual[x, 7.8e-72], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+82}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-72}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.39999999999999998e82 or 7.8e-72 < x Initial program 96.1%
Taylor expanded in x around inf 66.5%
if -2.39999999999999998e82 < x < 7.8e-72Initial program 100.0%
Taylor expanded in y around 0 48.1%
Final simplification57.3%
(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 34.8%
Final simplification34.8%
(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 2023200
(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))))