
(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(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.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* x 3.0))) (t_1 (* x (* 3.0 y))))
(if (<= t_0 -5e+48)
t_1
(if (<= t_0 6e-45)
(- z)
(if (<= t_0 4.0) t_1 (if (<= t_0 2e+76) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double t_1 = x * (3.0 * y);
double tmp;
if (t_0 <= -5e+48) {
tmp = t_1;
} else if (t_0 <= 6e-45) {
tmp = -z;
} else if (t_0 <= 4.0) {
tmp = t_1;
} else if (t_0 <= 2e+76) {
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) :: t_1
real(8) :: tmp
t_0 = y * (x * 3.0d0)
t_1 = x * (3.0d0 * y)
if (t_0 <= (-5d+48)) then
tmp = t_1
else if (t_0 <= 6d-45) then
tmp = -z
else if (t_0 <= 4.0d0) then
tmp = t_1
else if (t_0 <= 2d+76) 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 = y * (x * 3.0);
double t_1 = x * (3.0 * y);
double tmp;
if (t_0 <= -5e+48) {
tmp = t_1;
} else if (t_0 <= 6e-45) {
tmp = -z;
} else if (t_0 <= 4.0) {
tmp = t_1;
} else if (t_0 <= 2e+76) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) t_1 = x * (3.0 * y) tmp = 0 if t_0 <= -5e+48: tmp = t_1 elif t_0 <= 6e-45: tmp = -z elif t_0 <= 4.0: tmp = t_1 elif t_0 <= 2e+76: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) t_1 = Float64(x * Float64(3.0 * y)) tmp = 0.0 if (t_0 <= -5e+48) tmp = t_1; elseif (t_0 <= 6e-45) tmp = Float64(-z); elseif (t_0 <= 4.0) tmp = t_1; elseif (t_0 <= 2e+76) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); t_1 = x * (3.0 * y); tmp = 0.0; if (t_0 <= -5e+48) tmp = t_1; elseif (t_0 <= 6e-45) tmp = -z; elseif (t_0 <= 4.0) tmp = t_1; elseif (t_0 <= 2e+76) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+48], t$95$1, If[LessEqual[t$95$0, 6e-45], (-z), If[LessEqual[t$95$0, 4.0], t$95$1, If[LessEqual[t$95$0, 2e+76], (-z), t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
t_1 := x \cdot \left(3 \cdot y\right)\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+48}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 6 \cdot 10^{-45}:\\
\;\;\;\;-z\\
\mathbf{elif}\;t_0 \leq 4:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+76}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 x 3) y) < -4.99999999999999973e48 or 6.00000000000000022e-45 < (*.f64 (*.f64 x 3) y) < 4Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
add-cube-cbrt98.3%
pow398.3%
Applied egg-rr98.3%
Taylor expanded in z around 0 82.2%
*-commutative82.2%
pow-base-182.2%
*-lft-identity82.2%
rem-square-sqrt81.6%
unpow281.6%
associate-*r*81.6%
unpow281.6%
rem-square-sqrt82.3%
Simplified82.3%
if -4.99999999999999973e48 < (*.f64 (*.f64 x 3) y) < 6.00000000000000022e-45 or 4 < (*.f64 (*.f64 x 3) y) < 2.0000000000000001e76Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if 2.0000000000000001e76 < (*.f64 (*.f64 x 3) y) Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
add-cube-cbrt98.7%
pow398.6%
Applied egg-rr98.6%
Taylor expanded in z around 0 85.5%
pow-base-185.5%
*-lft-identity85.5%
associate-*r*85.7%
*-commutative85.7%
Simplified85.7%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e+88) (not (<= x 6.8e-64))) (* 3.0 (* x y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+88) || !(x <= 6.8e-64)) {
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 ((x <= (-3.9d+88)) .or. (.not. (x <= 6.8d-64))) 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 ((x <= -3.9e+88) || !(x <= 6.8e-64)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e+88) or not (x <= 6.8e-64): tmp = 3.0 * (x * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e+88) || !(x <= 6.8e-64)) 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 ((x <= -3.9e+88) || ~((x <= 6.8e-64))) tmp = 3.0 * (x * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e+88], N[Not[LessEqual[x, 6.8e-64]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+88} \lor \neg \left(x \leq 6.8 \cdot 10^{-64}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.9000000000000001e88 or 6.80000000000000024e-64 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
*-commutative99.8%
add-sqr-sqrt54.8%
associate-*r*54.9%
fma-neg54.9%
Applied egg-rr54.9%
Taylor expanded in y around inf 68.4%
if -3.9000000000000001e88 < x < 6.80000000000000024e-64Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 69.3%
neg-mul-169.3%
Simplified69.3%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e+74) (not (<= x 1.4e-63))) (* x (* 3.0 y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e+74) || !(x <= 1.4e-63)) {
tmp = x * (3.0 * 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 ((x <= (-4.2d+74)) .or. (.not. (x <= 1.4d-63))) then
tmp = x * (3.0d0 * y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e+74) || !(x <= 1.4e-63)) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e+74) or not (x <= 1.4e-63): tmp = x * (3.0 * y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e+74) || !(x <= 1.4e-63)) tmp = Float64(x * Float64(3.0 * y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.2e+74) || ~((x <= 1.4e-63))) tmp = x * (3.0 * y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e+74], N[Not[LessEqual[x, 1.4e-63]], $MachinePrecision]], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+74} \lor \neg \left(x \leq 1.4 \cdot 10^{-63}\right):\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.1999999999999998e74 or 1.4000000000000001e-63 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-cube-cbrt98.4%
pow398.4%
Applied egg-rr98.4%
Taylor expanded in z around 0 67.4%
*-commutative67.4%
pow-base-167.4%
*-lft-identity67.4%
rem-square-sqrt67.0%
unpow267.0%
associate-*r*67.0%
unpow267.0%
rem-square-sqrt67.4%
Simplified67.4%
if -4.1999999999999998e74 < x < 1.4000000000000001e-63Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 68.8%
neg-mul-168.8%
Simplified68.8%
Final simplification68.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.9%
Simplified99.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.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 50.2%
neg-mul-150.2%
Simplified50.2%
Final simplification50.2%
(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.9%
Simplified99.9%
add-cube-cbrt98.2%
pow398.1%
Applied egg-rr98.1%
rem-cube-cbrt99.9%
sub-neg99.9%
*-commutative99.9%
associate-*r*99.8%
fma-def99.8%
add-sqr-sqrt57.8%
sqrt-unprod62.7%
sqr-neg62.7%
sqrt-unprod20.4%
add-sqr-sqrt48.6%
Applied egg-rr48.6%
Taylor expanded in x around 0 2.2%
Final simplification2.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 2023293
(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))