
(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}
(FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
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
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
def code(x, y, z): return (y * (x * 3.0)) - z
function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
function tmp = code(x, y, z) tmp = (y * (x * 3.0)) - z; end
code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -28000000000000.0) (not (<= x 2.8e-60))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -28000000000000.0) || !(x <= 2.8e-60)) {
tmp = 3.0 * (x * y);
} 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 <= (-28000000000000.0d0)) .or. (.not. (x <= 2.8d-60))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -28000000000000.0) || !(x <= 2.8e-60)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -28000000000000.0) or not (x <= 2.8e-60): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -28000000000000.0) || !(x <= 2.8e-60)) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -28000000000000.0) || ~((x <= 2.8e-60))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -28000000000000.0], N[Not[LessEqual[x, 2.8e-60]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -28000000000000 \lor \neg \left(x \leq 2.8 \cdot 10^{-60}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.8e13 or 2.8000000000000002e-60 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 79.3%
if -2.8e13 < x < 2.8000000000000002e-60Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 76.4%
mul-1-neg76.4%
Simplified76.4%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e+14) (not (<= x 2.5e-60))) (* x (* 3.0 y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e+14) || !(x <= 2.5e-60)) {
tmp = x * (3.0 * y);
} 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 <= (-1d+14)) .or. (.not. (x <= 2.5d-60))) then
tmp = x * (3.0d0 * y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1e+14) || !(x <= 2.5e-60)) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e+14) or not (x <= 2.5e-60): tmp = x * (3.0 * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e+14) || !(x <= 2.5e-60)) tmp = Float64(x * Float64(3.0 * y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1e+14) || ~((x <= 2.5e-60))) tmp = x * (3.0 * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e+14], N[Not[LessEqual[x, 2.5e-60]], $MachinePrecision]], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+14} \lor \neg \left(x \leq 2.5 \cdot 10^{-60}\right):\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1e14 or 2.5000000000000001e-60 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 79.3%
associate-*r*79.4%
*-commutative79.4%
associate-*r*79.3%
Simplified79.3%
if -1e14 < x < 2.5000000000000001e-60Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 76.4%
mul-1-neg76.4%
Simplified76.4%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+14) (* y (* x 3.0)) (if (<= x 2.8e-60) (- z) (* x (* 3.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+14) {
tmp = y * (x * 3.0);
} else if (x <= 2.8e-60) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
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.1d+14)) then
tmp = y * (x * 3.0d0)
else if (x <= 2.8d-60) then
tmp = -z
else
tmp = x * (3.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+14) {
tmp = y * (x * 3.0);
} else if (x <= 2.8e-60) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e+14: tmp = y * (x * 3.0) elif x <= 2.8e-60: tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+14) tmp = Float64(y * Float64(x * 3.0)); elseif (x <= 2.8e-60) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e+14) tmp = y * (x * 3.0); elseif (x <= 2.8e-60) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+14], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.8e-60], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+14}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-60}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if x < -1.1e14Initial program 100.0%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around inf 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in x around inf 83.0%
associate-*r*83.2%
Simplified83.2%
if -1.1e14 < x < 2.8000000000000002e-60Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 76.4%
mul-1-neg76.4%
Simplified76.4%
if 2.8000000000000002e-60 < x Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 77.5%
associate-*r*77.6%
*-commutative77.6%
associate-*r*77.5%
Simplified77.5%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
double code(double x, double y, double z) {
return (3.0 * (x * 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 = (3.0d0 * (x * y)) - z
end function
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
def code(x, y, z): return (3.0 * (x * y)) - z
function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
function tmp = code(x, y, z) tmp = (3.0 * (x * y)) - z; end
code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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}
Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(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%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 50.9%
mul-1-neg50.9%
Simplified50.9%
Final simplification50.9%
(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 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%
associate-*l*99.9%
Simplified99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*r*99.8%
fmm-def99.8%
add-sqr-sqrt46.6%
sqrt-unprod60.3%
sqr-neg60.3%
sqrt-unprod27.5%
add-sqr-sqrt50.5%
Applied egg-rr50.5%
Taylor expanded in y around 0 2.4%
Final simplification2.4%
(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 2024130
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))