
(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 (fma (- x z) y z))
double code(double x, double y, double z) {
return fma((x - z), y, z);
}
function code(x, y, z) return fma(Float64(x - z), y, z) end
code[x_, y_, z_] := N[(N[(x - z), $MachinePrecision] * y + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - z, y, z\right)
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
distribute-rgt-out--N/A
unsub-negN/A
mul-1-negN/A
*-lft-identityN/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= y -9.2e+210) (* y x) (if (or (<= y -3.25) (not (<= y 1.0))) (* (- z) y) (* 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.2e+210) {
tmp = y * x;
} else if ((y <= -3.25) || !(y <= 1.0)) {
tmp = -z * y;
} else {
tmp = 1.0 * 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 <= (-9.2d+210)) then
tmp = y * x
else if ((y <= (-3.25d0)) .or. (.not. (y <= 1.0d0))) then
tmp = -z * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.2e+210) {
tmp = y * x;
} else if ((y <= -3.25) || !(y <= 1.0)) {
tmp = -z * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.2e+210: tmp = y * x elif (y <= -3.25) or not (y <= 1.0): tmp = -z * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.2e+210) tmp = Float64(y * x); elseif ((y <= -3.25) || !(y <= 1.0)) tmp = Float64(Float64(-z) * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.2e+210) tmp = y * x; elseif ((y <= -3.25) || ~((y <= 1.0))) tmp = -z * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.2e+210], N[(y * x), $MachinePrecision], If[Or[LessEqual[y, -3.25], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[((-z) * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+210}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.25 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if y < -9.1999999999999995e210Initial program 88.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6440.4
Applied rewrites40.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6467.4
Applied rewrites67.4%
if -9.1999999999999995e210 < y < -3.25 or 1 < y Initial program 98.3%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.3
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites61.8%
if -3.25 < y < 1Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.0
Applied rewrites76.0%
Taylor expanded in y around 0
Applied rewrites74.8%
Final simplification68.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000142) (not (<= y 4800000.0))) (* (- x z) y) (* (- 1.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000142) || !(y <= 4800000.0)) {
tmp = (x - z) * y;
} else {
tmp = (1.0 - 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 <= (-0.000142d0)) .or. (.not. (y <= 4800000.0d0))) then
tmp = (x - z) * y
else
tmp = (1.0d0 - y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000142) || !(y <= 4800000.0)) {
tmp = (x - z) * y;
} else {
tmp = (1.0 - y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000142) or not (y <= 4800000.0): tmp = (x - z) * y else: tmp = (1.0 - y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000142) || !(y <= 4800000.0)) tmp = Float64(Float64(x - z) * y); else tmp = Float64(Float64(1.0 - y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.000142) || ~((y <= 4800000.0))) tmp = (x - z) * y; else tmp = (1.0 - y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000142], N[Not[LessEqual[y, 4800000.0]], $MachinePrecision]], N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000142 \lor \neg \left(y \leq 4800000\right):\\
\;\;\;\;\left(x - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\end{array}
\end{array}
if y < -1.42000000000000009e-4 or 4.8e6 < y Initial program 97.1%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.7
Applied rewrites99.7%
if -1.42000000000000009e-4 < y < 4.8e6Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.9
Applied rewrites76.9%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e-160) (not (<= z 7.5e-109))) (* (- 1.0 y) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-160) || !(z <= 7.5e-109)) {
tmp = (1.0 - y) * 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 ((z <= (-3.8d-160)) .or. (.not. (z <= 7.5d-109))) then
tmp = (1.0d0 - y) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-160) || !(z <= 7.5e-109)) {
tmp = (1.0 - y) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e-160) or not (z <= 7.5e-109): tmp = (1.0 - y) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e-160) || !(z <= 7.5e-109)) tmp = Float64(Float64(1.0 - y) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e-160) || ~((z <= 7.5e-109))) tmp = (1.0 - y) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e-160], N[Not[LessEqual[z, 7.5e-109]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-160} \lor \neg \left(z \leq 7.5 \cdot 10^{-109}\right):\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -3.7999999999999998e-160 or 7.49999999999999982e-109 < z Initial program 97.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.2
Applied rewrites84.2%
if -3.7999999999999998e-160 < z < 7.49999999999999982e-109Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6427.4
Applied rewrites27.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6475.1
Applied rewrites75.1%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e-5) (not (<= y 1.8e-19))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-5) || !(y <= 1.8e-19)) {
tmp = y * x;
} else {
tmp = 1.0 * 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-5)) .or. (.not. (y <= 1.8d-19))) then
tmp = y * x
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-5) || !(y <= 1.8e-19)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e-5) or not (y <= 1.8e-19): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-5) || !(y <= 1.8e-19)) tmp = Float64(y * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.3e-5) || ~((y <= 1.8e-19))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e-5], N[Not[LessEqual[y, 1.8e-19]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-5} \lor \neg \left(y \leq 1.8 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if y < -2.3e-5 or 1.8000000000000001e-19 < y Initial program 97.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6458.8
Applied rewrites58.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6445.8
Applied rewrites45.8%
if -2.3e-5 < y < 1.8000000000000001e-19Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in y around 0
Applied rewrites77.0%
Final simplification59.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 98.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6467.1
Applied rewrites67.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6436.4
Applied rewrites36.4%
(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 2024318
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))