
(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 4 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}
(FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
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
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
def code(x, y, z): return (3.0 * (y * x)) - z
function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
function tmp = code(x, y, z) tmp = (3.0 * (y * x)) - z; end
code[x_, y_, z_] := N[(N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot x\right) - z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.35e+89) (not (<= x 1.9e-139))) (* 3.0 (* y x)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e+89) || !(x <= 1.9e-139)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
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.35d+89)) .or. (.not. (x <= 1.9d-139))) then
tmp = 3.0d0 * (y * x)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e+89) || !(x <= 1.9e-139)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.35e+89) or not (x <= 1.9e-139): tmp = 3.0 * (y * x) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.35e+89) || !(x <= 1.9e-139)) tmp = Float64(3.0 * Float64(y * x)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.35e+89) || ~((x <= 1.9e-139))) tmp = 3.0 * (y * x); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.35e+89], N[Not[LessEqual[x, 1.9e-139]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+89} \lor \neg \left(x \leq 1.9 \cdot 10^{-139}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.35e89 or 1.90000000000000004e-139 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around inf 69.9%
if -1.35e89 < x < 1.90000000000000004e-139Initial program 99.9%
Taylor expanded in x around 0 70.1%
mul-1-neg70.1%
Simplified70.1%
Final simplification70.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.24e+89) (* y (* 3.0 x)) (if (<= x 2.1e-141) (- z) (* 3.0 (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.24e+89) {
tmp = y * (3.0 * x);
} else if (x <= 2.1e-141) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
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.24d+89)) then
tmp = y * (3.0d0 * x)
else if (x <= 2.1d-141) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.24e+89) {
tmp = y * (3.0 * x);
} else if (x <= 2.1e-141) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.24e+89: tmp = y * (3.0 * x) elif x <= 2.1e-141: tmp = -z else: tmp = 3.0 * (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.24e+89) tmp = Float64(y * Float64(3.0 * x)); elseif (x <= 2.1e-141) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.24e+89) tmp = y * (3.0 * x); elseif (x <= 2.1e-141) tmp = -z; else tmp = 3.0 * (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.24e+89], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e-141], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.24 \cdot 10^{+89}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-141}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if x < -1.2400000000000001e89Initial program 99.9%
Taylor expanded in x around 0 99.8%
*-commutative99.8%
add-cube-cbrt98.8%
associate-*l*98.8%
fma-neg98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in z around 0 78.6%
pow-base-178.6%
*-lft-identity78.6%
*-commutative78.6%
associate-*l*78.7%
*-commutative78.7%
Simplified78.7%
if -1.2400000000000001e89 < x < 2.0999999999999999e-141Initial program 99.9%
Taylor expanded in x around 0 70.1%
mul-1-neg70.1%
Simplified70.1%
if 2.0999999999999999e-141 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around inf 65.1%
Final simplification70.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
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
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 50.7%
mul-1-neg50.7%
Simplified50.7%
Final simplification50.7%
(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 2023185
(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))