
(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 6 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 (+ (- (* 0.125 x) (* y (/ z 2.0))) t))
double code(double x, double y, double z, double t) {
return ((0.125 * 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 = ((0.125d0 * x) - (y * (z / 2.0d0))) + t
end function
public static double code(double x, double y, double z, double t) {
return ((0.125 * x) - (y * (z / 2.0))) + t;
}
def code(x, y, z, t): return ((0.125 * x) - (y * (z / 2.0))) + t
function code(x, y, z, t) return Float64(Float64(Float64(0.125 * x) - Float64(y * Float64(z / 2.0))) + t) end
function tmp = code(x, y, z, t) tmp = ((0.125 * x) - (y * (z / 2.0))) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(0.125 * x), $MachinePrecision] - N[(y * N[(z / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(0.125 \cdot x - y \cdot \frac{z}{2}\right) + t
\end{array}
Initial program 99.7%
associate-+l-99.7%
*-commutative99.7%
associate-+l-99.7%
metadata-eval99.7%
*-commutative99.7%
associate-/l*100.0%
Simplified100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= (* y z) -5e+84) (not (<= (* y z) 5e-43))) (- t (* y (* z 0.5))) (+ (* 0.125 x) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (((y * z) <= -5e+84) || !((y * z) <= 5e-43)) {
tmp = t - (y * (z * 0.5));
} else {
tmp = (0.125 * x) + 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 (((y * z) <= (-5d+84)) .or. (.not. ((y * z) <= 5d-43))) then
tmp = t - (y * (z * 0.5d0))
else
tmp = (0.125d0 * x) + t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (((y * z) <= -5e+84) || !((y * z) <= 5e-43)) {
tmp = t - (y * (z * 0.5));
} else {
tmp = (0.125 * x) + t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((y * z) <= -5e+84) or not ((y * z) <= 5e-43): tmp = t - (y * (z * 0.5)) else: tmp = (0.125 * x) + t return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(y * z) <= -5e+84) || !(Float64(y * z) <= 5e-43)) tmp = Float64(t - Float64(y * Float64(z * 0.5))); else tmp = Float64(Float64(0.125 * x) + t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((y * z) <= -5e+84) || ~(((y * z) <= 5e-43))) tmp = t - (y * (z * 0.5)); else tmp = (0.125 * x) + t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -5e+84], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e-43]], $MachinePrecision]], N[(t - N[(y * N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.125 * x), $MachinePrecision] + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+84} \lor \neg \left(y \cdot z \leq 5 \cdot 10^{-43}\right):\\
\;\;\;\;t - y \cdot \left(z \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.125 \cdot x + t\\
\end{array}
\end{array}
if (*.f64 y z) < -5.0000000000000001e84 or 5.00000000000000019e-43 < (*.f64 y z) Initial program 99.3%
associate-+l-99.3%
*-commutative99.3%
associate-+l-99.3%
metadata-eval99.3%
*-commutative99.3%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 87.6%
*-commutative87.6%
associate-*r*88.3%
Simplified88.3%
if -5.0000000000000001e84 < (*.f64 y z) < 5.00000000000000019e-43Initial program 100.0%
associate-+l-100.0%
*-commutative100.0%
associate-+l-100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 92.5%
Final simplification90.5%
(FPCore (x y z t) :precision binary64 (if (or (<= (* y z) -1.8e+151) (not (<= (* y z) 5.6e-44))) (* (* y z) -0.5) t))
double code(double x, double y, double z, double t) {
double tmp;
if (((y * z) <= -1.8e+151) || !((y * z) <= 5.6e-44)) {
tmp = (y * z) * -0.5;
} 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 (((y * z) <= (-1.8d+151)) .or. (.not. ((y * z) <= 5.6d-44))) then
tmp = (y * z) * (-0.5d0)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (((y * z) <= -1.8e+151) || !((y * z) <= 5.6e-44)) {
tmp = (y * z) * -0.5;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((y * z) <= -1.8e+151) or not ((y * z) <= 5.6e-44): tmp = (y * z) * -0.5 else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(y * z) <= -1.8e+151) || !(Float64(y * z) <= 5.6e-44)) tmp = Float64(Float64(y * z) * -0.5); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((y * z) <= -1.8e+151) || ~(((y * z) <= 5.6e-44))) tmp = (y * z) * -0.5; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -1.8e+151], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5.6e-44]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * -0.5), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1.8 \cdot 10^{+151} \lor \neg \left(y \cdot z \leq 5.6 \cdot 10^{-44}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if (*.f64 y z) < -1.8e151 or 5.6e-44 < (*.f64 y z) Initial program 99.2%
associate-+l-99.2%
*-commutative99.2%
associate-+l-99.2%
metadata-eval99.2%
*-commutative99.2%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 87.6%
*-commutative87.6%
associate-*r*88.3%
Simplified88.3%
metadata-eval88.3%
div-inv88.3%
clear-num88.2%
div-inv88.1%
Applied egg-rr88.1%
Taylor expanded in t around 0 69.9%
if -1.8e151 < (*.f64 y z) < 5.6e-44Initial program 100.0%
associate-+l-100.0%
*-commutative100.0%
associate-+l-100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in t around inf 42.4%
Final simplification54.3%
(FPCore (x y z t) :precision binary64 (if (<= (* y z) -5e+159) (* (* y z) -0.5) (if (<= (* y z) 2e+95) (+ (* 0.125 x) t) (* y (* z -0.5)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y * z) <= -5e+159) {
tmp = (y * z) * -0.5;
} else if ((y * z) <= 2e+95) {
tmp = (0.125 * x) + t;
} else {
tmp = y * (z * -0.5);
}
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 ((y * z) <= (-5d+159)) then
tmp = (y * z) * (-0.5d0)
else if ((y * z) <= 2d+95) then
tmp = (0.125d0 * x) + t
else
tmp = y * (z * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y * z) <= -5e+159) {
tmp = (y * z) * -0.5;
} else if ((y * z) <= 2e+95) {
tmp = (0.125 * x) + t;
} else {
tmp = y * (z * -0.5);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y * z) <= -5e+159: tmp = (y * z) * -0.5 elif (y * z) <= 2e+95: tmp = (0.125 * x) + t else: tmp = y * (z * -0.5) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y * z) <= -5e+159) tmp = Float64(Float64(y * z) * -0.5); elseif (Float64(y * z) <= 2e+95) tmp = Float64(Float64(0.125 * x) + t); else tmp = Float64(y * Float64(z * -0.5)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y * z) <= -5e+159) tmp = (y * z) * -0.5; elseif ((y * z) <= 2e+95) tmp = (0.125 * x) + t; else tmp = y * (z * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+159], N[(N[(y * z), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 2e+95], N[(N[(0.125 * x), $MachinePrecision] + t), $MachinePrecision], N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+159}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -0.5\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+95}:\\
\;\;\;\;0.125 \cdot x + t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot -0.5\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000003e159Initial program 99.9%
associate-+l-99.9%
*-commutative99.9%
associate-+l-99.9%
metadata-eval99.9%
*-commutative99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 92.7%
*-commutative92.7%
associate-*r*92.7%
Simplified92.7%
metadata-eval92.7%
div-inv92.7%
clear-num92.6%
div-inv92.5%
Applied egg-rr92.5%
Taylor expanded in t around 0 80.5%
if -5.00000000000000003e159 < (*.f64 y z) < 2.00000000000000004e95Initial program 100.0%
associate-+l-100.0%
*-commutative100.0%
associate-+l-100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 85.9%
if 2.00000000000000004e95 < (*.f64 y z) Initial program 98.2%
associate-+l-98.2%
*-commutative98.2%
associate-+l-98.2%
metadata-eval98.2%
*-commutative98.2%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 86.5%
*-commutative86.5%
associate-*r*88.3%
Simplified88.3%
metadata-eval88.3%
div-inv88.3%
clear-num88.2%
div-inv88.1%
Applied egg-rr88.1%
Taylor expanded in t around 0 76.1%
add-log-exp49.4%
*-un-lft-identity49.4%
log-prod49.4%
metadata-eval49.4%
add-log-exp76.1%
*-commutative76.1%
associate-*l*77.9%
Applied egg-rr77.9%
+-lft-identity77.9%
Simplified77.9%
Final simplification83.6%
(FPCore (x y z t) :precision binary64 (if (<= (* y z) -5e+159) (* (* y z) -0.5) (if (<= (* y z) 1e-56) t (* y (* z -0.5)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y * z) <= -5e+159) {
tmp = (y * z) * -0.5;
} else if ((y * z) <= 1e-56) {
tmp = t;
} else {
tmp = y * (z * -0.5);
}
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 ((y * z) <= (-5d+159)) then
tmp = (y * z) * (-0.5d0)
else if ((y * z) <= 1d-56) then
tmp = t
else
tmp = y * (z * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y * z) <= -5e+159) {
tmp = (y * z) * -0.5;
} else if ((y * z) <= 1e-56) {
tmp = t;
} else {
tmp = y * (z * -0.5);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y * z) <= -5e+159: tmp = (y * z) * -0.5 elif (y * z) <= 1e-56: tmp = t else: tmp = y * (z * -0.5) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y * z) <= -5e+159) tmp = Float64(Float64(y * z) * -0.5); elseif (Float64(y * z) <= 1e-56) tmp = t; else tmp = Float64(y * Float64(z * -0.5)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y * z) <= -5e+159) tmp = (y * z) * -0.5; elseif ((y * z) <= 1e-56) tmp = t; else tmp = y * (z * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+159], N[(N[(y * z), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e-56], t, N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+159}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -0.5\\
\mathbf{elif}\;y \cdot z \leq 10^{-56}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot -0.5\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.00000000000000003e159Initial program 99.9%
associate-+l-99.9%
*-commutative99.9%
associate-+l-99.9%
metadata-eval99.9%
*-commutative99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 92.7%
*-commutative92.7%
associate-*r*92.7%
Simplified92.7%
metadata-eval92.7%
div-inv92.7%
clear-num92.6%
div-inv92.5%
Applied egg-rr92.5%
Taylor expanded in t around 0 80.5%
if -5.00000000000000003e159 < (*.f64 y z) < 1e-56Initial program 100.0%
associate-+l-100.0%
*-commutative100.0%
associate-+l-100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in t around inf 42.4%
if 1e-56 < (*.f64 y z) Initial program 98.9%
associate-+l-98.9%
*-commutative98.9%
associate-+l-98.9%
metadata-eval98.9%
*-commutative98.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 84.7%
*-commutative84.7%
associate-*r*85.8%
Simplified85.8%
metadata-eval85.8%
div-inv85.8%
clear-num85.7%
div-inv85.6%
Applied egg-rr85.6%
Taylor expanded in t around 0 63.9%
add-log-exp34.2%
*-un-lft-identity34.2%
log-prod34.2%
metadata-eval34.2%
add-log-exp63.9%
*-commutative63.9%
associate-*l*65.1%
Applied egg-rr65.1%
+-lft-identity65.1%
Simplified65.1%
Final simplification54.6%
(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%
associate-+l-99.7%
*-commutative99.7%
associate-+l-99.7%
metadata-eval99.7%
*-commutative99.7%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in t around inf 32.6%
(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 2024137
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (+ (/ x 8) t) (* (/ z 2) y)))
(+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))