
(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
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 -2e+120)
(* (* x z) (- y))
(if (<= t_0 2e+100) (* x t_0) (* (* (- y) x) 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 <= -2e+120) {
tmp = (x * z) * -y;
} else if (t_0 <= 2e+100) {
tmp = x * t_0;
} else {
tmp = (-y * x) * 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 <= (-2d+120)) then
tmp = (x * z) * -y
else if (t_0 <= 2d+100) then
tmp = x * t_0
else
tmp = (-y * x) * 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 <= -2e+120) {
tmp = (x * z) * -y;
} else if (t_0 <= 2e+100) {
tmp = x * t_0;
} else {
tmp = (-y * x) * 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 <= -2e+120: tmp = (x * z) * -y elif t_0 <= 2e+100: tmp = x * t_0 else: tmp = (-y * x) * 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 <= -2e+120) tmp = Float64(Float64(x * z) * Float64(-y)); elseif (t_0 <= 2e+100) tmp = Float64(x * t_0); else tmp = Float64(Float64(Float64(-y) * x) * 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 <= -2e+120)
tmp = (x * z) * -y;
elseif (t_0 <= 2e+100)
tmp = x * t_0;
else
tmp = (-y * x) * 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, -2e+120], N[(N[(x * z), $MachinePrecision] * (-y)), $MachinePrecision], If[LessEqual[t$95$0, 2e+100], N[(x * t$95$0), $MachinePrecision], N[(N[((-y) * x), $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 -2 \cdot 10^{+120}:\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(-y\right)\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+100}:\\
\;\;\;\;x \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-y\right) \cdot x\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e120Initial program 88.5%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6437.1
Applied rewrites37.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6437.1
Applied rewrites37.1%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6499.8
Applied rewrites99.8%
Applied rewrites96.1%
if -2e120 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2.00000000000000003e100Initial program 99.9%
if 2.00000000000000003e100 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 84.6%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6440.7
Applied rewrites40.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6440.7
Applied rewrites40.7%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6499.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 -2e+20) (not (<= t_0 20000.0)))
(* (* (- y) x) 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 <= -2e+20) || !(t_0 <= 20000.0)) {
tmp = (-y * x) * 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 <= (-2d+20)) .or. (.not. (t_0 <= 20000.0d0))) then
tmp = (-y * x) * 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 <= -2e+20) || !(t_0 <= 20000.0)) {
tmp = (-y * x) * 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 <= -2e+20) or not (t_0 <= 20000.0): tmp = (-y * x) * 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 <= -2e+20) || !(t_0 <= 20000.0)) tmp = Float64(Float64(Float64(-y) * x) * 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 <= -2e+20) || ~((t_0 <= 20000.0)))
tmp = (-y * x) * 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, -2e+20], N[Not[LessEqual[t$95$0, 20000.0]], $MachinePrecision]], N[(N[((-y) * x), $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 -2 \cdot 10^{+20} \lor \neg \left(t\_0 \leq 20000\right):\\
\;\;\;\;\left(\left(-y\right) \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e20 or 2e4 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 90.0%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6452.7
Applied rewrites52.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6452.7
Applied rewrites52.7%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6494.7
Applied rewrites94.7%
if -2e20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2e4Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.0%
Final simplification96.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* y z) -10000.0) (not (<= (* y z) 2e-7))) (* (* x z) (- y)) (* x 1.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -10000.0) || !((y * z) <= 2e-7)) {
tmp = (x * z) * -y;
} 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) :: tmp
if (((y * z) <= (-10000.0d0)) .or. (.not. ((y * z) <= 2d-7))) then
tmp = (x * z) * -y
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 tmp;
if (((y * z) <= -10000.0) || !((y * z) <= 2e-7)) {
tmp = (x * z) * -y;
} else {
tmp = x * 1.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -10000.0) or not ((y * z) <= 2e-7): tmp = (x * z) * -y else: tmp = x * 1.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -10000.0) || !(Float64(y * z) <= 2e-7)) tmp = Float64(Float64(x * z) * Float64(-y)); 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)
tmp = 0.0;
if (((y * z) <= -10000.0) || ~(((y * z) <= 2e-7)))
tmp = (x * z) * -y;
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_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -10000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e-7]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * (-y)), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -10000 \lor \neg \left(y \cdot z \leq 2 \cdot 10^{-7}\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (*.f64 y z) < -1e4 or 1.9999999999999999e-7 < (*.f64 y z) Initial program 90.1%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6453.1
Applied rewrites53.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6453.1
Applied rewrites53.1%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6494.3
Applied rewrites94.3%
Applied rewrites91.0%
if -1e4 < (*.f64 y z) < 1.9999999999999999e-7Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.7%
Final simplification94.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 1.5e-23) (fma (* x (- y)) z x) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 1.5e-23) {
tmp = fma((x * -y), z, x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 1.5e-23) tmp = fma(Float64(x * Float64(-y)), z, x); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); 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[x, 1.5e-23], N[(N[(x * (-y)), $MachinePrecision] * z + x), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 1.50000000000000001e-23Initial program 93.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6494.9
Applied rewrites94.9%
if 1.50000000000000001e-23 < x Initial program 99.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 95.1%
Taylor expanded in y around 0
Applied rewrites51.4%
herbie shell --seed 2024338
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))