
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= (* z y) -1e+286)
(* t_0 y)
(if (<= (* z y) 5e+83)
(* (- 1.0 (* z y)) x)
(/ 1.0 (/ 1.0 (fma t_0 y x)))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if ((z * y) <= -1e+286) {
tmp = t_0 * y;
} else if ((z * y) <= 5e+83) {
tmp = (1.0 - (z * y)) * x;
} else {
tmp = 1.0 / (1.0 / fma(t_0, y, x));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (Float64(z * y) <= -1e+286) tmp = Float64(t_0 * y); elseif (Float64(z * y) <= 5e+83) tmp = Float64(Float64(1.0 - Float64(z * y)) * x); else tmp = Float64(1.0 / Float64(1.0 / fma(t_0, y, x))); end return 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[((-z) * x), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1e+286], N[(t$95$0 * y), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 5e+83], N[(N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(1.0 / N[(1.0 / N[(t$95$0 * y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+286}:\\
\;\;\;\;t\_0 \cdot y\\
\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+83}:\\
\;\;\;\;\left(1 - z \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{\mathsf{fma}\left(t\_0, y, x\right)}}\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000003e286Initial program 63.9%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
Applied rewrites0.4%
Taylor expanded in z 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.6
Applied rewrites99.6%
Applied rewrites99.9%
if -1.00000000000000003e286 < (*.f64 y z) < 5.00000000000000029e83Initial program 99.8%
if 5.00000000000000029e83 < (*.f64 y z) Initial program 81.9%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.0
Applied rewrites99.0%
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
associate-*l*N/A
lift-*.f64N/A
flip3-+N/A
clear-numN/A
lower-/.f64N/A
Applied rewrites96.8%
Final simplification99.5%
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 (* z y)) x)) (t_1 (fma (* (- z) x) y x))) (if (<= t_0 -5e-23) t_1 (if (<= t_0 1e+307) t_0 t_1))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (1.0 - (z * y)) * x;
double t_1 = fma((-z * x), y, x);
double tmp;
if (t_0 <= -5e-23) {
tmp = t_1;
} else if (t_0 <= 1e+307) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(1.0 - Float64(z * y)) * x) t_1 = fma(Float64(Float64(-z) * x), y, x) tmp = 0.0 if (t_0 <= -5e-23) tmp = t_1; elseif (t_0 <= 1e+307) tmp = t_0; else tmp = t_1; end return 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[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-z) * x), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-23], t$95$1, If[LessEqual[t$95$0, 1e+307], t$95$0, t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(1 - z \cdot y\right) \cdot x\\
t_1 := \mathsf{fma}\left(\left(-z\right) \cdot x, y, x\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+307}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) < -5.0000000000000002e-23 or 9.99999999999999986e306 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) Initial program 87.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.f6493.9
Applied rewrites93.9%
if -5.0000000000000002e-23 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) < 9.99999999999999986e306Initial program 99.8%
Final simplification97.3%
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 (* z y)) x)) (t_1 (* (* (- z) x) y))) (if (<= t_0 -5e+100) t_1 (if (<= t_0 2e+307) t_0 t_1))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (1.0 - (z * y)) * x;
double t_1 = (-z * x) * y;
double tmp;
if (t_0 <= -5e+100) {
tmp = t_1;
} else if (t_0 <= 2e+307) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (1.0d0 - (z * y)) * x
t_1 = (-z * x) * y
if (t_0 <= (-5d+100)) then
tmp = t_1
else if (t_0 <= 2d+307) then
tmp = t_0
else
tmp = t_1
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 - (z * y)) * x;
double t_1 = (-z * x) * y;
double tmp;
if (t_0 <= -5e+100) {
tmp = t_1;
} else if (t_0 <= 2e+307) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (1.0 - (z * y)) * x t_1 = (-z * x) * y tmp = 0 if t_0 <= -5e+100: tmp = t_1 elif t_0 <= 2e+307: tmp = t_0 else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(1.0 - Float64(z * y)) * x) t_1 = Float64(Float64(Float64(-z) * x) * y) tmp = 0.0 if (t_0 <= -5e+100) tmp = t_1; elseif (t_0 <= 2e+307) tmp = t_0; else tmp = t_1; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (1.0 - (z * y)) * x;
t_1 = (-z * x) * y;
tmp = 0.0;
if (t_0 <= -5e+100)
tmp = t_1;
elseif (t_0 <= 2e+307)
tmp = t_0;
else
tmp = t_1;
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[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-z) * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+100], t$95$1, If[LessEqual[t$95$0, 2e+307], t$95$0, t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(1 - z \cdot y\right) \cdot x\\
t_1 := \left(\left(-z\right) \cdot x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+100}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) < -4.9999999999999999e100 or 1.99999999999999997e307 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) Initial program 84.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6491.9
Applied rewrites91.9%
Applied rewrites10.8%
Taylor expanded in z 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.f6474.2
Applied rewrites74.2%
Applied rewrites72.2%
if -4.9999999999999999e100 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 y z))) < 1.99999999999999997e307Initial program 99.8%
Final simplification90.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* (- z) x) y)))
(if (<= (* z y) -1e+286)
t_0
(if (<= (* z y) -500.0)
(* (* (- y) z) x)
(if (<= (* z y) 5e-5) (* 1.0 x) t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (-z * x) * y;
double tmp;
if ((z * y) <= -1e+286) {
tmp = t_0;
} else if ((z * y) <= -500.0) {
tmp = (-y * z) * x;
} else if ((z * y) <= 5e-5) {
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 = (-z * x) * y
if ((z * y) <= (-1d+286)) then
tmp = t_0
else if ((z * y) <= (-500.0d0)) then
tmp = (-y * z) * x
else if ((z * y) <= 5d-5) 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 = (-z * x) * y;
double tmp;
if ((z * y) <= -1e+286) {
tmp = t_0;
} else if ((z * y) <= -500.0) {
tmp = (-y * z) * x;
} else if ((z * y) <= 5e-5) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (-z * x) * y tmp = 0 if (z * y) <= -1e+286: tmp = t_0 elif (z * y) <= -500.0: tmp = (-y * z) * x elif (z * y) <= 5e-5: 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(-z) * x) * y) tmp = 0.0 if (Float64(z * y) <= -1e+286) tmp = t_0; elseif (Float64(z * y) <= -500.0) tmp = Float64(Float64(Float64(-y) * z) * x); elseif (Float64(z * y) <= 5e-5) 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 = (-z * x) * y;
tmp = 0.0;
if ((z * y) <= -1e+286)
tmp = t_0;
elseif ((z * y) <= -500.0)
tmp = (-y * z) * x;
elseif ((z * y) <= 5e-5)
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[((-z) * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1e+286], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], -500.0], N[(N[((-y) * z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 5e-5], 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(-z\right) \cdot x\right) \cdot y\\
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+286}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \cdot y \leq -500:\\
\;\;\;\;\left(\left(-y\right) \cdot z\right) \cdot x\\
\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{-5}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000003e286 or 5.00000000000000024e-5 < (*.f64 y z) Initial program 80.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6497.9
Applied rewrites97.9%
Applied rewrites20.5%
Taylor expanded in z 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.f6495.8
Applied rewrites95.8%
Applied rewrites90.7%
if -1.00000000000000003e286 < (*.f64 y z) < -500Initial program 99.5%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
if -500 < (*.f64 y z) < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites97.5%
Final simplification95.3%
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 (* z y))))
(if (<= t_0 -2.0)
(* (* (- z) x) y)
(if (<= t_0 10000.0) (* 1.0 x) (* (* (- y) x) z)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (z * y);
double tmp;
if (t_0 <= -2.0) {
tmp = (-z * x) * y;
} else if (t_0 <= 10000.0) {
tmp = 1.0 * x;
} 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 - (z * y)
if (t_0 <= (-2.0d0)) then
tmp = (-z * x) * y
else if (t_0 <= 10000.0d0) then
tmp = 1.0d0 * x
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 - (z * y);
double tmp;
if (t_0 <= -2.0) {
tmp = (-z * x) * y;
} else if (t_0 <= 10000.0) {
tmp = 1.0 * x;
} else {
tmp = (-y * x) * z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (z * y) tmp = 0 if t_0 <= -2.0: tmp = (-z * x) * y elif t_0 <= 10000.0: tmp = 1.0 * x 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(z * y)) tmp = 0.0 if (t_0 <= -2.0) tmp = Float64(Float64(Float64(-z) * x) * y); elseif (t_0 <= 10000.0) tmp = Float64(1.0 * x); 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 - (z * y);
tmp = 0.0;
if (t_0 <= -2.0)
tmp = (-z * x) * y;
elseif (t_0 <= 10000.0)
tmp = 1.0 * x;
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[(z * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2.0], N[(N[((-z) * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 10000.0], N[(1.0 * x), $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 - z \cdot y\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;\left(\left(-z\right) \cdot x\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 10000:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-y\right) \cdot x\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2Initial program 87.3%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6497.1
Applied rewrites97.1%
Applied rewrites29.7%
Taylor expanded in z 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.1
Applied rewrites94.1%
Applied rewrites86.5%
if -2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 1e4Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites96.3%
if 1e4 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 88.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6489.0
Applied rewrites89.0%
Applied rewrites19.9%
Taylor expanded in z 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.f6487.9
Applied rewrites87.9%
Final simplification92.4%
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 (* z y))) (t_1 (* (* (- z) x) y))) (if (<= t_0 -2.0) t_1 (if (<= t_0 2.0) (* 1.0 x) t_1))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (z * y);
double t_1 = (-z * x) * y;
double tmp;
if (t_0 <= -2.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (z * y)
t_1 = (-z * x) * y
if (t_0 <= (-2.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
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (z * y);
double t_1 = (-z * x) * y;
double tmp;
if (t_0 <= -2.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (z * y) t_1 = (-z * x) * y tmp = 0 if t_0 <= -2.0: tmp = t_1 elif t_0 <= 2.0: tmp = 1.0 * x else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(z * y)) t_1 = Float64(Float64(Float64(-z) * x) * y) tmp = 0.0 if (t_0 <= -2.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(1.0 * x); else tmp = t_1; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (z * y);
t_1 = (-z * x) * y;
tmp = 0.0;
if (t_0 <= -2.0)
tmp = t_1;
elseif (t_0 <= 2.0)
tmp = 1.0 * x;
else
tmp = t_1;
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[(z * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-z) * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(1.0 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - z \cdot y\\
t_1 := \left(\left(-z\right) \cdot x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;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)) < -2 or 2 < (-.f64 #s(literal 1 binary64) (*.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
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6491.6
Applied rewrites91.6%
Applied rewrites23.6%
Taylor expanded in z 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.f6489.2
Applied rewrites89.2%
Applied rewrites84.3%
if -2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites97.5%
Final simplification91.7%
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.6%
Taylor expanded in z around 0
Applied rewrites56.1%
Final simplification56.1%
herbie shell --seed 2024259
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))