
(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 (* (* (- x) y) z)))
(if (<= (* y z) -1e+202)
t_0
(if (<= (* y z) 2e+83) (* (- 1.0 (* y z)) x) t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -1e+202) {
tmp = t_0;
} else if ((y * z) <= 2e+83) {
tmp = (1.0 - (y * z)) * x;
} else {
tmp = t_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 = (-x * y) * z
if ((y * z) <= (-1d+202)) then
tmp = t_0
else if ((y * z) <= 2d+83) then
tmp = (1.0d0 - (y * z)) * x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -1e+202) {
tmp = t_0;
} else if ((y * z) <= 2e+83) {
tmp = (1.0 - (y * z)) * x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (-x * y) * z tmp = 0 if (y * z) <= -1e+202: tmp = t_0 elif (y * z) <= 2e+83: tmp = (1.0 - (y * z)) * x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(Float64(-x) * y) * z) tmp = 0.0 if (Float64(y * z) <= -1e+202) tmp = t_0; elseif (Float64(y * z) <= 2e+83) tmp = Float64(Float64(1.0 - Float64(y * z)) * x); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (-x * y) * z;
tmp = 0.0;
if ((y * z) <= -1e+202)
tmp = t_0;
elseif ((y * z) <= 2e+83)
tmp = (1.0 - (y * z)) * x;
else
tmp = t_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[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -1e+202], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e+83], N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+202}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+83}:\\
\;\;\;\;\left(1 - y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -9.999999999999999e201 or 2.00000000000000006e83 < (*.f64 y z) Initial program 85.1%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6498.7
Applied rewrites98.7%
lift-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
Applied rewrites99.2%
Taylor expanded in z around inf
associate-*r*N/A
associate-/r*N/A
metadata-evalN/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Taylor expanded in z around inf
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
if -9.999999999999999e201 < (*.f64 y z) < 2.00000000000000006e83Initial program 99.8%
Final simplification99.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* (- x) y) z)))
(if (<= (* y z) -1e+202)
t_0
(if (<= (* y z) -5000000000.0)
(* (* y (- z)) x)
(if (<= (* y z) 0.02) (* 1.0 x) t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -1e+202) {
tmp = t_0;
} else if ((y * z) <= -5000000000.0) {
tmp = (y * -z) * x;
} else if ((y * z) <= 0.02) {
tmp = 1.0 * x;
} else {
tmp = t_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 = (-x * y) * z
if ((y * z) <= (-1d+202)) then
tmp = t_0
else if ((y * z) <= (-5000000000.0d0)) then
tmp = (y * -z) * x
else if ((y * z) <= 0.02d0) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -1e+202) {
tmp = t_0;
} else if ((y * z) <= -5000000000.0) {
tmp = (y * -z) * x;
} else if ((y * z) <= 0.02) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (-x * y) * z tmp = 0 if (y * z) <= -1e+202: tmp = t_0 elif (y * z) <= -5000000000.0: tmp = (y * -z) * x elif (y * z) <= 0.02: tmp = 1.0 * x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(Float64(-x) * y) * z) tmp = 0.0 if (Float64(y * z) <= -1e+202) tmp = t_0; elseif (Float64(y * z) <= -5000000000.0) tmp = Float64(Float64(y * Float64(-z)) * x); elseif (Float64(y * z) <= 0.02) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (-x * y) * z;
tmp = 0.0;
if ((y * z) <= -1e+202)
tmp = t_0;
elseif ((y * z) <= -5000000000.0)
tmp = (y * -z) * x;
elseif ((y * z) <= 0.02)
tmp = 1.0 * x;
else
tmp = t_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[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -1e+202], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], -5000000000.0], N[(N[(y * (-z)), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.02], N[(1.0 * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+202}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq -5000000000:\\
\;\;\;\;\left(y \cdot \left(-z\right)\right) \cdot x\\
\mathbf{elif}\;y \cdot z \leq 0.02:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -9.999999999999999e201 or 0.0200000000000000004 < (*.f64 y z) Initial program 87.9%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6494.1
Applied rewrites94.1%
lift-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
Applied rewrites96.6%
Taylor expanded in z around inf
associate-*r*N/A
associate-/r*N/A
metadata-evalN/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6493.9
Applied rewrites93.9%
Taylor expanded in z around inf
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6495.1
Applied rewrites95.1%
if -9.999999999999999e201 < (*.f64 y z) < -5e9Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6497.9
Applied rewrites97.9%
if -5e9 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites96.0%
Final simplification95.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 (* (* (- x) y) z))) (if (<= (* y z) -5000000000.0) t_0 (if (<= (* y z) 0.02) (* 1.0 x) t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -5000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.02) {
tmp = 1.0 * x;
} else {
tmp = t_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 = (-x * y) * z
if ((y * z) <= (-5000000000.0d0)) then
tmp = t_0
else if ((y * z) <= 0.02d0) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -5000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.02) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (-x * y) * z tmp = 0 if (y * z) <= -5000000000.0: tmp = t_0 elif (y * z) <= 0.02: tmp = 1.0 * x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(Float64(-x) * y) * z) tmp = 0.0 if (Float64(y * z) <= -5000000000.0) tmp = t_0; elseif (Float64(y * z) <= 0.02) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (-x * y) * z;
tmp = 0.0;
if ((y * z) <= -5000000000.0)
tmp = t_0;
elseif ((y * z) <= 0.02)
tmp = 1.0 * x;
else
tmp = t_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[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -5000000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.02], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;y \cdot z \leq -5000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.02:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -5e9 or 0.0200000000000000004 < (*.f64 y z) Initial program 90.5%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6492.0
Applied rewrites92.0%
lift-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
Applied rewrites94.6%
Taylor expanded in z around inf
associate-*r*N/A
associate-/r*N/A
metadata-evalN/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6492.0
Applied rewrites92.0%
Taylor expanded in z around inf
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
if -5e9 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites96.0%
Final simplification94.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 3.9e-132) (fma (* (- z) x) y x) (* (- 1.0 (* y z)) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 3.9e-132) {
tmp = fma((-z * x), y, x);
} else {
tmp = (1.0 - (y * z)) * x;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 3.9e-132) tmp = fma(Float64(Float64(-z) * x), y, x); else tmp = Float64(Float64(1.0 - Float64(y * z)) * x); 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, 3.9e-132], N[(N[((-z) * x), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.9 \cdot 10^{-132}:\\
\;\;\;\;\mathsf{fma}\left(\left(-z\right) \cdot x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if x < 3.89999999999999982e-132Initial program 91.7%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6491.5
Applied rewrites91.5%
if 3.89999999999999982e-132 < x Initial program 99.9%
Final simplification94.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* 1.0 x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 1.0 * x;
}
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 = 1.0d0 * x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 1.0 * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 1.0 * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(1.0 * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 1.0 * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
1 \cdot x
\end{array}
Initial program 94.7%
Taylor expanded in z around 0
Applied rewrites44.8%
Final simplification44.8%
herbie shell --seed 2024268
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))