
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (- 1.0 (* y z)) 5e+223) (fma (* (- y) z) x x) (* (* (- x) z) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((1.0 - (y * z)) <= 5e+223) {
tmp = fma((-y * z), x, x);
} else {
tmp = (-x * z) * y;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(1.0 - Float64(y * z)) <= 5e+223) tmp = fma(Float64(Float64(-y) * z), x, x); else tmp = Float64(Float64(Float64(-x) * z) * y); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], 5e+223], N[(N[((-y) * z), $MachinePrecision] * x + x), $MachinePrecision], N[(N[((-x) * z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - y \cdot z \leq 5 \cdot 10^{+223}:\\
\;\;\;\;\mathsf{fma}\left(\left(-y\right) \cdot z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot z\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 4.99999999999999985e223Initial program 98.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6498.3
Applied rewrites98.3%
if 4.99999999999999985e223 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 79.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6479.5
Applied rewrites79.5%
Applied rewrites43.9%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
distribute-neg-fracN/A
mul-1-negN/A
remove-double-negN/A
lower-neg.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity99.9
Applied rewrites99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (or (<= t_0 -2000000.0) (not (<= t_0 2.0)))
(* (* (- x) y) z)
(* x 1.0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -2000000.0) || !(t_0 <= 2.0)) {
tmp = (-x * y) * z;
} else {
tmp = x * 1.0;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 = 1.0d0 - (y * z)
if ((t_0 <= (-2000000.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (-x * y) * z
else
tmp = x * 1.0d0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -2000000.0) || !(t_0 <= 2.0)) {
tmp = (-x * y) * z;
} else {
tmp = x * 1.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -2000000.0) or not (t_0 <= 2.0): tmp = (-x * y) * z else: tmp = x * 1.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -2000000.0) || !(t_0 <= 2.0)) tmp = Float64(Float64(Float64(-x) * y) * z); else tmp = Float64(x * 1.0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if ((t_0 <= -2000000.0) || ~((t_0 <= 2.0)))
tmp = (-x * y) * z;
else
tmp = x * 1.0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2000000.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2000000 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e6 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.6%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6492.6
Applied rewrites92.6%
Applied rewrites22.1%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
distribute-neg-fracN/A
mul-1-negN/A
remove-double-negN/A
lower-neg.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity90.1
Applied rewrites90.1%
Applied rewrites90.0%
if -2e6 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.8%
Final simplification94.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 -2000000.0)
(* (* (- x) z) y)
(if (<= t_0 2.0) (* x 1.0) (* (* (- x) y) z)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -2000000.0) {
tmp = (-x * z) * y;
} else if (t_0 <= 2.0) {
tmp = x * 1.0;
} else {
tmp = (-x * y) * z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 = 1.0d0 - (y * z)
if (t_0 <= (-2000000.0d0)) then
tmp = (-x * z) * y
else if (t_0 <= 2.0d0) then
tmp = x * 1.0d0
else
tmp = (-x * y) * z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -2000000.0) {
tmp = (-x * z) * y;
} else if (t_0 <= 2.0) {
tmp = x * 1.0;
} else {
tmp = (-x * y) * z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if t_0 <= -2000000.0: tmp = (-x * z) * y elif t_0 <= 2.0: tmp = x * 1.0 else: tmp = (-x * y) * z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= -2000000.0) tmp = Float64(Float64(Float64(-x) * z) * y); elseif (t_0 <= 2.0) tmp = Float64(x * 1.0); else tmp = Float64(Float64(Float64(-x) * y) * z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if (t_0 <= -2000000.0)
tmp = (-x * z) * y;
elseif (t_0 <= 2.0)
tmp = x * 1.0;
else
tmp = (-x * y) * z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000.0], N[(N[((-x) * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x * 1.0), $MachinePrecision], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2000000:\\
\;\;\;\;\left(\left(-x\right) \cdot z\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e6Initial program 93.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6493.0
Applied rewrites93.0%
Applied rewrites0.5%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
distribute-neg-fracN/A
mul-1-negN/A
remove-double-negN/A
lower-neg.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity90.9
Applied rewrites90.9%
if -2e6 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.8%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6492.3
Applied rewrites92.3%
Applied rewrites41.7%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
distribute-neg-fracN/A
mul-1-negN/A
remove-double-negN/A
lower-neg.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity89.3
Applied rewrites89.3%
Applied rewrites91.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z)))) (if (<= t_0 5e+223) (* x t_0) (* (* (- x) z) y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= 5e+223) {
tmp = x * t_0;
} else {
tmp = (-x * z) * y;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 = 1.0d0 - (y * z)
if (t_0 <= 5d+223) then
tmp = x * t_0
else
tmp = (-x * z) * y
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= 5e+223) {
tmp = x * t_0;
} else {
tmp = (-x * z) * y;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if t_0 <= 5e+223: tmp = x * t_0 else: tmp = (-x * z) * y return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= 5e+223) tmp = Float64(x * t_0); else tmp = Float64(Float64(Float64(-x) * z) * y); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if (t_0 <= 5e+223)
tmp = x * t_0;
else
tmp = (-x * z) * y;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+223], N[(x * t$95$0), $MachinePrecision], N[(N[((-x) * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+223}:\\
\;\;\;\;x \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot z\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 4.99999999999999985e223Initial program 98.3%
if 4.99999999999999985e223 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 79.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6479.5
Applied rewrites79.5%
Applied rewrites43.9%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
distribute-neg-fracN/A
mul-1-negN/A
remove-double-negN/A
lower-neg.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity99.9
Applied rewrites99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x 1.0))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * 1.0;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * 1.0;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * 1.0
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * 1.0) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * 1.0;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot 1
\end{array}
Initial program 96.6%
Taylor expanded in y around 0
Applied rewrites55.0%
herbie shell --seed 2024340
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))