
(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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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
assert x < y;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -2.3e+51) (not (<= x 4e-40))) (* 3.0 (* x y)) (- z)))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e+51) || !(x <= 4e-40)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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 <= (-2.3d+51)) .or. (.not. (x <= 4d-40))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e+51) || !(x <= 4e-40)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (x <= -2.3e+51) or not (x <= 4e-40): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((x <= -2.3e+51) || !(x <= 4e-40)) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x <= -2.3e+51) || ~((x <= 4e-40)))
tmp = 3.0 * (x * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e+51], N[Not[LessEqual[x, 4e-40]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+51} \lor \neg \left(x \leq 4 \cdot 10^{-40}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.30000000000000005e51 or 3.9999999999999997e-40 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 68.3%
if -2.30000000000000005e51 < x < 3.9999999999999997e-40Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.3%
neg-mul-170.3%
Simplified70.3%
Final simplification69.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -5.2e+50) (* x (* 3.0 y)) (if (<= x 4.8e-40) (- z) (* 3.0 (* x y)))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+50) {
tmp = x * (3.0 * y);
} else if (x <= 4.8e-40) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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 <= (-5.2d+50)) then
tmp = x * (3.0d0 * y)
else if (x <= 4.8d-40) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+50) {
tmp = x * (3.0 * y);
} else if (x <= 4.8e-40) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if x <= -5.2e+50: tmp = x * (3.0 * y) elif x <= 4.8e-40: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (x <= -5.2e+50) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 4.8e-40) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -5.2e+50)
tmp = x * (3.0 * y);
elseif (x <= 4.8e-40)
tmp = -z;
else
tmp = 3.0 * (x * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -5.2e+50], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.8e-40], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+50}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-40}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -5.2000000000000004e50Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 73.3%
associate-*r*73.3%
*-commutative73.3%
associate-*r*73.3%
Simplified73.3%
if -5.2000000000000004e50 < x < 4.79999999999999982e-40Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.8%
neg-mul-170.8%
Simplified70.8%
if 4.79999999999999982e-40 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 64.5%
Final simplification69.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -7.6e+51) (* y (* x 3.0)) (if (<= x 2.6e-42) (- z) (* 3.0 (* x y)))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (x <= -7.6e+51) {
tmp = y * (x * 3.0);
} else if (x <= 2.6e-42) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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 <= (-7.6d+51)) then
tmp = y * (x * 3.0d0)
else if (x <= 2.6d-42) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.6e+51) {
tmp = y * (x * 3.0);
} else if (x <= 2.6e-42) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if x <= -7.6e+51: tmp = y * (x * 3.0) elif x <= 2.6e-42: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (x <= -7.6e+51) tmp = Float64(y * Float64(x * 3.0)); elseif (x <= 2.6e-42) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -7.6e+51)
tmp = y * (x * 3.0);
elseif (x <= 2.6e-42)
tmp = -z;
else
tmp = 3.0 * (x * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -7.6e+51], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.6e-42], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+51}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{-42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -7.5999999999999994e51Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 72.8%
associate-*r*72.9%
*-commutative72.9%
associate-*r*72.8%
Simplified72.8%
Taylor expanded in x around 0 72.8%
*-commutative72.8%
associate-*r*72.8%
*-commutative72.8%
associate-*r*72.9%
Simplified72.9%
if -7.5999999999999994e51 < x < 2.6e-42Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 70.0%
neg-mul-170.0%
Simplified70.0%
if 2.6e-42 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 63.7%
Final simplification68.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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
assert x < y;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y);
double code(double x, double y, double z) {
return -z;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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
assert x < y;
public static double code(double x, double y, double z) {
return -z;
}
[x, y] = sort([x, y]) def code(x, y, z): return -z
x, y = sort([x, y]) function code(x, y, z) return Float64(-z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
-z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 51.1%
neg-mul-151.1%
Simplified51.1%
Final simplification51.1%
(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 2023308
(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))