
(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, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
NOTE: x, y, and z 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 && y < z;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x, y, and z 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, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -3e+57) (not (<= x 6e-33))) (* 3.0 (* x y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e+57) || !(x <= 6e-33)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x, y, and z 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 <= (-3d+57)) .or. (.not. (x <= 6d-33))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3e+57) || !(x <= 6e-33)) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -3e+57) or not (x <= 6e-33): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -3e+57) || !(x <= 6e-33)) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x <= -3e+57) || ~((x <= 6e-33)))
tmp = 3.0 * (x * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[x, -3e+57], N[Not[LessEqual[x, 6e-33]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+57} \lor \neg \left(x \leq 6 \cdot 10^{-33}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3e57 or 6.0000000000000003e-33 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 90.3%
*-commutative90.3%
fma-neg90.3%
associate-/l*90.3%
metadata-eval90.3%
Simplified90.3%
Taylor expanded in x around inf 69.8%
if -3e57 < x < 6.0000000000000003e-33Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 65.8%
mul-1-neg65.8%
Simplified65.8%
Final simplification67.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -1.8e+56) (* x (* 3.0 y)) (if (<= x 1.35e-31) (- z) (* y (* x 3.0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+56) {
tmp = x * (3.0 * y);
} else if (x <= 1.35e-31) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
NOTE: x, y, and z 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 <= (-1.8d+56)) then
tmp = x * (3.0d0 * y)
else if (x <= 1.35d-31) then
tmp = -z
else
tmp = y * (x * 3.0d0)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+56) {
tmp = x * (3.0 * y);
} else if (x <= 1.35e-31) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -1.8e+56: tmp = x * (3.0 * y) elif x <= 1.35e-31: tmp = -z else: tmp = y * (x * 3.0) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.8e+56) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 1.35e-31) tmp = Float64(-z); else tmp = Float64(y * Float64(x * 3.0)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -1.8e+56)
tmp = x * (3.0 * y);
elseif (x <= 1.35e-31)
tmp = -z;
else
tmp = y * (x * 3.0);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -1.8e+56], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.35e-31], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+56}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-31}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if x < -1.79999999999999999e56Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 88.2%
*-commutative88.2%
fma-neg88.2%
associate-/l*88.1%
metadata-eval88.1%
Simplified88.1%
Taylor expanded in x around inf 75.8%
*-commutative75.8%
associate-*r*75.8%
Simplified75.8%
if -1.79999999999999999e56 < x < 1.35000000000000007e-31Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 66.0%
mul-1-neg66.0%
Simplified66.0%
if 1.35000000000000007e-31 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 91.9%
*-commutative91.9%
fma-neg91.9%
associate-/l*91.9%
metadata-eval91.9%
Simplified91.9%
Taylor expanded in x around inf 65.9%
*-commutative65.9%
associate-*r*65.8%
Simplified65.8%
Taylor expanded in x around 0 65.9%
*-commutative65.9%
associate-*r*65.8%
*-commutative65.8%
associate-*r*65.9%
Simplified65.9%
Final simplification67.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -1.05e+56) (* x (* 3.0 y)) (if (<= x 2.7e-36) (- z) (* 3.0 (* x y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+56) {
tmp = x * (3.0 * y);
} else if (x <= 2.7e-36) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
NOTE: x, y, and z 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 <= (-1.05d+56)) then
tmp = x * (3.0d0 * y)
else if (x <= 2.7d-36) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+56) {
tmp = x * (3.0 * y);
} else if (x <= 2.7e-36) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -1.05e+56: tmp = x * (3.0 * y) elif x <= 2.7e-36: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.05e+56) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 2.7e-36) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -1.05e+56)
tmp = x * (3.0 * y);
elseif (x <= 2.7e-36)
tmp = -z;
else
tmp = 3.0 * (x * y);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, -1.05e+56], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.7e-36], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+56}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-36}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -1.05000000000000009e56Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 88.2%
*-commutative88.2%
fma-neg88.2%
associate-/l*88.1%
metadata-eval88.1%
Simplified88.1%
Taylor expanded in x around inf 75.8%
*-commutative75.8%
associate-*r*75.8%
Simplified75.8%
if -1.05000000000000009e56 < x < 2.70000000000000007e-36Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 65.8%
mul-1-neg65.8%
Simplified65.8%
if 2.70000000000000007e-36 < x Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 92.0%
*-commutative92.0%
fma-neg92.0%
associate-/l*92.0%
metadata-eval92.0%
Simplified92.0%
Taylor expanded in x around inf 64.8%
Final simplification67.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
NOTE: x, y, and z 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 && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x, y, and z 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, z] = \mathsf{sort}([x, y, z])\\
\\
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%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -z;
}
NOTE: x, y, and z 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 && y < z;
public static double code(double x, double y, double z) {
return -z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return -z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 51.0%
mul-1-neg51.0%
Simplified51.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 2024108
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))