
(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 (* 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}
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.55e+169)
(and (not (<= x -2.8e+134))
(or (<= x -2.25e+105)
(not
(or (<= x -4e+93)
(and (not (<= x -1.1e+47))
(or (<= x 5e-266)
(and (not (<= x 6e-155)) (<= x 4.6e-26)))))))))
(* 3.0 (* x y))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+169) || (!(x <= -2.8e+134) && ((x <= -2.25e+105) || !((x <= -4e+93) || (!(x <= -1.1e+47) && ((x <= 5e-266) || (!(x <= 6e-155) && (x <= 4.6e-26)))))))) {
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 <= (-1.55d+169)) .or. (.not. (x <= (-2.8d+134))) .and. (x <= (-2.25d+105)) .or. (.not. (x <= (-4d+93)) .or. (.not. (x <= (-1.1d+47))) .and. (x <= 5d-266) .or. (.not. (x <= 6d-155)) .and. (x <= 4.6d-26))) 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 <= -1.55e+169) || (!(x <= -2.8e+134) && ((x <= -2.25e+105) || !((x <= -4e+93) || (!(x <= -1.1e+47) && ((x <= 5e-266) || (!(x <= 6e-155) && (x <= 4.6e-26)))))))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e+169) or (not (x <= -2.8e+134) and ((x <= -2.25e+105) or not ((x <= -4e+93) or (not (x <= -1.1e+47) and ((x <= 5e-266) or (not (x <= 6e-155) and (x <= 4.6e-26))))))): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e+169) || (!(x <= -2.8e+134) && ((x <= -2.25e+105) || !((x <= -4e+93) || (!(x <= -1.1e+47) && ((x <= 5e-266) || (!(x <= 6e-155) && (x <= 4.6e-26)))))))) 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 <= -1.55e+169) || (~((x <= -2.8e+134)) && ((x <= -2.25e+105) || ~(((x <= -4e+93) || (~((x <= -1.1e+47)) && ((x <= 5e-266) || (~((x <= 6e-155)) && (x <= 4.6e-26))))))))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e+169], And[N[Not[LessEqual[x, -2.8e+134]], $MachinePrecision], Or[LessEqual[x, -2.25e+105], N[Not[Or[LessEqual[x, -4e+93], And[N[Not[LessEqual[x, -1.1e+47]], $MachinePrecision], Or[LessEqual[x, 5e-266], And[N[Not[LessEqual[x, 6e-155]], $MachinePrecision], LessEqual[x, 4.6e-26]]]]]], $MachinePrecision]]]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+169} \lor \neg \left(x \leq -2.8 \cdot 10^{+134}\right) \land \left(x \leq -2.25 \cdot 10^{+105} \lor \neg \left(x \leq -4 \cdot 10^{+93} \lor \neg \left(x \leq -1.1 \cdot 10^{+47}\right) \land \left(x \leq 5 \cdot 10^{-266} \lor \neg \left(x \leq 6 \cdot 10^{-155}\right) \land x \leq 4.6 \cdot 10^{-26}\right)\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* 3.0 x)))) (if (<= t_0 -1e-22) (* 3.0 (* x y)) (if (<= t_0 5e+76) (- z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -1e-22) {
tmp = 3.0 * (x * y);
} else if (t_0 <= 5e+76) {
tmp = -z;
} else {
tmp = t_0;
}
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) :: tmp
t_0 = y * (3.0d0 * x)
if (t_0 <= (-1d-22)) then
tmp = 3.0d0 * (x * y)
else if (t_0 <= 5d+76) then
tmp = -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -1e-22) {
tmp = 3.0 * (x * y);
} else if (t_0 <= 5e+76) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (3.0 * x) tmp = 0 if t_0 <= -1e-22: tmp = 3.0 * (x * y) elif t_0 <= 5e+76: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(3.0 * x)) tmp = 0.0 if (t_0 <= -1e-22) tmp = Float64(3.0 * Float64(x * y)); elseif (t_0 <= 5e+76) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (3.0 * x); tmp = 0.0; if (t_0 <= -1e-22) tmp = 3.0 * (x * y); elseif (t_0 <= 5e+76) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-22], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+76], (-z), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(3 \cdot x\right)\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-22}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+76}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(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}
(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 2023348
(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))