
(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.15e-29) (not (<= y 1.9e+43))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-29) || !(y <= 1.9e+43)) {
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.15d-29)) .or. (.not. (y <= 1.9d+43))) 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.15e-29) || !(y <= 1.9e+43)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e-29) or not (y <= 1.9e+43): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e-29) || !(y <= 1.9e+43)) 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.15e-29) || ~((y <= 1.9e+43))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e-29], N[Not[LessEqual[y, 1.9e+43]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-29} \lor \neg \left(y \leq 1.9 \cdot 10^{+43}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.14999999999999996e-29 or 1.90000000000000004e43 < 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 72.7%
if -1.14999999999999996e-29 < y < 1.90000000000000004e43Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.6%
neg-mul-170.6%
Simplified70.6%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e-20) (* 3.0 (* x y)) (if (<= y 1.8e+42) (- z) (* y (* x 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-20) {
tmp = 3.0 * (x * y);
} else if (y <= 1.8e+42) {
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.85d-20)) then
tmp = 3.0d0 * (x * y)
else if (y <= 1.8d+42) 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.85e-20) {
tmp = 3.0 * (x * y);
} else if (y <= 1.8e+42) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e-20: tmp = 3.0 * (x * y) elif y <= 1.8e+42: tmp = -z else: tmp = y * (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e-20) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 1.8e+42) 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.85e-20) tmp = 3.0 * (x * y); elseif (y <= 1.8e+42) tmp = -z; else tmp = y * (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e-20], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.8e+42], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-20}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if y < -1.85e-20Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 71.7%
if -1.85e-20 < y < 1.8e42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.1%
neg-mul-170.1%
Simplified70.1%
if 1.8e42 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 86.1%
clear-num86.0%
un-div-inv86.1%
Applied egg-rr86.1%
Taylor expanded in z around 0 73.3%
associate-*r*73.3%
Simplified73.3%
Final simplification71.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.5e-22) (* 3.0 (* x y)) (if (<= y 2e+42) (- z) (* x (* 3.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e-22) {
tmp = 3.0 * (x * y);
} else if (y <= 2e+42) {
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 <= (-1.5d-22)) then
tmp = 3.0d0 * (x * y)
else if (y <= 2d+42) 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 <= -1.5e-22) {
tmp = 3.0 * (x * y);
} else if (y <= 2e+42) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.5e-22: tmp = 3.0 * (x * y) elif y <= 2e+42: tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.5e-22) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 2e+42) 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 <= -1.5e-22) tmp = 3.0 * (x * y); elseif (y <= 2e+42) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.5e-22], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e+42], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-22}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if y < -1.5e-22Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 72.2%
if -1.5e-22 < y < 2.00000000000000009e42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.6%
neg-mul-170.6%
Simplified70.6%
if 2.00000000000000009e42 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 73.3%
*-commutative73.3%
associate-*l*73.3%
*-commutative73.3%
Simplified73.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}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
(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.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.8%
Simplified99.8%
Taylor expanded in x around 0 51.2%
neg-mul-151.2%
Simplified51.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 2024087
(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))