
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* 3.0 y) x (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-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 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
*-commutative99.8%
fma-neg99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* 3.0 x))))
(if (<= t_0 -4e+52)
(* (* 3.0 y) x)
(if (<= t_0 -200000000000.0)
(- z)
(if (<= t_0 -1e-37) t_0 (if (<= t_0 1e-112) (- z) (* 3.0 (* y x))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -4e+52) {
tmp = (3.0 * y) * x;
} else if (t_0 <= -200000000000.0) {
tmp = -z;
} else if (t_0 <= -1e-37) {
tmp = t_0;
} else if (t_0 <= 1e-112) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
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) :: t_0
real(8) :: tmp
t_0 = y * (3.0d0 * x)
if (t_0 <= (-4d+52)) then
tmp = (3.0d0 * y) * x
else if (t_0 <= (-200000000000.0d0)) then
tmp = -z
else if (t_0 <= (-1d-37)) then
tmp = t_0
else if (t_0 <= 1d-112) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = y * (3.0 * x);
double tmp;
if (t_0 <= -4e+52) {
tmp = (3.0 * y) * x;
} else if (t_0 <= -200000000000.0) {
tmp = -z;
} else if (t_0 <= -1e-37) {
tmp = t_0;
} else if (t_0 <= 1e-112) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = y * (3.0 * x) tmp = 0 if t_0 <= -4e+52: tmp = (3.0 * y) * x elif t_0 <= -200000000000.0: tmp = -z elif t_0 <= -1e-37: tmp = t_0 elif t_0 <= 1e-112: tmp = -z else: tmp = 3.0 * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(y * Float64(3.0 * x)) tmp = 0.0 if (t_0 <= -4e+52) tmp = Float64(Float64(3.0 * y) * x); elseif (t_0 <= -200000000000.0) tmp = Float64(-z); elseif (t_0 <= -1e-37) tmp = t_0; elseif (t_0 <= 1e-112) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = y * (3.0 * x);
tmp = 0.0;
if (t_0 <= -4e+52)
tmp = (3.0 * y) * x;
elseif (t_0 <= -200000000000.0)
tmp = -z;
elseif (t_0 <= -1e-37)
tmp = t_0;
elseif (t_0 <= 1e-112)
tmp = -z;
else
tmp = 3.0 * (y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+52], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, -200000000000.0], (-z), If[LessEqual[t$95$0, -1e-37], t$95$0, If[LessEqual[t$95$0, 1e-112], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(3 \cdot x\right)\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{+52}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{elif}\;t_0 \leq -200000000000:\\
\;\;\;\;-z\\
\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-37}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 10^{-112}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x 3) y) < -4e52Initial program 99.6%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
+-commutative99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in x around inf 89.8%
*-commutative89.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
if -4e52 < (*.f64 (*.f64 x 3) y) < -2e11 or -1.00000000000000007e-37 < (*.f64 (*.f64 x 3) y) < 9.9999999999999995e-113Initial program 100.0%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 85.0%
mul-1-neg85.0%
Simplified85.0%
if -2e11 < (*.f64 (*.f64 x 3) y) < -1.00000000000000007e-37Initial program 99.7%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in x around inf 75.6%
add-sqr-sqrt0.0%
unpow20.0%
*-commutative0.0%
associate-*l*0.0%
Applied egg-rr0.0%
unpow20.0%
add-sqr-sqrt75.8%
*-commutative75.8%
associate-*r*75.6%
Applied egg-rr75.6%
if 9.9999999999999995e-113 < (*.f64 (*.f64 x 3) y) Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 81.2%
Final simplification84.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -5e+82) (not (<= x 1.96e-259))) (* 3.0 (* y x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+82) || !(x <= 1.96e-259)) {
tmp = 3.0 * (y * x);
} 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 <= (-5d+82)) .or. (.not. (x <= 1.96d-259))) then
tmp = 3.0d0 * (y * x)
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 <= -5e+82) || !(x <= 1.96e-259)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -5e+82) or not (x <= 1.96e-259): tmp = 3.0 * (y * x) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -5e+82) || !(x <= 1.96e-259)) tmp = Float64(3.0 * Float64(y * x)); 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 <= -5e+82) || ~((x <= 1.96e-259)))
tmp = 3.0 * (y * x);
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, -5e+82], N[Not[LessEqual[x, 1.96e-259]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+82} \lor \neg \left(x \leq 1.96 \cdot 10^{-259}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.00000000000000015e82 or 1.9600000000000001e-259 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 66.3%
if -5.00000000000000015e82 < x < 1.9600000000000001e-259Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.1%
mul-1-neg74.1%
Simplified74.1%
Final simplification69.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -7.4e+82) (* (* 3.0 y) x) (if (<= x 1.96e-259) (- z) (* 3.0 (* y x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -7.4e+82) {
tmp = (3.0 * y) * x;
} else if (x <= 1.96e-259) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
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 <= (-7.4d+82)) then
tmp = (3.0d0 * y) * x
else if (x <= 1.96d-259) then
tmp = -z
else
tmp = 3.0d0 * (y * x)
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 <= -7.4e+82) {
tmp = (3.0 * y) * x;
} else if (x <= 1.96e-259) {
tmp = -z;
} else {
tmp = 3.0 * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -7.4e+82: tmp = (3.0 * y) * x elif x <= 1.96e-259: tmp = -z else: tmp = 3.0 * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -7.4e+82) tmp = Float64(Float64(3.0 * y) * x); elseif (x <= 1.96e-259) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(y * x)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -7.4e+82)
tmp = (3.0 * y) * x;
elseif (x <= 1.96e-259)
tmp = -z;
else
tmp = 3.0 * (y * x);
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, -7.4e+82], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.96e-259], (-z), N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{+82}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{elif}\;x \leq 1.96 \cdot 10^{-259}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if x < -7.4000000000000005e82Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around inf 81.4%
*-commutative81.4%
associate-*r*81.3%
*-commutative81.3%
Simplified81.3%
if -7.4000000000000005e82 < x < 1.9600000000000001e-259Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.1%
mul-1-neg74.1%
Simplified74.1%
if 1.9600000000000001e-259 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
+-commutative99.8%
fma-def99.7%
Simplified99.7%
Taylor expanded in x around inf 59.7%
Final simplification69.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (y * x)) - 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 * (y * x)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (y * x)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (y * x)) - 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[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(y \cdot x\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* 3.0 y) x) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((3.0 * y) * x) - 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 * y) * x) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((3.0 * y) * x) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(3.0 * y) * x) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((3.0 * y) * x) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.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.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 51.0%
mul-1-neg51.0%
Simplified51.0%
Final simplification51.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 2024019
(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))