
(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 (- (* 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 (<= y -1.22e-114) (not (<= y 7.6e+46))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.22e-114) || !(y <= 7.6e+46)) {
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 ((y <= (-1.22d-114)) .or. (.not. (y <= 7.6d+46))) 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 ((y <= -1.22e-114) || !(y <= 7.6e+46)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.22e-114) or not (y <= 7.6e+46): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.22e-114) || !(y <= 7.6e+46)) 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 ((y <= -1.22e-114) || ~((y <= 7.6e+46))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.22e-114], N[Not[LessEqual[y, 7.6e+46]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.22 \cdot 10^{-114} \lor \neg \left(y \leq 7.6 \cdot 10^{+46}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.22e-114 or 7.5999999999999998e46 < y Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 63.2%
if -1.22e-114 < y < 7.5999999999999998e46Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 60.6%
neg-mul-160.6%
Simplified60.6%
Final simplification62.1%
(FPCore (x y z) :precision binary64 (if (<= y -3.6e-115) (* 3.0 (* x y)) (if (<= y 7.6e+46) (- z) (* x (* 3.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e-115) {
tmp = 3.0 * (x * y);
} else if (y <= 7.6e+46) {
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 (y <= (-3.6d-115)) then
tmp = 3.0d0 * (x * y)
else if (y <= 7.6d+46) 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 (y <= -3.6e-115) {
tmp = 3.0 * (x * y);
} else if (y <= 7.6e+46) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.6e-115: tmp = 3.0 * (x * y) elif y <= 7.6e+46: tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.6e-115) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 7.6e+46) 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 (y <= -3.6e-115) tmp = 3.0 * (x * y); elseif (y <= 7.6e+46) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.6e-115], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.6e+46], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-115}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+46}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if y < -3.60000000000000009e-115Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 55.4%
if -3.60000000000000009e-115 < y < 7.5999999999999998e46Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 60.6%
neg-mul-160.6%
Simplified60.6%
if 7.5999999999999998e46 < y Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.8%
associate-*r*75.9%
*-commutative75.9%
associate-*r*75.8%
Simplified75.8%
Final simplification62.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.22e-114) (* 3.0 (* x y)) (if (<= y 7.6e+46) (- z) (* y (* x 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.22e-114) {
tmp = 3.0 * (x * y);
} else if (y <= 7.6e+46) {
tmp = -z;
} else {
tmp = y * (x * 3.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) :: tmp
if (y <= (-1.22d-114)) then
tmp = 3.0d0 * (x * y)
else if (y <= 7.6d+46) then
tmp = -z
else
tmp = y * (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.22e-114) {
tmp = 3.0 * (x * y);
} else if (y <= 7.6e+46) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.22e-114: tmp = 3.0 * (x * y) elif y <= 7.6e+46: tmp = -z else: tmp = y * (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.22e-114) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 7.6e+46) tmp = Float64(-z); else tmp = Float64(y * Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.22e-114) tmp = 3.0 * (x * y); elseif (y <= 7.6e+46) tmp = -z; else tmp = y * (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.22e-114], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.6e+46], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.22 \cdot 10^{-114}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+46}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if y < -1.22e-114Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 55.4%
if -1.22e-114 < y < 7.5999999999999998e46Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 60.6%
neg-mul-160.6%
Simplified60.6%
if 7.5999999999999998e46 < y Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 75.8%
*-commutative75.8%
*-commutative75.8%
associate-*l*75.9%
add-cube-cbrt75.2%
unpow275.2%
associate-*r*75.3%
pow-to-exp73.0%
add-exp-log32.0%
prod-exp31.9%
rem-log-exp31.9%
pow-to-exp31.9%
unpow231.9%
cbrt-unprod20.0%
pow220.0%
*-commutative20.0%
*-commutative20.0%
associate-*l*20.0%
Applied egg-rr20.0%
exp-sum20.0%
rem-exp-log20.0%
rem-exp-log49.6%
Simplified49.6%
Taylor expanded in y around 0 75.8%
associate-*r*75.9%
*-commutative75.9%
Simplified75.9%
Final simplification62.1%
(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.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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.8%
Simplified99.8%
Taylor expanded in x around 0 47.9%
neg-mul-147.9%
Simplified47.9%
Final simplification47.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.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
*-commutative99.8%
fma-neg99.8%
add-sqr-sqrt49.7%
sqrt-unprod62.9%
sqr-neg62.9%
sqrt-prod27.3%
add-sqr-sqrt52.8%
Applied egg-rr52.8%
Taylor expanded in x 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 2024020
(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))