
(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 (fma (* x 3.0) y (- z)))
double code(double x, double y, double z) {
return fma((x * 3.0), y, -z);
}
function code(x, y, z) return fma(Float64(x * 3.0), y, Float64(-z)) end
code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] * y + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot 3, y, -z\right)
\end{array}
Initial program 99.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -5e+154)
(* (* y 3.0) x)
(if (<= t_0 4e-83) (- z) (* (* y x) 3.0)))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+154) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 4e-83) {
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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-5d+154)) then
tmp = (y * 3.0d0) * x
else if (t_0 <= 4d-83) 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 t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+154) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 4e-83) {
tmp = -z;
} else {
tmp = (y * x) * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -5e+154: tmp = (y * 3.0) * x elif t_0 <= 4e-83: tmp = -z else: tmp = (y * x) * 3.0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -5e+154) tmp = Float64(Float64(y * 3.0) * x); elseif (t_0 <= 4e-83) tmp = Float64(-z); else tmp = Float64(Float64(y * x) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -5e+154) tmp = (y * 3.0) * x; elseif (t_0 <= 4e-83) tmp = -z; else tmp = (y * x) * 3.0; 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, -5e+154], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 4e-83], (-z), N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-83}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -5.00000000000000004e154Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.2
Applied rewrites95.2%
Applied rewrites95.2%
if -5.00000000000000004e154 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.0000000000000001e-83Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6480.2
Applied rewrites80.2%
if 4.0000000000000001e-83 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.5
Applied rewrites75.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (<= t_0 -5e+154) (* (* y 3.0) x) (if (<= t_0 4e-83) (- z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+154) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 4e-83) {
tmp = -z;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-5d+154)) then
tmp = (y * 3.0d0) * x
else if (t_0 <= 4d-83) then
tmp = -z
else
tmp = t_0
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 <= -5e+154) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 4e-83) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -5e+154: tmp = (y * 3.0) * x elif t_0 <= 4e-83: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -5e+154) tmp = Float64(Float64(y * 3.0) * x); elseif (t_0 <= 4e-83) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -5e+154) tmp = (y * 3.0) * x; elseif (t_0 <= 4e-83) tmp = -z; else tmp = t_0; 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, -5e+154], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 4e-83], (-z), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-83}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -5.00000000000000004e154Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.2
Applied rewrites95.2%
Applied rewrites95.2%
if -5.00000000000000004e154 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.0000000000000001e-83Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6480.2
Applied rewrites80.2%
if 4.0000000000000001e-83 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.5
Applied rewrites75.5%
Applied rewrites75.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (<= t_0 -2.6e+152) t_0 (if (<= t_0 6.3e-74) (- z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2.6e+152) {
tmp = t_0;
} else if (t_0 <= 6.3e-74) {
tmp = -z;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-2.6d+152)) then
tmp = t_0
else if (t_0 <= 6.3d-74) then
tmp = -z
else
tmp = t_0
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 <= -2.6e+152) {
tmp = t_0;
} else if (t_0 <= 6.3e-74) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2.6e+152: tmp = t_0 elif t_0 <= 6.3e-74: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2.6e+152) tmp = t_0; elseif (t_0 <= 6.3e-74) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -2.6e+152) tmp = t_0; elseif (t_0 <= 6.3e-74) tmp = -z; else tmp = t_0; 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, -2.6e+152], t$95$0, If[LessEqual[t$95$0, 6.3e-74], (-z), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2.6 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 6.3 \cdot 10^{-74}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2.6000000000000001e152 or 6.30000000000000003e-74 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6481.7
Applied rewrites81.7%
Applied rewrites81.6%
if -2.6000000000000001e152 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 6.30000000000000003e-74Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6480.2
Applied rewrites80.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(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.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%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6447.5
Applied rewrites47.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 2024249
(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))