
(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 7 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 (- (* y (* x 3.0)) z))
assert(x < y);
double code(double x, double y, double z) {
return (y * (x * 3.0)) - 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 = (y * (x * 3.0d0)) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (y * (x * 3.0)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (y * (x * 3.0)) - z;
end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 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
(if (or (<= y -1.5e+51)
(not
(or (<= y 2.3e-16)
(and (not (<= y 2400.0))
(or (<= y 7.5e+77)
(and (not (<= y 4.1e+107)) (<= y 8.8e+134)))))))
(* 3.0 (* x y))
(- z)))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134)))))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
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 ((y <= (-1.5d+51)) .or. (.not. (y <= 2.3d-16) .or. (.not. (y <= 2400.0d0)) .and. (y <= 7.5d+77) .or. (.not. (y <= 4.1d+107)) .and. (y <= 8.8d+134))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134)))))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (y <= -1.5e+51) or not ((y <= 2.3e-16) or (not (y <= 2400.0) and ((y <= 7.5e+77) or (not (y <= 4.1e+107) and (y <= 8.8e+134))))): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134)))))) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -1.5e+51) || ~(((y <= 2.3e-16) || (~((y <= 2400.0)) && ((y <= 7.5e+77) || (~((y <= 4.1e+107)) && (y <= 8.8e+134)))))))
tmp = 3.0 * (x * y);
else
tmp = -z;
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[y, -1.5e+51], N[Not[Or[LessEqual[y, 2.3e-16], And[N[Not[LessEqual[y, 2400.0]], $MachinePrecision], Or[LessEqual[y, 7.5e+77], And[N[Not[LessEqual[y, 4.1e+107]], $MachinePrecision], LessEqual[y, 8.8e+134]]]]]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+51} \lor \neg \left(y \leq 2.3 \cdot 10^{-16} \lor \neg \left(y \leq 2400\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 8.8 \cdot 10^{+134}\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.5e51 or 2.2999999999999999e-16 < y < 2400 or 7.49999999999999955e77 < y < 4.0999999999999999e107 or 8.8e134 < y Initial program 99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around inf 74.4%
if -1.5e51 < y < 2.2999999999999999e-16 or 2400 < y < 7.49999999999999955e77 or 4.0999999999999999e107 < y < 8.8e134Initial program 99.9%
Taylor expanded in x around 0 77.3%
mul-1-neg77.3%
Simplified77.3%
Final simplification76.1%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -1.9e+54)
(* 3.0 (* x y))
(if (or (<= y 1.4e-16)
(and (not (<= y 3000.0))
(or (<= y 7.5e+77)
(and (not (<= y 4.1e+107)) (<= y 1.32e+135)))))
(- z)
(* y (* x 3.0)))))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+54) {
tmp = 3.0 * (x * y);
} else if ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135))))) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
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 (y <= (-1.9d+54)) then
tmp = 3.0d0 * (x * y)
else if ((y <= 1.4d-16) .or. (.not. (y <= 3000.0d0)) .and. (y <= 7.5d+77) .or. (.not. (y <= 4.1d+107)) .and. (y <= 1.32d+135)) then
tmp = -z
else
tmp = y * (x * 3.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+54) {
tmp = 3.0 * (x * y);
} else if ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135))))) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if y <= -1.9e+54: tmp = 3.0 * (x * y) elif (y <= 1.4e-16) or (not (y <= 3000.0) and ((y <= 7.5e+77) or (not (y <= 4.1e+107) and (y <= 1.32e+135)))): tmp = -z else: tmp = y * (x * 3.0) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (y <= -1.9e+54) tmp = Float64(3.0 * Float64(x * y)); elseif ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135))))) tmp = Float64(-z); else tmp = Float64(y * Float64(x * 3.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -1.9e+54)
tmp = 3.0 * (x * y);
elseif ((y <= 1.4e-16) || (~((y <= 3000.0)) && ((y <= 7.5e+77) || (~((y <= 4.1e+107)) && (y <= 1.32e+135)))))
tmp = -z;
else
tmp = y * (x * 3.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -1.9e+54], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.4e-16], And[N[Not[LessEqual[y, 3000.0]], $MachinePrecision], Or[LessEqual[y, 7.5e+77], And[N[Not[LessEqual[y, 4.1e+107]], $MachinePrecision], LessEqual[y, 1.32e+135]]]]], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+54}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-16} \lor \neg \left(y \leq 3000\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 1.32 \cdot 10^{+135}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if y < -1.9000000000000001e54Initial program 99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around inf 60.7%
if -1.9000000000000001e54 < y < 1.4000000000000001e-16 or 3e3 < y < 7.49999999999999955e77 or 4.0999999999999999e107 < y < 1.32e135Initial program 99.9%
Taylor expanded in x around 0 77.3%
mul-1-neg77.3%
Simplified77.3%
if 1.4000000000000001e-16 < y < 3e3 or 7.49999999999999955e77 < y < 4.0999999999999999e107 or 1.32e135 < y Initial program 99.7%
Taylor expanded in x around 0 99.7%
*-commutative99.7%
fma-neg99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 89.8%
*-commutative89.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
Final simplification76.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - 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 * (x * y)) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - 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[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.8%
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 (- (* x (* 3.0 y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - 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 = (x * (3.0d0 * y)) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.9%
fma-neg99.9%
Simplified99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
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.8%
Taylor expanded in x around 0 57.1%
mul-1-neg57.1%
Simplified57.1%
Final simplification57.1%
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.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt44.3%
sqrt-unprod53.9%
sqr-neg53.9%
sqrt-unprod23.8%
add-sqr-sqrt43.3%
Applied egg-rr43.3%
Taylor expanded in y around 0 2.1%
Final simplification2.1%
(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 2023196
(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))