
(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 (fma (* x 3.0) y (- z)))
assert(x < y);
double code(double x, double y, double z) {
return fma((x * 3.0), y, -z);
}
x, y = sort([x, y]) function code(x, y, z) return fma(Float64(x * 3.0), y, Float64(-z)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] * y + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(x \cdot 3, y, -z\right)
\end{array}
Initial program 99.8%
fma-neg99.8%
Simplified99.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 (<= x -1.7e-6) (not (<= x 8e-32))) (* 3.0 (* x y)) (- z)))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-6) || !(x <= 8e-32)) {
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 ((x <= (-1.7d-6)) .or. (.not. (x <= 8d-32))) 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 ((x <= -1.7e-6) || !(x <= 8e-32)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (x <= -1.7e-6) or not (x <= 8e-32): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-6) || !(x <= 8e-32)) 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 ((x <= -1.7e-6) || ~((x <= 8e-32)))
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[x, -1.7e-6], N[Not[LessEqual[x, 8e-32]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-6} \lor \neg \left(x \leq 8 \cdot 10^{-32}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.70000000000000003e-6 or 8.00000000000000045e-32 < x Initial program 99.8%
add-sqr-sqrt53.1%
associate-*r*53.1%
fma-neg53.1%
add-sqr-sqrt24.7%
sqrt-unprod43.1%
sqr-neg43.1%
sqrt-unprod21.1%
add-sqr-sqrt39.8%
Applied egg-rr39.8%
fma-udef39.8%
associate-*r*39.8%
add-sqr-sqrt72.1%
associate-*r*72.1%
flip3-+14.8%
*-commutative14.8%
associate-*r*14.7%
*-commutative14.7%
unpow-prod-down14.7%
pow314.7%
metadata-eval14.7%
metadata-eval14.7%
metadata-eval14.7%
fma-def14.7%
pow314.7%
*-commutative14.7%
metadata-eval14.7%
metadata-eval14.7%
Applied egg-rr14.8%
*-commutative14.8%
*-commutative14.8%
associate-*r*14.8%
distribute-rgt-out--14.8%
*-commutative14.8%
associate-*r*14.8%
Simplified14.8%
Taylor expanded in y around inf 72.6%
if -1.70000000000000003e-6 < x < 8.00000000000000045e-32Initial program 99.9%
Taylor expanded in x around 0 76.0%
mul-1-neg76.0%
Simplified76.0%
Final simplification74.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -1.8e-6) (* (* x 3.0) y) (if (<= x 3.1e-29) (- z) (* 3.0 (* x y)))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-6) {
tmp = (x * 3.0) * y;
} else if (x <= 3.1e-29) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 (x <= (-1.8d-6)) then
tmp = (x * 3.0d0) * y
else if (x <= 3.1d-29) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-6) {
tmp = (x * 3.0) * y;
} else if (x <= 3.1e-29) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if x <= -1.8e-6: tmp = (x * 3.0) * y elif x <= 3.1e-29: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (x <= -1.8e-6) tmp = Float64(Float64(x * 3.0) * y); elseif (x <= 3.1e-29) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -1.8e-6)
tmp = (x * 3.0) * y;
elseif (x <= 3.1e-29)
tmp = -z;
else
tmp = 3.0 * (x * y);
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[x, -1.8e-6], N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[x, 3.1e-29], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-6}:\\
\;\;\;\;\left(x \cdot 3\right) \cdot y\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-29}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -1.79999999999999992e-6Initial program 99.8%
add-sqr-sqrt53.6%
associate-*r*53.7%
fma-neg53.7%
add-sqr-sqrt26.9%
sqrt-unprod50.5%
sqr-neg50.5%
sqrt-unprod23.6%
add-sqr-sqrt46.2%
Applied egg-rr46.2%
fma-udef46.2%
associate-*r*46.2%
add-sqr-sqrt80.1%
associate-*r*80.1%
flip3-+14.1%
*-commutative14.1%
associate-*r*14.1%
*-commutative14.1%
unpow-prod-down14.0%
pow314.0%
metadata-eval14.0%
metadata-eval14.0%
metadata-eval14.0%
fma-def14.0%
pow314.0%
*-commutative14.0%
metadata-eval14.0%
metadata-eval14.0%
Applied egg-rr14.0%
*-commutative14.0%
*-commutative14.0%
associate-*r*14.0%
distribute-rgt-out--14.0%
*-commutative14.0%
associate-*r*14.0%
Simplified14.0%
Taylor expanded in y around inf 9.3%
cube-prod14.3%
Simplified14.3%
Taylor expanded in y around inf 80.6%
*-commutative80.6%
associate-*r*80.6%
Simplified80.6%
if -1.79999999999999992e-6 < x < 3.10000000000000026e-29Initial program 99.9%
Taylor expanded in x around 0 76.0%
mul-1-neg76.0%
Simplified76.0%
if 3.10000000000000026e-29 < x Initial program 99.9%
add-sqr-sqrt52.6%
associate-*r*52.5%
fma-neg52.5%
add-sqr-sqrt22.8%
sqrt-unprod36.8%
sqr-neg36.8%
sqrt-unprod18.9%
add-sqr-sqrt34.3%
Applied egg-rr34.3%
fma-udef34.3%
associate-*r*34.4%
add-sqr-sqrt65.3%
associate-*r*65.3%
flip3-+15.4%
*-commutative15.4%
associate-*r*15.3%
*-commutative15.3%
unpow-prod-down15.3%
pow315.3%
metadata-eval15.3%
metadata-eval15.3%
metadata-eval15.3%
fma-def15.3%
pow315.3%
*-commutative15.3%
metadata-eval15.3%
metadata-eval15.3%
Applied egg-rr15.4%
*-commutative15.4%
*-commutative15.4%
associate-*r*15.4%
distribute-rgt-out--15.4%
*-commutative15.4%
associate-*r*15.4%
Simplified15.4%
Taylor expanded in y around inf 65.8%
Final simplification74.2%
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 50.3%
mul-1-neg50.3%
Simplified50.3%
Final simplification50.3%
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%
add-sqr-sqrt49.4%
associate-*r*49.4%
fma-neg49.4%
add-sqr-sqrt22.5%
sqrt-unprod33.1%
sqr-neg33.1%
sqrt-unprod14.5%
add-sqr-sqrt27.0%
Applied egg-rr27.0%
Taylor expanded in x around 0 2.5%
Final simplification2.5%
(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 2023238
(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))