
(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 7 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 (if (<= (* y z) -5e+99) (* z (* y (- x))) (if (<= (* y z) 1e+248) (- x (* (* y z) x)) (* y (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+99) {
tmp = z * (y * -x);
} else if ((y * z) <= 1e+248) {
tmp = x - ((y * z) * 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) <= (-5d+99)) then
tmp = z * (y * -x)
else if ((y * z) <= 1d+248) then
tmp = x - ((y * z) * 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) <= -5e+99) {
tmp = z * (y * -x);
} else if ((y * z) <= 1e+248) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+99: tmp = z * (y * -x) elif (y * z) <= 1e+248: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+99) tmp = Float64(z * Float64(y * Float64(-x))); elseif (Float64(y * z) <= 1e+248) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -5e+99) tmp = z * (y * -x); elseif ((y * z) <= 1e+248) tmp = x - ((y * z) * x); else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+99], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e+248], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+99}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 10^{+248}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000008e99Initial program 85.3%
Taylor expanded in z around inf 99.8%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -5.00000000000000008e99 < (*.f64 y z) < 1.00000000000000005e248Initial program 99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
distribute-rgt-neg-in99.9%
Applied egg-rr99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
add-sqr-sqrt45.8%
sqrt-unprod71.7%
sqr-neg71.7%
sqrt-unprod37.3%
add-sqr-sqrt69.0%
*-commutative69.0%
cancel-sign-sub-inv69.0%
associate-*l*67.0%
add-sqr-sqrt36.8%
sqrt-unprod70.2%
sqr-neg70.2%
sqrt-unprod41.8%
add-sqr-sqrt93.5%
Applied egg-rr93.5%
Taylor expanded in y around 0 99.9%
if 1.00000000000000005e248 < (*.f64 y z) Initial program 79.8%
Taylor expanded in y around inf 79.8%
mul-1-neg79.8%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+99) (* z (* y (- x))) (if (<= (* y z) 1e+248) (* x (- 1.0 (* y z))) (* y (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+99) {
tmp = z * (y * -x);
} else if ((y * z) <= 1e+248) {
tmp = x * (1.0 - (y * z));
} 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) <= (-5d+99)) then
tmp = z * (y * -x)
else if ((y * z) <= 1d+248) then
tmp = x * (1.0d0 - (y * z))
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) <= -5e+99) {
tmp = z * (y * -x);
} else if ((y * z) <= 1e+248) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+99: tmp = z * (y * -x) elif (y * z) <= 1e+248: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+99) tmp = Float64(z * Float64(y * Float64(-x))); elseif (Float64(y * z) <= 1e+248) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -5e+99) tmp = z * (y * -x); elseif ((y * z) <= 1e+248) tmp = x * (1.0 - (y * z)); else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+99], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e+248], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+99}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 10^{+248}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000008e99Initial program 85.3%
Taylor expanded in z around inf 99.8%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -5.00000000000000008e99 < (*.f64 y z) < 1.00000000000000005e248Initial program 99.9%
if 1.00000000000000005e248 < (*.f64 y z) Initial program 79.8%
Taylor expanded in y around inf 79.8%
mul-1-neg79.8%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e-52) (not (<= z 3.2e+47))) (* z (* y (- x))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-52) || !(z <= 3.2e+47)) {
tmp = z * (y * -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 ((z <= (-3.8d-52)) .or. (.not. (z <= 3.2d+47))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-52) || !(z <= 3.2e+47)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e-52) or not (z <= 3.2e+47): tmp = z * (y * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e-52) || !(z <= 3.2e+47)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e-52) || ~((z <= 3.2e+47))) tmp = z * (y * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e-52], N[Not[LessEqual[z, 3.2e+47]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-52} \lor \neg \left(z \leq 3.2 \cdot 10^{+47}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.8000000000000003e-52 or 3.2e47 < z Initial program 91.2%
Taylor expanded in z around inf 91.7%
Taylor expanded in y around inf 73.3%
mul-1-neg73.3%
*-commutative73.3%
distribute-rgt-neg-in73.3%
Simplified73.3%
if -3.8000000000000003e-52 < z < 3.2e47Initial program 99.9%
Taylor expanded in y around 0 82.8%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.6e-124) (not (<= z 3.8e+49))) (* y (* z (- x))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.6e-124) || !(z <= 3.8e+49)) {
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 ((z <= (-9.6d-124)) .or. (.not. (z <= 3.8d+49))) 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 ((z <= -9.6e-124) || !(z <= 3.8e+49)) {
tmp = y * (z * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.6e-124) or not (z <= 3.8e+49): tmp = y * (z * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.6e-124) || !(z <= 3.8e+49)) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.6e-124) || ~((z <= 3.8e+49))) tmp = y * (z * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.6e-124], N[Not[LessEqual[z, 3.8e+49]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{-124} \lor \neg \left(z \leq 3.8 \cdot 10^{+49}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.5999999999999997e-124 or 3.7999999999999999e49 < z Initial program 91.6%
Taylor expanded in y around inf 66.6%
mul-1-neg66.6%
associate-*r*71.3%
distribute-rgt-neg-in71.3%
*-commutative71.3%
associate-*l*71.9%
Simplified71.9%
if -9.5999999999999997e-124 < z < 3.7999999999999999e49Initial program 99.9%
Taylor expanded in y around 0 83.4%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-123) (not (<= z 6.4e+95))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-123) || !(z <= 6.4e+95)) {
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 ((z <= (-6.5d-123)) .or. (.not. (z <= 6.4d+95))) 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 ((z <= -6.5e-123) || !(z <= 6.4e+95)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-123) or not (z <= 6.4e+95): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-123) || !(z <= 6.4e+95)) 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 ((z <= -6.5e-123) || ~((z <= 6.4e+95))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-123], N[Not[LessEqual[z, 6.4e+95]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-123} \lor \neg \left(z \leq 6.4 \cdot 10^{+95}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.49999999999999938e-123 or 6.4000000000000001e95 < z Initial program 91.2%
Taylor expanded in y around inf 64.9%
mul-1-neg64.9%
distribute-rgt-neg-in64.9%
distribute-rgt-neg-out64.9%
Simplified64.9%
if -6.49999999999999938e-123 < z < 6.4000000000000001e95Initial program 99.9%
Taylor expanded in y around 0 78.5%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (<= z 6.2e+154) x (/ (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 6.2e+154) {
tmp = x;
} else {
tmp = (z * x) / z;
}
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 (z <= 6.2d+154) then
tmp = x
else
tmp = (z * x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6.2e+154) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6.2e+154: tmp = x else: tmp = (z * x) / z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6.2e+154) tmp = x; else tmp = Float64(Float64(z * x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6.2e+154) tmp = x; else tmp = (z * x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6.2e+154], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.2 \cdot 10^{+154}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 6.2000000000000003e154Initial program 95.3%
Taylor expanded in y around 0 57.3%
if 6.2000000000000003e154 < z Initial program 94.2%
Taylor expanded in z around inf 91.1%
Taylor expanded in y around 0 3.8%
associate-*r/12.1%
Applied egg-rr12.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 95.1%
Taylor expanded in y around 0 50.8%
herbie shell --seed 2024123
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))