
(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.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 2e+299) 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 <= 2e+299) {
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 <= 2d+299) 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 <= 2e+299) {
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 <= 2e+299: 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 <= 2e+299) 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 <= 2e+299) 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, 2e+299], 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 2 \cdot 10^{+299}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) < 2.0000000000000001e299Initial program 100.0%
if 2.0000000000000001e299 < (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y))) Initial program 78.6%
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
(if (<= y -2e+114)
(* y x)
(if (<= y -5.5e+63)
(* y (- z))
(if (<= y -1.5e-6) (* y x) (if (<= y 7.6e-17) z (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e+114) {
tmp = y * x;
} else if (y <= -5.5e+63) {
tmp = y * -z;
} else if (y <= -1.5e-6) {
tmp = y * x;
} else if (y <= 7.6e-17) {
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 <= (-2d+114)) then
tmp = y * x
else if (y <= (-5.5d+63)) then
tmp = y * -z
else if (y <= (-1.5d-6)) then
tmp = y * x
else if (y <= 7.6d-17) 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 <= -2e+114) {
tmp = y * x;
} else if (y <= -5.5e+63) {
tmp = y * -z;
} else if (y <= -1.5e-6) {
tmp = y * x;
} else if (y <= 7.6e-17) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e+114: tmp = y * x elif y <= -5.5e+63: tmp = y * -z elif y <= -1.5e-6: tmp = y * x elif y <= 7.6e-17: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e+114) tmp = Float64(y * x); elseif (y <= -5.5e+63) tmp = Float64(y * Float64(-z)); elseif (y <= -1.5e-6) tmp = Float64(y * x); elseif (y <= 7.6e-17) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e+114) tmp = y * x; elseif (y <= -5.5e+63) tmp = y * -z; elseif (y <= -1.5e-6) tmp = y * x; elseif (y <= 7.6e-17) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e+114], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.5e+63], N[(y * (-z)), $MachinePrecision], If[LessEqual[y, -1.5e-6], N[(y * x), $MachinePrecision], If[LessEqual[y, 7.6e-17], z, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+114}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{+63}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-17}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2e114 or -5.50000000000000004e63 < y < -1.5e-6 or 7.6000000000000002e-17 < y Initial program 94.6%
Taylor expanded in x around inf 67.6%
if -2e114 < y < -5.50000000000000004e63Initial program 100.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 80.2%
mul-1-neg80.2%
distribute-rgt-neg-out80.2%
Simplified80.2%
if -1.5e-6 < y < 7.6000000000000002e-17Initial program 100.0%
Taylor expanded in y around 0 74.7%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-6) (not (<= y 9.8e-17))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-6) || !(y <= 9.8e-17)) {
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.5d-6)) .or. (.not. (y <= 9.8d-17))) 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.5e-6) || !(y <= 9.8e-17)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-6) or not (y <= 9.8e-17): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-6) || !(y <= 9.8e-17)) 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.5e-6) || ~((y <= 9.8e-17))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-6], N[Not[LessEqual[y, 9.8e-17]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-6} \lor \neg \left(y \leq 9.8 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.5e-6 or 9.80000000000000024e-17 < y Initial program 95.1%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
Simplified98.7%
if -1.5e-6 < y < 9.80000000000000024e-17Initial program 100.0%
Taylor expanded in y around 0 74.7%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-6) (not (<= y 9.5e-16))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-6) || !(y <= 9.5e-16)) {
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.8d-6)) .or. (.not. (y <= 9.5d-16))) 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.8e-6) || !(y <= 9.5e-16)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-6) or not (y <= 9.5e-16): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-6) || !(y <= 9.5e-16)) 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.8e-6) || ~((y <= 9.5e-16))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-6], N[Not[LessEqual[y, 9.5e-16]], $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.8 \cdot 10^{-6} \lor \neg \left(y \leq 9.5 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if y < -1.79999999999999992e-6 or 9.5000000000000005e-16 < y Initial program 95.1%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
Simplified98.7%
if -1.79999999999999992e-6 < y < 9.5000000000000005e-16Initial program 100.0%
Taylor expanded in x around 0 75.3%
distribute-lft-out--75.3%
*-rgt-identity75.3%
Simplified75.3%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e-6) (* y x) (if (<= y 6.6e-16) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-6) {
tmp = y * x;
} else if (y <= 6.6e-16) {
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 <= (-1.65d-6)) then
tmp = y * x
else if (y <= 6.6d-16) 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 <= -1.65e-6) {
tmp = y * x;
} else if (y <= 6.6e-16) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-6: tmp = y * x elif y <= 6.6e-16: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-6) tmp = Float64(y * x); elseif (y <= 6.6e-16) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e-6) tmp = y * x; elseif (y <= 6.6e-16) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-6], N[(y * x), $MachinePrecision], If[LessEqual[y, 6.6e-16], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{-16}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.65000000000000008e-6 or 6.59999999999999976e-16 < y Initial program 95.1%
Taylor expanded in x around inf 64.0%
if -1.65000000000000008e-6 < y < 6.59999999999999976e-16Initial program 100.0%
Taylor expanded in y around 0 74.7%
Final simplification69.6%
(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 40.6%
Final simplification40.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 2023238
(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))))