
(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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.6e-8)
(not
(or (<= z -7.2e-120) (and (not (<= z -1.75e-139)) (<= z 1.02e-67)))))
(- z)
(* 3.0 (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e-8) || !((z <= -7.2e-120) || (!(z <= -1.75e-139) && (z <= 1.02e-67)))) {
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 ((z <= (-1.6d-8)) .or. (.not. (z <= (-7.2d-120)) .or. (.not. (z <= (-1.75d-139))) .and. (z <= 1.02d-67))) 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 ((z <= -1.6e-8) || !((z <= -7.2e-120) || (!(z <= -1.75e-139) && (z <= 1.02e-67)))) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.6e-8) or not ((z <= -7.2e-120) or (not (z <= -1.75e-139) and (z <= 1.02e-67))): tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.6e-8) || !((z <= -7.2e-120) || (!(z <= -1.75e-139) && (z <= 1.02e-67)))) 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 ((z <= -1.6e-8) || ~(((z <= -7.2e-120) || (~((z <= -1.75e-139)) && (z <= 1.02e-67))))) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.6e-8], N[Not[Or[LessEqual[z, -7.2e-120], And[N[Not[LessEqual[z, -1.75e-139]], $MachinePrecision], LessEqual[z, 1.02e-67]]]], $MachinePrecision]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{-8} \lor \neg \left(z \leq -7.2 \cdot 10^{-120} \lor \neg \left(z \leq -1.75 \cdot 10^{-139}\right) \land z \leq 1.02 \cdot 10^{-67}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.6000000000000001e-8 or -7.2000000000000005e-120 < z < -1.75000000000000001e-139 or 1.01999999999999993e-67 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
if -1.6000000000000001e-8 < z < -7.2000000000000005e-120 or -1.75000000000000001e-139 < z < 1.01999999999999993e-67Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 85.2%
Final simplification81.1%
(FPCore (x y z)
:precision binary64
(if (<= z -1.1e-8)
(- z)
(if (<= z -7.2e-120)
(* 3.0 (* x y))
(if (or (<= z -1.62e-139) (not (<= z 1.02e-67))) (- z) (* x (* 3.0 y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e-8) {
tmp = -z;
} else if (z <= -7.2e-120) {
tmp = 3.0 * (x * y);
} else if ((z <= -1.62e-139) || !(z <= 1.02e-67)) {
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 (z <= (-1.1d-8)) then
tmp = -z
else if (z <= (-7.2d-120)) then
tmp = 3.0d0 * (x * y)
else if ((z <= (-1.62d-139)) .or. (.not. (z <= 1.02d-67))) 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 (z <= -1.1e-8) {
tmp = -z;
} else if (z <= -7.2e-120) {
tmp = 3.0 * (x * y);
} else if ((z <= -1.62e-139) || !(z <= 1.02e-67)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e-8: tmp = -z elif z <= -7.2e-120: tmp = 3.0 * (x * y) elif (z <= -1.62e-139) or not (z <= 1.02e-67): tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e-8) tmp = Float64(-z); elseif (z <= -7.2e-120) tmp = Float64(3.0 * Float64(x * y)); elseif ((z <= -1.62e-139) || !(z <= 1.02e-67)) 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 (z <= -1.1e-8) tmp = -z; elseif (z <= -7.2e-120) tmp = 3.0 * (x * y); elseif ((z <= -1.62e-139) || ~((z <= 1.02e-67))) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e-8], (-z), If[LessEqual[z, -7.2e-120], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -1.62e-139], N[Not[LessEqual[z, 1.02e-67]], $MachinePrecision]], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-8}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -7.2 \cdot 10^{-120}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;z \leq -1.62 \cdot 10^{-139} \lor \neg \left(z \leq 1.02 \cdot 10^{-67}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if z < -1.0999999999999999e-8 or -7.2000000000000005e-120 < z < -1.62000000000000001e-139 or 1.01999999999999993e-67 < z Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
if -1.0999999999999999e-8 < z < -7.2000000000000005e-120Initial program 99.8%
associate-*l*99.4%
Simplified99.4%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 74.6%
if -1.62000000000000001e-139 < z < 1.01999999999999993e-67Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 88.1%
*-commutative88.1%
associate-*r*88.2%
Simplified88.2%
Final simplification81.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.8%
associate-*l*99.8%
Simplified99.8%
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.8%
associate-*l*99.8%
Simplified99.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.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 49.3%
mul-1-neg49.3%
Simplified49.3%
Final simplification49.3%
(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.8%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt50.1%
sqrt-unprod61.4%
sqr-neg61.4%
sqrt-unprod24.3%
add-sqr-sqrt50.8%
Applied egg-rr50.8%
Taylor expanded in y around 0 2.3%
Final simplification2.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}
herbie shell --seed 2024035
(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))