
(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 6 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 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (y * (x - 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 + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 99.2%
distribute-lft-out--99.2%
*-rgt-identity99.2%
cancel-sign-sub-inv99.2%
+-commutative99.2%
associate-+r+99.2%
+-commutative99.2%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -1.0)
t_0
(if (<= y 1.6e-28)
z
(if (<= y 4e+27) (* y x) (if (<= y 1.52e+37) t_0 (* y x)))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.6e-28) {
tmp = z;
} else if (y <= 4e+27) {
tmp = y * x;
} else if (y <= 1.52e+37) {
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 = y * -z
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.6d-28) then
tmp = z
else if (y <= 4d+27) then
tmp = y * x
else if (y <= 1.52d+37) 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 = y * -z;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.6e-28) {
tmp = z;
} else if (y <= 4e+27) {
tmp = y * x;
} else if (y <= 1.52e+37) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.6e-28: tmp = z elif y <= 4e+27: tmp = y * x elif y <= 1.52e+37: tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.6e-28) tmp = z; elseif (y <= 4e+27) tmp = Float64(y * x); elseif (y <= 1.52e+37) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 1.6e-28) tmp = z; elseif (y <= 4e+27) tmp = y * x; elseif (y <= 1.52e+37) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.6e-28], z, If[LessEqual[y, 4e+27], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.52e+37], t$95$0, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-28}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+27}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.52 \cdot 10^{+37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 4.0000000000000001e27 < y < 1.5200000000000001e37Initial program 96.6%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 65.0%
mul-1-neg65.0%
distribute-rgt-neg-out65.0%
Simplified65.0%
if -1 < y < 1.59999999999999991e-28Initial program 100.0%
Taylor expanded in y around 0 78.1%
if 1.59999999999999991e-28 < y < 4.0000000000000001e27 or 1.5200000000000001e37 < y Initial program 100.0%
Taylor expanded in x around inf 62.2%
*-commutative62.2%
Simplified62.2%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e-8) (not (<= y 1.65e-28))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-8) || !(y <= 1.65e-28)) {
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 <= (-2.3d-8)) .or. (.not. (y <= 1.65d-28))) 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 <= -2.3e-8) || !(y <= 1.65e-28)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e-8) or not (y <= 1.65e-28): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-8) || !(y <= 1.65e-28)) 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 <= -2.3e-8) || ~((y <= 1.65e-28))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e-8], N[Not[LessEqual[y, 1.65e-28]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-8} \lor \neg \left(y \leq 1.65 \cdot 10^{-28}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.3000000000000001e-8 or 1.6500000000000001e-28 < y Initial program 98.4%
Taylor expanded in y around inf 96.4%
mul-1-neg96.4%
sub-neg96.4%
Simplified96.4%
if -2.3000000000000001e-8 < y < 1.6500000000000001e-28Initial program 100.0%
Taylor expanded in y around 0 78.1%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 8e-7))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 8e-7)) {
tmp = y * (x - z);
} else {
tmp = z + (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.0d0)) .or. (.not. (y <= 8d-7))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 8e-7)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 8e-7): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 8e-7)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 8e-7))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 8e-7]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 8 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 7.9999999999999996e-7 < y Initial program 98.3%
Taylor expanded in y around inf 99.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
if -1 < y < 7.9999999999999996e-7Initial program 100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.8%
*-commutative98.8%
Simplified98.8%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= y -360000000000.0) (* y x) (if (<= y 1.7e-29) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -360000000000.0) {
tmp = y * x;
} else if (y <= 1.7e-29) {
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 <= (-360000000000.0d0)) then
tmp = y * x
else if (y <= 1.7d-29) 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 <= -360000000000.0) {
tmp = y * x;
} else if (y <= 1.7e-29) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -360000000000.0: tmp = y * x elif y <= 1.7e-29: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -360000000000.0) tmp = Float64(y * x); elseif (y <= 1.7e-29) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -360000000000.0) tmp = y * x; elseif (y <= 1.7e-29) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -360000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.7e-29], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -360000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-29}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.6e11 or 1.69999999999999986e-29 < y Initial program 98.4%
Taylor expanded in x around inf 53.5%
*-commutative53.5%
Simplified53.5%
if -3.6e11 < y < 1.69999999999999986e-29Initial program 100.0%
Taylor expanded in y around 0 77.6%
Final simplification65.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 99.2%
Taylor expanded in y around 0 41.3%
Final simplification41.3%
(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 2023287
(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))))