
(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 7 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 (- (* (* 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.8e+44)
(and (not (<= x -1.8e+20))
(or (<= x -7.5e-10) (not (<= x 3.6e-109)))))
(* 3.0 (* x y))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.8e+44) || (!(x <= -1.8e+20) && ((x <= -7.5e-10) || !(x <= 3.6e-109)))) {
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.8d+44)) .or. (.not. (x <= (-1.8d+20))) .and. (x <= (-7.5d-10)) .or. (.not. (x <= 3.6d-109))) 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.8e+44) || (!(x <= -1.8e+20) && ((x <= -7.5e-10) || !(x <= 3.6e-109)))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.8e+44) or (not (x <= -1.8e+20) and ((x <= -7.5e-10) or not (x <= 3.6e-109))): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.8e+44) || (!(x <= -1.8e+20) && ((x <= -7.5e-10) || !(x <= 3.6e-109)))) 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.8e+44) || (~((x <= -1.8e+20)) && ((x <= -7.5e-10) || ~((x <= 3.6e-109))))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.8e+44], And[N[Not[LessEqual[x, -1.8e+20]], $MachinePrecision], Or[LessEqual[x, -7.5e-10], N[Not[LessEqual[x, 3.6e-109]], $MachinePrecision]]]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+44} \lor \neg \left(x \leq -1.8 \cdot 10^{+20}\right) \land \left(x \leq -7.5 \cdot 10^{-10} \lor \neg \left(x \leq 3.6 \cdot 10^{-109}\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.8e44 or -1.8e20 < x < -7.49999999999999995e-10 or 3.6000000000000001e-109 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 68.2%
if -1.8e44 < x < -1.8e20 or -7.49999999999999995e-10 < x < 3.6000000000000001e-109Initial program 99.9%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
Simplified80.0%
Final simplification73.7%
(FPCore (x y z)
:precision binary64
(if (<= x -4.8e+44)
(* x (* 3.0 y))
(if (or (<= x -8.2e+20) (and (not (<= x -1.45e-11)) (<= x 8e-106)))
(- z)
(* 3.0 (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+44) {
tmp = x * (3.0 * y);
} else if ((x <= -8.2e+20) || (!(x <= -1.45e-11) && (x <= 8e-106))) {
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.8d+44)) then
tmp = x * (3.0d0 * y)
else if ((x <= (-8.2d+20)) .or. (.not. (x <= (-1.45d-11))) .and. (x <= 8d-106)) 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.8e+44) {
tmp = x * (3.0 * y);
} else if ((x <= -8.2e+20) || (!(x <= -1.45e-11) && (x <= 8e-106))) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e+44: tmp = x * (3.0 * y) elif (x <= -8.2e+20) or (not (x <= -1.45e-11) and (x <= 8e-106)): tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+44) tmp = Float64(x * Float64(3.0 * y)); elseif ((x <= -8.2e+20) || (!(x <= -1.45e-11) && (x <= 8e-106))) 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.8e+44) tmp = x * (3.0 * y); elseif ((x <= -8.2e+20) || (~((x <= -1.45e-11)) && (x <= 8e-106))) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+44], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -8.2e+20], And[N[Not[LessEqual[x, -1.45e-11]], $MachinePrecision], LessEqual[x, 8e-106]]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+44}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{+20} \lor \neg \left(x \leq -1.45 \cdot 10^{-11}\right) \land x \leq 8 \cdot 10^{-106}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -4.80000000000000026e44Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.1%
*-commutative75.1%
associate-*r*75.2%
Simplified75.2%
if -4.80000000000000026e44 < x < -8.2e20 or -1.45e-11 < x < 7.99999999999999953e-106Initial program 99.9%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
Simplified80.0%
if -8.2e20 < x < -1.45e-11 or 7.99999999999999953e-106 < x Initial program 99.9%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 64.2%
Final simplification73.7%
(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 55.1%
neg-mul-155.1%
Simplified55.1%
Final simplification55.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.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
*-commutative99.8%
fma-neg99.8%
add-sqr-sqrt47.3%
sqrt-unprod57.3%
sqr-neg57.3%
sqrt-unprod22.4%
add-sqr-sqrt45.4%
Applied egg-rr45.4%
Taylor expanded in x around 0 2.1%
Final simplification2.1%
(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 2024067
(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))