
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.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 * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.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 * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
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 = (y * (x * 3.0d0)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (y * (x * 3.0)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (y * (x * 3.0)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -1.65e+93) (not (<= x 2.55e-86))) (* x (* 3.0 y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+93) || !(x <= 2.55e-86)) {
tmp = x * (3.0 * y);
} else {
tmp = -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) :: tmp
if ((x <= (-1.65d+93)) .or. (.not. (x <= 2.55d-86))) then
tmp = x * (3.0d0 * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+93) || !(x <= 2.55e-86)) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -1.65e+93) or not (x <= 2.55e-86): tmp = x * (3.0 * y) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -1.65e+93) || !(x <= 2.55e-86)) tmp = Float64(x * Float64(3.0 * y)); else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x <= -1.65e+93) || ~((x <= 2.55e-86)))
tmp = x * (3.0 * y);
else
tmp = -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_] := If[Or[LessEqual[x, -1.65e+93], N[Not[LessEqual[x, 2.55e-86]], $MachinePrecision]], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+93} \lor \neg \left(x \leq 2.55 \cdot 10^{-86}\right):\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.65000000000000004e93 or 2.55000000000000003e-86 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 87.9%
Taylor expanded in z around 0 63.2%
*-commutative63.2%
associate-*l*63.3%
*-commutative63.3%
Simplified63.3%
if -1.65000000000000004e93 < x < 2.55000000000000003e-86Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 73.9%
mul-1-neg73.9%
Simplified73.9%
Final simplification69.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -5.8e+92) (not (<= x 8e-87))) (* 3.0 (* x y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+92) || !(x <= 8e-87)) {
tmp = 3.0 * (x * y);
} else {
tmp = -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) :: tmp
if ((x <= (-5.8d+92)) .or. (.not. (x <= 8d-87))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+92) || !(x <= 8e-87)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -5.8e+92) or not (x <= 8e-87): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -5.8e+92) || !(x <= 8e-87)) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x <= -5.8e+92) || ~((x <= 8e-87)))
tmp = 3.0 * (x * y);
else
tmp = -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_] := If[Or[LessEqual[x, -5.8e+92], N[Not[LessEqual[x, 8e-87]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+92} \lor \neg \left(x \leq 8 \cdot 10^{-87}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.8000000000000001e92 or 8.00000000000000014e-87 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 87.9%
Taylor expanded in z around 0 63.2%
if -5.8000000000000001e92 < x < 8.00000000000000014e-87Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 73.9%
mul-1-neg73.9%
Simplified73.9%
Final simplification69.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -2.4e+93) (* y (* x 3.0)) (if (<= x 2.55e-86) (- z) (* x (* 3.0 y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+93) {
tmp = y * (x * 3.0);
} else if (x <= 2.55e-86) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
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) :: tmp
if (x <= (-2.4d+93)) then
tmp = y * (x * 3.0d0)
else if (x <= 2.55d-86) then
tmp = -z
else
tmp = x * (3.0d0 * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+93) {
tmp = y * (x * 3.0);
} else if (x <= 2.55e-86) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -2.4e+93: tmp = y * (x * 3.0) elif x <= 2.55e-86: tmp = -z else: tmp = x * (3.0 * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -2.4e+93) tmp = Float64(y * Float64(x * 3.0)); elseif (x <= 2.55e-86) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -2.4e+93)
tmp = y * (x * 3.0);
elseif (x <= 2.55e-86)
tmp = -z;
else
tmp = x * (3.0 * y);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -2.4e+93], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.55e-86], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+93}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{-86}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if x < -2.4000000000000001e93Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in z around inf 90.8%
Taylor expanded in z around 0 71.3%
associate-*r*71.3%
*-commutative71.3%
Simplified71.3%
if -2.4000000000000001e93 < x < 2.55000000000000003e-86Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 73.9%
mul-1-neg73.9%
Simplified73.9%
if 2.55000000000000003e-86 < x Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 86.2%
Taylor expanded in z around 0 58.8%
*-commutative58.8%
associate-*l*58.9%
*-commutative58.9%
Simplified58.9%
Final simplification69.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
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 = (x * (3.0d0 * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
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 = (3.0d0 * (x * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -z;
}
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 = -z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return -z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return -z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 56.8%
mul-1-neg56.8%
Simplified56.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 z)
assert(x < y && y < z);
double code(double x, double y, double z) {
return z;
}
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 = z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z
x, y, z = sort([x, y, z]) function code(x, y, z) return z end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := z
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 56.8%
mul-1-neg56.8%
Simplified56.8%
neg-sub056.8%
sub-neg56.8%
add-sqr-sqrt22.1%
sqrt-unprod13.5%
sqr-neg13.5%
sqrt-unprod1.2%
add-sqr-sqrt2.2%
Applied egg-rr2.2%
+-lft-identity2.2%
Simplified2.2%
(FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
double code(double x, double y, double z) {
return (x * (3.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 * (3.0d0 * y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
def code(x, y, z): return (x * (3.0 * y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
function tmp = code(x, y, z) tmp = (x * (3.0 * y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
herbie shell --seed 2024163
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))