
(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}
(FPCore (x y z) :precision binary64 (- x (* (* y z) x)))
double code(double x, double y, double z) {
return x - ((y * z) * x);
}
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) * x)
end function
public static double code(double x, double y, double z) {
return x - ((y * z) * x);
}
def code(x, y, z): return x - ((y * z) * x)
function code(x, y, z) return Float64(x - Float64(Float64(y * z) * x)) end
function tmp = code(x, y, z) tmp = x - ((y * z) * x); end
code[x_, y_, z_] := N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(y \cdot z\right) \cdot x
\end{array}
Initial program 98.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
lower--.f64N/A
lower-*.f6498.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- z) y) x))) (if (<= t_0 -500000.0) t_1 (if (<= t_0 2.0) (* 1.0 x) t_1))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-z * y) * x;
double tmp;
if (t_0 <= -500000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (-z * y) * x
if (t_0 <= (-500000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = 1.0d0 * x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-z * y) * x;
double tmp;
if (t_0 <= -500000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) t_1 = (-z * y) * x tmp = 0 if t_0 <= -500000.0: tmp = t_1 elif t_0 <= 2.0: tmp = 1.0 * x else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(Float64(-z) * y) * x) tmp = 0.0 if (t_0 <= -500000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(1.0 * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); t_1 = (-z * y) * x; tmp = 0.0; if (t_0 <= -500000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = 1.0 * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-z) * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -500000.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(1.0 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(\left(-z\right) \cdot y\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -500000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -5e5 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 96.1%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6494.4
Applied rewrites94.4%
if -5e5 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites98.2%
Final simplification96.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* (- x) y) z))) (if (<= (* y z) -50000.0) t_0 (if (<= (* y z) 0.0005) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -50000.0) {
tmp = t_0;
} else if ((y * z) <= 0.0005) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
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 = (-x * y) * z
if ((y * z) <= (-50000.0d0)) then
tmp = t_0
else if ((y * z) <= 0.0005d0) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (-x * y) * z;
double tmp;
if ((y * z) <= -50000.0) {
tmp = t_0;
} else if ((y * z) <= 0.0005) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (-x * y) * z tmp = 0 if (y * z) <= -50000.0: tmp = t_0 elif (y * z) <= 0.0005: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(-x) * y) * z) tmp = 0.0 if (Float64(y * z) <= -50000.0) tmp = t_0; elseif (Float64(y * z) <= 0.0005) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (-x * y) * z; tmp = 0.0; if ((y * z) <= -50000.0) tmp = t_0; elseif ((y * z) <= 0.0005) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -50000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.0005], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;y \cdot z \leq -50000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.0005:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -5e4 or 5.0000000000000001e-4 < (*.f64 y z) Initial program 96.1%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
lower--.f64N/A
lower-*.f6496.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in z around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.2
Applied rewrites90.2%
Taylor expanded in z around inf
Applied rewrites90.7%
if -5e4 < (*.f64 y z) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites98.2%
Final simplification94.4%
(FPCore (x y z) :precision binary64 (* (- 1.0 (* y z)) x))
double code(double x, double y, double z) {
return (1.0 - (y * z)) * x;
}
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 - (y * z)) * x
end function
public static double code(double x, double y, double z) {
return (1.0 - (y * z)) * x;
}
def code(x, y, z): return (1.0 - (y * z)) * x
function code(x, y, z) return Float64(Float64(1.0 - Float64(y * z)) * x) end
function tmp = code(x, y, z) tmp = (1.0 - (y * z)) * x; end
code[x_, y_, z_] := N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - y \cdot z\right) \cdot x
\end{array}
Initial program 98.0%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
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
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in z around 0
Applied rewrites50.0%
Final simplification50.0%
herbie shell --seed 2024235
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))