
(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 3 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 (* 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.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f6499.9
Simplified99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* 3.0 x))) (t_1 (* 3.0 (* x y)))) (if (<= t_0 -5e+25) t_1 (if (<= t_0 1e+83) (- z) t_1))))
double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double t_1 = 3.0 * (x * y);
double tmp;
if (t_0 <= -5e+25) {
tmp = t_1;
} else if (t_0 <= 1e+83) {
tmp = -z;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = y * (3.0d0 * x)
t_1 = 3.0d0 * (x * y)
if (t_0 <= (-5d+25)) then
tmp = t_1
else if (t_0 <= 1d+83) then
tmp = -z
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double t_1 = 3.0 * (x * y);
double tmp;
if (t_0 <= -5e+25) {
tmp = t_1;
} else if (t_0 <= 1e+83) {
tmp = -z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y * (3.0 * x) t_1 = 3.0 * (x * y) tmp = 0 if t_0 <= -5e+25: tmp = t_1 elif t_0 <= 1e+83: tmp = -z else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(3.0 * x)) t_1 = Float64(3.0 * Float64(x * y)) tmp = 0.0 if (t_0 <= -5e+25) tmp = t_1; elseif (t_0 <= 1e+83) tmp = Float64(-z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (3.0 * x); t_1 = 3.0 * (x * y); tmp = 0.0; if (t_0 <= -5e+25) tmp = t_1; elseif (t_0 <= 1e+83) tmp = -z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+25], t$95$1, If[LessEqual[t$95$0, 1e+83], (-z), t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(3 \cdot x\right)\\
t_1 := 3 \cdot \left(x \cdot y\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+83}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -5.00000000000000024e25 or 1.00000000000000003e83 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6486.3
Simplified86.3%
if -5.00000000000000024e25 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 1.00000000000000003e83Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6477.7
Simplified77.7%
Final simplification81.2%
(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.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6452.3
Simplified52.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 2024215
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))