
(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 (fma (* y 3.0) x (- z)))
double code(double x, double y, double z) {
return fma((y * 3.0), x, -z);
}
function code(x, y, z) return fma(Float64(y * 3.0), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y * 3.0), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot 3, x, -z\right)
\end{array}
Initial program 99.4%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (or (<= t_0 -2e+75) (not (<= t_0 1e-14))) (* (* 3.0 y) x) (- z))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -2e+75) || !(t_0 <= 1e-14)) {
tmp = (3.0 * y) * x;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if ((t_0 <= (-2d+75)) .or. (.not. (t_0 <= 1d-14))) then
tmp = (3.0d0 * y) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -2e+75) || !(t_0 <= 1e-14)) {
tmp = (3.0 * y) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if (t_0 <= -2e+75) or not (t_0 <= 1e-14): tmp = (3.0 * y) * x else: tmp = -z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if ((t_0 <= -2e+75) || !(t_0 <= 1e-14)) tmp = Float64(Float64(3.0 * y) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if ((t_0 <= -2e+75) || ~((t_0 <= 1e-14))) tmp = (3.0 * y) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+75], N[Not[LessEqual[t$95$0, 1e-14]], $MachinePrecision]], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75} \lor \neg \left(t\_0 \leq 10^{-14}\right):\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999985e75 or 9.99999999999999999e-15 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.0%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites32.1%
Taylor expanded in x around 0
Applied rewrites31.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6485.4
Applied rewrites85.4%
Applied rewrites85.5%
if -1.99999999999999985e75 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999999e-15Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
Final simplification80.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -2e+75)
(* (* 3.0 x) y)
(if (<= t_0 1e-14) (- z) (* (* 3.0 y) x)))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+75) {
tmp = (3.0 * x) * y;
} else if (t_0 <= 1e-14) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
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 = (x * 3.0d0) * y
if (t_0 <= (-2d+75)) then
tmp = (3.0d0 * x) * y
else if (t_0 <= 1d-14) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+75) {
tmp = (3.0 * x) * y;
} else if (t_0 <= 1e-14) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2e+75: tmp = (3.0 * x) * y elif t_0 <= 1e-14: tmp = -z else: tmp = (3.0 * y) * x return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2e+75) tmp = Float64(Float64(3.0 * x) * y); elseif (t_0 <= 1e-14) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -2e+75) tmp = (3.0 * x) * y; elseif (t_0 <= 1e-14) tmp = -z; else tmp = (3.0 * y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+75], N[(N[(3.0 * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 1e-14], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75}:\\
\;\;\;\;\left(3 \cdot x\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 10^{-14}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999985e75Initial program 99.7%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lift-neg.f64N/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
neg-sub0N/A
distribute-neg-fracN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
neg-sub0N/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
Applied rewrites90.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-fma.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
Taylor expanded in x around inf
Applied rewrites90.8%
if -1.99999999999999985e75 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999999e-15Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
if 9.99999999999999999e-15 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 98.5%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites35.6%
Taylor expanded in x around 0
Applied rewrites35.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6481.5
Applied rewrites81.5%
Applied rewrites81.6%
(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(Float64(y * x) * 3.0) - z) end
function tmp = code(x, y, z) tmp = ((y * x) * 3.0) - z; end
code[x_, y_, z_] := N[(N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot x\right) \cdot 3 - z
\end{array}
Initial program 99.4%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.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(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.4%
(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.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6445.3
Applied rewrites45.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.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6445.3
Applied rewrites45.3%
Applied rewrites2.5%
(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 2024313
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))