
(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 and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* 3.0 y) x (- z)))
assert(x < y);
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
x, y = sort([x, y]) function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-z)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.5%
associate-*l*99.4%
*-commutative99.4%
fma-neg99.4%
Simplified99.4%
Final simplification99.4%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* 3.0 x))))
(if (<= t_0 -5e+70)
t_0
(if (<= t_0 10000000000000.0) (- z) (* (* 3.0 y) x)))))assert(x < y);
double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -5e+70) {
tmp = t_0;
} else if (t_0 <= 10000000000000.0) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
NOTE: x and y 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 = y * (3.0d0 * x)
if (t_0 <= (-5d+70)) then
tmp = t_0
else if (t_0 <= 10000000000000.0d0) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -5e+70) {
tmp = t_0;
} else if (t_0 <= 10000000000000.0) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): t_0 = y * (3.0 * x) tmp = 0 if t_0 <= -5e+70: tmp = t_0 elif t_0 <= 10000000000000.0: tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y = sort([x, y]) function code(x, y, z) t_0 = Float64(y * Float64(3.0 * x)) tmp = 0.0 if (t_0 <= -5e+70) tmp = t_0; elseif (t_0 <= 10000000000000.0) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
t_0 = y * (3.0 * x);
tmp = 0.0;
if (t_0 <= -5e+70)
tmp = t_0;
elseif (t_0 <= 10000000000000.0)
tmp = -z;
else
tmp = (3.0 * y) * x;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+70], t$95$0, If[LessEqual[t$95$0, 10000000000000.0], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(3 \cdot x\right)\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 10000000000000:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 (*.f64 x 3) y) < -5.0000000000000002e70Initial program 99.8%
associate-*l*99.6%
Simplified99.6%
associate-*r*99.8%
add-sqr-sqrt57.6%
associate-*r*57.7%
fma-neg57.7%
add-sqr-sqrt27.8%
sqrt-unprod45.7%
sqr-neg45.7%
sqrt-unprod19.9%
add-sqr-sqrt47.7%
Applied egg-rr47.7%
Taylor expanded in x around inf 88.3%
rem-cube-cbrt87.1%
associate-*r*87.2%
*-commutative87.2%
associate-*l*87.1%
Applied egg-rr87.1%
rem-cube-cbrt88.2%
associate-*r*88.4%
Applied egg-rr88.4%
if -5.0000000000000002e70 < (*.f64 (*.f64 x 3) y) < 1e13Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.7%
mul-1-neg77.7%
Simplified77.7%
if 1e13 < (*.f64 (*.f64 x 3) y) Initial program 98.2%
associate-*l*98.2%
Simplified98.2%
associate-*r*98.2%
add-sqr-sqrt55.7%
associate-*r*55.6%
fma-neg55.6%
add-sqr-sqrt26.9%
sqrt-unprod41.5%
sqr-neg41.5%
sqrt-unprod21.2%
add-sqr-sqrt43.1%
Applied egg-rr43.1%
Taylor expanded in x around inf 81.1%
associate-*r*79.6%
*-commutative79.6%
associate-*r*79.5%
Simplified79.5%
Final simplification80.2%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= z -2.4e+137)
(not
(or (<= z -5.2e+75) (and (not (<= z -2.8e-16)) (<= z 3.35e+53)))))
(- z)
(* 3.0 (* y x))))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
NOTE: x and y 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 ((z <= (-2.4d+137)) .or. (.not. (z <= (-5.2d+75)) .or. (.not. (z <= (-2.8d-16))) .and. (z <= 3.35d+53))) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z <= -2.4e+137) or not ((z <= -5.2e+75) or (not (z <= -2.8e-16) and (z <= 3.35e+53))): tmp = -z else: tmp = 3.0 * (y * x) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+137) || !((z <= -5.2e+75) || (!(z <= -2.8e-16) && (z <= 3.35e+53)))) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.4e+137) || ~(((z <= -5.2e+75) || (~((z <= -2.8e-16)) && (z <= 3.35e+53)))))
tmp = -z;
else
tmp = 3.0 * (y * x);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e+137], N[Not[Or[LessEqual[z, -5.2e+75], And[N[Not[LessEqual[z, -2.8e-16]], $MachinePrecision], LessEqual[z, 3.35e+53]]]], $MachinePrecision]], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+137} \lor \neg \left(z \leq -5.2 \cdot 10^{+75} \lor \neg \left(z \leq -2.8 \cdot 10^{-16}\right) \land z \leq 3.35 \cdot 10^{+53}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if z < -2.39999999999999983e137 or -5.1999999999999997e75 < z < -2.8000000000000001e-16 or 3.3499999999999999e53 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 85.2%
mul-1-neg85.2%
Simplified85.2%
if -2.39999999999999983e137 < z < -5.1999999999999997e75 or -2.8000000000000001e-16 < z < 3.3499999999999999e53Initial program 99.1%
associate-*l*99.1%
Simplified99.1%
associate-*r*99.1%
add-sqr-sqrt51.3%
associate-*r*51.3%
fma-neg51.4%
add-sqr-sqrt26.0%
sqrt-unprod42.7%
sqr-neg42.7%
sqrt-unprod18.1%
add-sqr-sqrt39.7%
Applied egg-rr39.7%
Taylor expanded in x around inf 72.7%
Final simplification77.7%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= z -2.4e+137)
(not
(or (<= z -1.35e+75) (and (not (<= z -2.05e-16)) (<= z 5.8e+52)))))
(- z)
(* (* 3.0 y) x)))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || !((z <= -1.35e+75) || (!(z <= -2.05e-16) && (z <= 5.8e+52)))) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
NOTE: x and y 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 ((z <= (-2.4d+137)) .or. (.not. (z <= (-1.35d+75)) .or. (.not. (z <= (-2.05d-16))) .and. (z <= 5.8d+52))) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+137) || !((z <= -1.35e+75) || (!(z <= -2.05e-16) && (z <= 5.8e+52)))) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z <= -2.4e+137) or not ((z <= -1.35e+75) or (not (z <= -2.05e-16) and (z <= 5.8e+52))): tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+137) || !((z <= -1.35e+75) || (!(z <= -2.05e-16) && (z <= 5.8e+52)))) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.4e+137) || ~(((z <= -1.35e+75) || (~((z <= -2.05e-16)) && (z <= 5.8e+52)))))
tmp = -z;
else
tmp = (3.0 * y) * x;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e+137], N[Not[Or[LessEqual[z, -1.35e+75], And[N[Not[LessEqual[z, -2.05e-16]], $MachinePrecision], LessEqual[z, 5.8e+52]]]], $MachinePrecision]], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+137} \lor \neg \left(z \leq -1.35 \cdot 10^{+75} \lor \neg \left(z \leq -2.05 \cdot 10^{-16}\right) \land z \leq 5.8 \cdot 10^{+52}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.39999999999999983e137 or -1.34999999999999999e75 < z < -2.05000000000000003e-16 or 5.8e52 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 85.2%
mul-1-neg85.2%
Simplified85.2%
if -2.39999999999999983e137 < z < -1.34999999999999999e75 or -2.05000000000000003e-16 < z < 5.8e52Initial program 99.1%
associate-*l*99.1%
Simplified99.1%
associate-*r*99.1%
add-sqr-sqrt51.3%
associate-*r*51.3%
fma-neg51.4%
add-sqr-sqrt26.0%
sqrt-unprod42.7%
sqr-neg42.7%
sqrt-unprod18.1%
add-sqr-sqrt39.7%
Applied egg-rr39.7%
Taylor expanded in x around inf 72.7%
associate-*r*72.1%
*-commutative72.1%
associate-*r*72.1%
Simplified72.1%
Final simplification77.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
assert(x < y);
double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
NOTE: x and y 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 * (y * x)) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (3.0 * (y * x)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (y * x)) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
3 \cdot \left(y \cdot x\right) - z
\end{array}
Initial program 99.5%
associate-*l*99.4%
Simplified99.4%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* 3.0 y) x) z))
assert(x < y);
double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
NOTE: x and y 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 * y) * x) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return ((3.0 * y) * x) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(Float64(3.0 * y) * x) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = ((3.0 * y) * x) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.5%
associate-*l*99.4%
Simplified99.4%
Final simplification99.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y);
double code(double x, double y, double z) {
return -z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return -z;
}
[x, y] = sort([x, y]) def code(x, y, z): return -z
x, y = sort([x, y]) function code(x, y, z) return Float64(-z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
-z
\end{array}
Initial program 99.5%
associate-*l*99.4%
Simplified99.4%
Taylor expanded in x around 0 51.6%
mul-1-neg51.6%
Simplified51.6%
Final simplification51.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 z)
assert(x < y);
double code(double x, double y, double z) {
return z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return z;
}
[x, y] = sort([x, y]) def code(x, y, z): return z
x, y = sort([x, y]) function code(x, y, z) return z end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := z
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
z
\end{array}
Initial program 99.5%
associate-*l*99.4%
Simplified99.4%
associate-*r*99.5%
add-sqr-sqrt52.5%
associate-*r*52.5%
fma-neg52.5%
add-sqr-sqrt24.8%
sqrt-unprod31.1%
sqr-neg31.1%
sqrt-unprod12.5%
add-sqr-sqrt26.7%
Applied egg-rr26.7%
Taylor expanded in x around 0 2.3%
Final simplification2.3%
(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 2023336
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))