
(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 6 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 -6.2e-63)
(not
(or (<= y 28000000000000.0)
(and (not (<= y 8.6e+56)) (<= y 7.5e+108)))))
(* 3.0 (* x y))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-63) || !((y <= 28000000000000.0) || (!(y <= 8.6e+56) && (y <= 7.5e+108)))) {
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 <= (-6.2d-63)) .or. (.not. (y <= 28000000000000.0d0) .or. (.not. (y <= 8.6d+56)) .and. (y <= 7.5d+108))) 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 <= -6.2e-63) || !((y <= 28000000000000.0) || (!(y <= 8.6e+56) && (y <= 7.5e+108)))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-63) or not ((y <= 28000000000000.0) or (not (y <= 8.6e+56) and (y <= 7.5e+108))): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-63) || !((y <= 28000000000000.0) || (!(y <= 8.6e+56) && (y <= 7.5e+108)))) 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 <= -6.2e-63) || ~(((y <= 28000000000000.0) || (~((y <= 8.6e+56)) && (y <= 7.5e+108))))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-63], N[Not[Or[LessEqual[y, 28000000000000.0], And[N[Not[LessEqual[y, 8.6e+56]], $MachinePrecision], LessEqual[y, 7.5e+108]]]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-63} \lor \neg \left(y \leq 28000000000000 \lor \neg \left(y \leq 8.6 \cdot 10^{+56}\right) \land y \leq 7.5 \cdot 10^{+108}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -6.19999999999999968e-63 or 2.8e13 < y < 8.6000000000000007e56 or 7.50000000000000039e108 < y Initial program 99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around inf 73.1%
if -6.19999999999999968e-63 < y < 2.8e13 or 8.6000000000000007e56 < y < 7.50000000000000039e108Initial program 99.9%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification74.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* x 3.0))))
(if (<= y -5.8e-63)
t_0
(if (<= y 3.5e+14)
(- z)
(if (<= y 8.4e+57) t_0 (if (<= y 8e+108) (- z) (* 3.0 (* x y))))))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (y <= -5.8e-63) {
tmp = t_0;
} else if (y <= 3.5e+14) {
tmp = -z;
} else if (y <= 8.4e+57) {
tmp = t_0;
} else if (y <= 8e+108) {
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) :: t_0
real(8) :: tmp
t_0 = y * (x * 3.0d0)
if (y <= (-5.8d-63)) then
tmp = t_0
else if (y <= 3.5d+14) then
tmp = -z
else if (y <= 8.4d+57) then
tmp = t_0
else if (y <= 8d+108) 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 t_0 = y * (x * 3.0);
double tmp;
if (y <= -5.8e-63) {
tmp = t_0;
} else if (y <= 3.5e+14) {
tmp = -z;
} else if (y <= 8.4e+57) {
tmp = t_0;
} else if (y <= 8e+108) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) tmp = 0 if y <= -5.8e-63: tmp = t_0 elif y <= 3.5e+14: tmp = -z elif y <= 8.4e+57: tmp = t_0 elif y <= 8e+108: tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) tmp = 0.0 if (y <= -5.8e-63) tmp = t_0; elseif (y <= 3.5e+14) tmp = Float64(-z); elseif (y <= 8.4e+57) tmp = t_0; elseif (y <= 8e+108) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); tmp = 0.0; if (y <= -5.8e-63) tmp = t_0; elseif (y <= 3.5e+14) tmp = -z; elseif (y <= 8.4e+57) tmp = t_0; elseif (y <= 8e+108) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.8e-63], t$95$0, If[LessEqual[y, 3.5e+14], (-z), If[LessEqual[y, 8.4e+57], t$95$0, If[LessEqual[y, 8e+108], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
\mathbf{if}\;y \leq -5.8 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+14}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 8.4 \cdot 10^{+57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+108}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -5.7999999999999995e-63 or 3.5e14 < y < 8.39999999999999964e57Initial program 99.9%
Taylor expanded in x around 0 99.8%
sub-neg99.8%
associate-*r*99.9%
*-commutative99.9%
+-commutative99.9%
add-sqr-sqrt55.0%
distribute-rgt-neg-in55.0%
flip-+21.5%
Applied egg-rr17.3%
unpow217.3%
swap-sqr17.3%
metadata-eval17.3%
unpow217.3%
*-commutative17.3%
sub-neg17.3%
*-commutative17.3%
distribute-rgt-neg-in17.3%
metadata-eval17.3%
Simplified17.3%
Taylor expanded in z around 0 60.9%
associate-*r*60.9%
*-commutative60.9%
Simplified60.9%
Taylor expanded in y around 0 60.9%
associate-*r*60.9%
*-commutative60.9%
associate-*l*60.9%
Simplified60.9%
if -5.7999999999999995e-63 < y < 3.5e14 or 8.39999999999999964e57 < y < 8.0000000000000003e108Initial program 99.9%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
if 8.0000000000000003e108 < y Initial program 99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around inf 91.8%
Final simplification74.2%
(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%
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%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
Simplified52.1%
Final simplification52.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%
*-commutative99.9%
associate-*r*99.8%
fma-neg99.9%
add-sqr-sqrt48.9%
sqrt-unprod60.5%
sqr-neg60.5%
sqrt-unprod26.2%
add-sqr-sqrt48.3%
Applied egg-rr48.3%
Taylor expanded in y around 0 2.0%
Final simplification2.0%
(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 2023182
(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))