
(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 6 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 (* x (* y z))))
double code(double x, double y, double z) {
return x - (x * (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 - (x * (y * z))
end function
public static double code(double x, double y, double z) {
return x - (x * (y * z));
}
def code(x, y, z): return x - (x * (y * z))
function code(x, y, z) return Float64(x - Float64(x * Float64(y * z))) end
function tmp = code(x, y, z) tmp = x - (x * (y * z)); end
code[x_, y_, z_] := N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - x \cdot \left(y \cdot z\right)
\end{array}
Initial program 98.1%
sub-neg98.1%
distribute-rgt-in98.1%
*-un-lft-identity98.1%
distribute-rgt-neg-in98.1%
Applied egg-rr98.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -20000000000000.0) (not (<= (* y z) 0.1))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20000000000000.0) || !((y * z) <= 0.1)) {
tmp = (y * z) * -x;
} else {
tmp = 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 (((y * z) <= (-20000000000000.0d0)) .or. (.not. ((y * z) <= 0.1d0))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20000000000000.0) || !((y * z) <= 0.1)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -20000000000000.0) or not ((y * z) <= 0.1): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -20000000000000.0) || !(Float64(y * z) <= 0.1)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -20000000000000.0) || ~(((y * z) <= 0.1))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -20000000000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.1]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000000000 \lor \neg \left(y \cdot z \leq 0.1\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e13 or 0.10000000000000001 < (*.f64 y z) Initial program 96.2%
Taylor expanded in y around inf 95.3%
mul-1-neg95.3%
associate-*r*90.9%
Simplified90.9%
Taylor expanded in x around 0 95.3%
if -2e13 < (*.f64 y z) < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.1%
Final simplification97.2%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -20000000000000.0) (* z (* y (- x))) (if (<= (* y z) 0.1) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -20000000000000.0) {
tmp = z * (y * -x);
} else if ((y * z) <= 0.1) {
tmp = x;
} else {
tmp = (y * z) * -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 ((y * z) <= (-20000000000000.0d0)) then
tmp = z * (y * -x)
else if ((y * z) <= 0.1d0) then
tmp = x
else
tmp = (y * z) * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -20000000000000.0) {
tmp = z * (y * -x);
} else if ((y * z) <= 0.1) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -20000000000000.0: tmp = z * (y * -x) elif (y * z) <= 0.1: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -20000000000000.0) tmp = Float64(z * Float64(y * Float64(-x))); elseif (Float64(y * z) <= 0.1) tmp = x; else tmp = Float64(Float64(y * z) * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -20000000000000.0) tmp = z * (y * -x); elseif ((y * z) <= 0.1) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -20000000000000.0], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.1], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000000000:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e13Initial program 94.0%
Taylor expanded in y around inf 93.8%
mul-1-neg93.8%
associate-*r*96.6%
Simplified96.6%
if -2e13 < (*.f64 y z) < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.1%
if 0.10000000000000001 < (*.f64 y z) Initial program 98.3%
Taylor expanded in y around inf 96.8%
mul-1-neg96.8%
associate-*r*85.2%
Simplified85.2%
Taylor expanded in x around 0 96.8%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -1e+15) (* y (* x (- z))) (if (<= (* y z) 0.1) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+15) {
tmp = y * (x * -z);
} else if ((y * z) <= 0.1) {
tmp = x;
} else {
tmp = (y * z) * -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 ((y * z) <= (-1d+15)) then
tmp = y * (x * -z)
else if ((y * z) <= 0.1d0) then
tmp = x
else
tmp = (y * z) * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+15) {
tmp = y * (x * -z);
} else if ((y * z) <= 0.1) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -1e+15: tmp = y * (x * -z) elif (y * z) <= 0.1: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1e+15) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(y * z) <= 0.1) tmp = x; else tmp = Float64(Float64(y * z) * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -1e+15) tmp = y * (x * -z); elseif ((y * z) <= 0.1) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -1e+15], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.1], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+15}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1e15Initial program 93.9%
Taylor expanded in y around inf 93.9%
mul-1-neg93.9%
associate-*r*96.7%
distribute-rgt-neg-in96.7%
*-commutative96.7%
associate-*l*95.4%
Simplified95.4%
if -1e15 < (*.f64 y z) < 0.10000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.4%
if 0.10000000000000001 < (*.f64 y z) Initial program 98.3%
Taylor expanded in y around inf 96.8%
mul-1-neg96.8%
associate-*r*85.2%
Simplified85.2%
Taylor expanded in x around 0 96.8%
Final simplification97.2%
(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}
Initial program 98.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 98.1%
Taylor expanded in y around 0 50.3%
Final simplification50.3%
herbie shell --seed 2024079
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))