
(FPCore (x y z t) :precision binary64 (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))
double code(double x, double y, double z, double t) {
return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((1.0d0 / 8.0d0) * x) - ((y * z) / 2.0d0)) + t
end function
public static double code(double x, double y, double z, double t) {
return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
def code(x, y, z, t): return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(1.0 / 8.0) * x) - Float64(Float64(y * z) / 2.0)) + t) end
function tmp = code(x, y, z, t) tmp = (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / 8.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))
double code(double x, double y, double z, double t) {
return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((1.0d0 / 8.0d0) * x) - ((y * z) / 2.0d0)) + t
end function
public static double code(double x, double y, double z, double t) {
return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
def code(x, y, z, t): return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(1.0 / 8.0) * x) - Float64(Float64(y * z) / 2.0)) + t) end
function tmp = code(x, y, z, t) tmp = (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / 8.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\end{array}
(FPCore (x y z t) :precision binary64 (fma z (* y -0.5) (fma 0.125 x t)))
double code(double x, double y, double z, double t) {
return fma(z, (y * -0.5), fma(0.125, x, t));
}
function code(x, y, z, t) return fma(z, Float64(y * -0.5), fma(0.125, x, t)) end
code[x_, y_, z_, t_] := N[(z * N[(y * -0.5), $MachinePrecision] + N[(0.125 * x + t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y \cdot -0.5, \mathsf{fma}\left(0.125, x, t\right)\right)
\end{array}
Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
associate-+l+99.7%
associate-/l*99.9%
distribute-frac-neg99.9%
associate-/r/100.0%
*-commutative100.0%
+-commutative100.0%
fma-def100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
*-commutative100.0%
metadata-eval100.0%
+-commutative100.0%
fma-def100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* z -0.5))))
(if (<= t -1.46e+122)
t
(if (<= t -5.7e+79)
t_1
(if (<= t -9e+21)
t
(if (<= t 2.35e-152)
(* 0.125 x)
(if (<= t 2.5e-94)
t_1
(if (<= t 3.05e+50) (* 0.125 x) (if (<= t 3.4e+97) t_1 t)))))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z * -0.5);
double tmp;
if (t <= -1.46e+122) {
tmp = t;
} else if (t <= -5.7e+79) {
tmp = t_1;
} else if (t <= -9e+21) {
tmp = t;
} else if (t <= 2.35e-152) {
tmp = 0.125 * x;
} else if (t <= 2.5e-94) {
tmp = t_1;
} else if (t <= 3.05e+50) {
tmp = 0.125 * x;
} else if (t <= 3.4e+97) {
tmp = t_1;
} else {
tmp = t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (z * (-0.5d0))
if (t <= (-1.46d+122)) then
tmp = t
else if (t <= (-5.7d+79)) then
tmp = t_1
else if (t <= (-9d+21)) then
tmp = t
else if (t <= 2.35d-152) then
tmp = 0.125d0 * x
else if (t <= 2.5d-94) then
tmp = t_1
else if (t <= 3.05d+50) then
tmp = 0.125d0 * x
else if (t <= 3.4d+97) then
tmp = t_1
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (z * -0.5);
double tmp;
if (t <= -1.46e+122) {
tmp = t;
} else if (t <= -5.7e+79) {
tmp = t_1;
} else if (t <= -9e+21) {
tmp = t;
} else if (t <= 2.35e-152) {
tmp = 0.125 * x;
} else if (t <= 2.5e-94) {
tmp = t_1;
} else if (t <= 3.05e+50) {
tmp = 0.125 * x;
} else if (t <= 3.4e+97) {
tmp = t_1;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z * -0.5) tmp = 0 if t <= -1.46e+122: tmp = t elif t <= -5.7e+79: tmp = t_1 elif t <= -9e+21: tmp = t elif t <= 2.35e-152: tmp = 0.125 * x elif t <= 2.5e-94: tmp = t_1 elif t <= 3.05e+50: tmp = 0.125 * x elif t <= 3.4e+97: tmp = t_1 else: tmp = t return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z * -0.5)) tmp = 0.0 if (t <= -1.46e+122) tmp = t; elseif (t <= -5.7e+79) tmp = t_1; elseif (t <= -9e+21) tmp = t; elseif (t <= 2.35e-152) tmp = Float64(0.125 * x); elseif (t <= 2.5e-94) tmp = t_1; elseif (t <= 3.05e+50) tmp = Float64(0.125 * x); elseif (t <= 3.4e+97) tmp = t_1; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z * -0.5); tmp = 0.0; if (t <= -1.46e+122) tmp = t; elseif (t <= -5.7e+79) tmp = t_1; elseif (t <= -9e+21) tmp = t; elseif (t <= 2.35e-152) tmp = 0.125 * x; elseif (t <= 2.5e-94) tmp = t_1; elseif (t <= 3.05e+50) tmp = 0.125 * x; elseif (t <= 3.4e+97) tmp = t_1; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t, -1.46e+122], t, If[LessEqual[t, -5.7e+79], t$95$1, If[LessEqual[t, -9e+21], t, If[LessEqual[t, 2.35e-152], N[(0.125 * x), $MachinePrecision], If[LessEqual[t, 2.5e-94], t$95$1, If[LessEqual[t, 3.05e+50], N[(0.125 * x), $MachinePrecision], If[LessEqual[t, 3.4e+97], t$95$1, t]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z \cdot -0.5\right)\\
\mathbf{if}\;t \leq -1.46 \cdot 10^{+122}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq -5.7 \cdot 10^{+79}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t \leq -9 \cdot 10^{+21}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 2.35 \cdot 10^{-152}:\\
\;\;\;\;0.125 \cdot x\\
\mathbf{elif}\;t \leq 2.5 \cdot 10^{-94}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t \leq 3.05 \cdot 10^{+50}:\\
\;\;\;\;0.125 \cdot x\\
\mathbf{elif}\;t \leq 3.4 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -1.46e122 or -5.6999999999999997e79 < t < -9e21 or 3.4000000000000001e97 < t Initial program 100.0%
metadata-eval100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in t around inf 66.8%
if -1.46e122 < t < -5.6999999999999997e79 or 2.35000000000000006e-152 < t < 2.4999999999999998e-94 or 3.05000000000000013e50 < t < 3.4000000000000001e97Initial program 98.0%
metadata-eval98.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 62.4%
*-commutative62.4%
associate-*l*64.4%
Simplified64.4%
if -9e21 < t < 2.35000000000000006e-152 or 2.4999999999999998e-94 < t < 3.05000000000000013e50Initial program 100.0%
metadata-eval100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 59.8%
Final simplification63.0%
(FPCore (x y z t) :precision binary64 (if (or (<= (* z y) -1e+102) (not (<= (* z y) 2e+38))) (- t (* (* z y) 0.5)) (+ t (* 0.125 x))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * y) <= -1e+102) || !((z * y) <= 2e+38)) {
tmp = t - ((z * y) * 0.5);
} else {
tmp = t + (0.125 * x);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (((z * y) <= (-1d+102)) .or. (.not. ((z * y) <= 2d+38))) then
tmp = t - ((z * y) * 0.5d0)
else
tmp = t + (0.125d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (((z * y) <= -1e+102) || !((z * y) <= 2e+38)) {
tmp = t - ((z * y) * 0.5);
} else {
tmp = t + (0.125 * x);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z * y) <= -1e+102) or not ((z * y) <= 2e+38): tmp = t - ((z * y) * 0.5) else: tmp = t + (0.125 * x) return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z * y) <= -1e+102) || !(Float64(z * y) <= 2e+38)) tmp = Float64(t - Float64(Float64(z * y) * 0.5)); else tmp = Float64(t + Float64(0.125 * x)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z * y) <= -1e+102) || ~(((z * y) <= 2e+38))) tmp = t - ((z * y) * 0.5); else tmp = t + (0.125 * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z * y), $MachinePrecision], -1e+102], N[Not[LessEqual[N[(z * y), $MachinePrecision], 2e+38]], $MachinePrecision]], N[(t - N[(N[(z * y), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], N[(t + N[(0.125 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+102} \lor \neg \left(z \cdot y \leq 2 \cdot 10^{+38}\right):\\
\;\;\;\;t - \left(z \cdot y\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t + 0.125 \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -9.99999999999999977e101 or 1.99999999999999995e38 < (*.f64 y z) Initial program 99.2%
metadata-eval99.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 91.8%
if -9.99999999999999977e101 < (*.f64 y z) < 1.99999999999999995e38Initial program 100.0%
metadata-eval100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 92.7%
Final simplification92.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.25e-51) (not (<= z 1.5e+129))) (* y (* z -0.5)) (+ t (* 0.125 x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e-51) || !(z <= 1.5e+129)) {
tmp = y * (z * -0.5);
} else {
tmp = t + (0.125 * x);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-2.25d-51)) .or. (.not. (z <= 1.5d+129))) then
tmp = y * (z * (-0.5d0))
else
tmp = t + (0.125d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e-51) || !(z <= 1.5e+129)) {
tmp = y * (z * -0.5);
} else {
tmp = t + (0.125 * x);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.25e-51) or not (z <= 1.5e+129): tmp = y * (z * -0.5) else: tmp = t + (0.125 * x) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.25e-51) || !(z <= 1.5e+129)) tmp = Float64(y * Float64(z * -0.5)); else tmp = Float64(t + Float64(0.125 * x)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.25e-51) || ~((z <= 1.5e+129))) tmp = y * (z * -0.5); else tmp = t + (0.125 * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.25e-51], N[Not[LessEqual[z, 1.5e+129]], $MachinePrecision]], N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision], N[(t + N[(0.125 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{-51} \lor \neg \left(z \leq 1.5 \cdot 10^{+129}\right):\\
\;\;\;\;y \cdot \left(z \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t + 0.125 \cdot x\\
\end{array}
\end{array}
if z < -2.24999999999999987e-51 or 1.50000000000000015e129 < z Initial program 99.1%
metadata-eval99.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 64.6%
*-commutative64.6%
associate-*l*65.4%
Simplified65.4%
if -2.24999999999999987e-51 < z < 1.50000000000000015e129Initial program 100.0%
metadata-eval100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 83.9%
Final simplification77.3%
(FPCore (x y z t) :precision binary64 (if (<= t -2.75e+22) t (if (<= t 4.8e+62) (* 0.125 x) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.75e+22) {
tmp = t;
} else if (t <= 4.8e+62) {
tmp = 0.125 * x;
} else {
tmp = t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-2.75d+22)) then
tmp = t
else if (t <= 4.8d+62) then
tmp = 0.125d0 * x
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.75e+22) {
tmp = t;
} else if (t <= 4.8e+62) {
tmp = 0.125 * x;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.75e+22: tmp = t elif t <= 4.8e+62: tmp = 0.125 * x else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.75e+22) tmp = t; elseif (t <= 4.8e+62) tmp = Float64(0.125 * x); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.75e+22) tmp = t; elseif (t <= 4.8e+62) tmp = 0.125 * x; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.75e+22], t, If[LessEqual[t, 4.8e+62], N[(0.125 * x), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.75 \cdot 10^{+22}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 4.8 \cdot 10^{+62}:\\
\;\;\;\;0.125 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -2.7500000000000001e22 or 4.8e62 < t Initial program 99.3%
metadata-eval99.3%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in t around inf 60.7%
if -2.7500000000000001e22 < t < 4.8e62Initial program 100.0%
metadata-eval100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 54.8%
Final simplification57.3%
(FPCore (x y z t) :precision binary64 (+ t (- (* 0.125 x) (/ y (/ 2.0 z)))))
double code(double x, double y, double z, double t) {
return t + ((0.125 * x) - (y / (2.0 / z)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t + ((0.125d0 * x) - (y / (2.0d0 / z)))
end function
public static double code(double x, double y, double z, double t) {
return t + ((0.125 * x) - (y / (2.0 / z)));
}
def code(x, y, z, t): return t + ((0.125 * x) - (y / (2.0 / z)))
function code(x, y, z, t) return Float64(t + Float64(Float64(0.125 * x) - Float64(y / Float64(2.0 / z)))) end
function tmp = code(x, y, z, t) tmp = t + ((0.125 * x) - (y / (2.0 / z))); end
code[x_, y_, z_, t_] := N[(t + N[(N[(0.125 * x), $MachinePrecision] - N[(y / N[(2.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \left(0.125 \cdot x - \frac{y}{\frac{2}{z}}\right)
\end{array}
Initial program 99.7%
metadata-eval99.7%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.7%
metadata-eval99.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in t around inf 31.8%
Final simplification31.8%
(FPCore (x y z t) :precision binary64 (- (+ (/ x 8.0) t) (* (/ z 2.0) y)))
double code(double x, double y, double z, double t) {
return ((x / 8.0) + t) - ((z / 2.0) * y);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x / 8.0d0) + t) - ((z / 2.0d0) * y)
end function
public static double code(double x, double y, double z, double t) {
return ((x / 8.0) + t) - ((z / 2.0) * y);
}
def code(x, y, z, t): return ((x / 8.0) + t) - ((z / 2.0) * y)
function code(x, y, z, t) return Float64(Float64(Float64(x / 8.0) + t) - Float64(Float64(z / 2.0) * y)) end
function tmp = code(x, y, z, t) tmp = ((x / 8.0) + t) - ((z / 2.0) * y); end
code[x_, y_, z_, t_] := N[(N[(N[(x / 8.0), $MachinePrecision] + t), $MachinePrecision] - N[(N[(z / 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{8} + t\right) - \frac{z}{2} \cdot y
\end{array}
herbie shell --seed 2024024
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (+ (/ x 8.0) t) (* (/ z 2.0) y))
(+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))