
(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 6 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.9%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e+58) (not (<= x 6.1e-6))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e+58) || !(x <= 6.1e-6)) {
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 <= (-6.5d+58)) .or. (.not. (x <= 6.1d-6))) 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 <= -6.5e+58) || !(x <= 6.1e-6)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e+58) or not (x <= 6.1e-6): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e+58) || !(x <= 6.1e-6)) 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 <= -6.5e+58) || ~((x <= 6.1e-6))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e+58], N[Not[LessEqual[x, 6.1e-6]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+58} \lor \neg \left(x \leq 6.1 \cdot 10^{-6}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.49999999999999998e58 or 6.10000000000000004e-6 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 73.0%
if -6.49999999999999998e58 < x < 6.10000000000000004e-6Initial program 99.9%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 73.1%
neg-mul-173.1%
Simplified73.1%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= x -4.8e+58) (* x (* 3.0 y)) (if (<= x 650.0) (- z) (* y (* 3.0 x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+58) {
tmp = x * (3.0 * y);
} else if (x <= 650.0) {
tmp = -z;
} else {
tmp = y * (3.0 * 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 <= (-4.8d+58)) then
tmp = x * (3.0d0 * y)
else if (x <= 650.0d0) then
tmp = -z
else
tmp = y * (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+58) {
tmp = x * (3.0 * y);
} else if (x <= 650.0) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e+58: tmp = x * (3.0 * y) elif x <= 650.0: tmp = -z else: tmp = y * (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+58) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 650.0) tmp = Float64(-z); else tmp = Float64(y * Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e+58) tmp = x * (3.0 * y); elseif (x <= 650.0) tmp = -z; else tmp = y * (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+58], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 650.0], (-z), N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+58}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 650:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if x < -4.8e58Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 74.8%
associate-*r*74.8%
*-commutative74.8%
associate-*r*74.8%
Simplified74.8%
if -4.8e58 < x < 650Initial program 99.9%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 73.5%
neg-mul-173.5%
Simplified73.5%
if 650 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 89.5%
clear-num89.5%
associate-/r/89.4%
Applied egg-rr89.4%
Taylor expanded in z around 0 73.4%
associate-*r*73.5%
Simplified73.5%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= x -4.3e+58) (* x (* 3.0 y)) (if (<= x 2.4e-7) (- z) (* 3.0 (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+58) {
tmp = x * (3.0 * y);
} else if (x <= 2.4e-7) {
tmp = -z;
} else {
tmp = 3.0 * (x * 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 <= (-4.3d+58)) then
tmp = x * (3.0d0 * y)
else if (x <= 2.4d-7) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+58) {
tmp = x * (3.0 * y);
} else if (x <= 2.4e-7) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.3e+58: tmp = x * (3.0 * y) elif x <= 2.4e-7: tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.3e+58) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 2.4e-7) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.3e+58) tmp = x * (3.0 * y); elseif (x <= 2.4e-7) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.3e+58], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.4e-7], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+58}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-7}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -4.29999999999999991e58Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 74.8%
associate-*r*74.8%
*-commutative74.8%
associate-*r*74.8%
Simplified74.8%
if -4.29999999999999991e58 < x < 2.39999999999999979e-7Initial program 99.9%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in x around 0 73.1%
neg-mul-173.1%
Simplified73.1%
if 2.39999999999999979e-7 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 71.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%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 52.1%
neg-mul-152.1%
Simplified52.1%
(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.5%
Simplified99.5%
Taylor expanded in x around 0 52.1%
neg-mul-152.1%
Simplified52.1%
neg-sub052.1%
sub-neg52.1%
add-sqr-sqrt26.6%
sqrt-unprod18.5%
sqr-neg18.5%
sqrt-unprod1.1%
add-sqr-sqrt2.2%
Applied egg-rr2.2%
+-lft-identity2.2%
Simplified2.2%
(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 2024138
(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))