
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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 + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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 + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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 + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (if (<= x -4.6e-29) (* 0.5 (/ x t)) (if (<= x 8e-175) (* z (/ -0.5 t)) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.6e-29) {
tmp = 0.5 * (x / t);
} else if (x <= 8e-175) {
tmp = z * (-0.5 / t);
} else {
tmp = (y * 0.5) / 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 (x <= (-4.6d-29)) then
tmp = 0.5d0 * (x / t)
else if (x <= 8d-175) then
tmp = z * ((-0.5d0) / t)
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.6e-29) {
tmp = 0.5 * (x / t);
} else if (x <= 8e-175) {
tmp = z * (-0.5 / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -4.6e-29: tmp = 0.5 * (x / t) elif x <= 8e-175: tmp = z * (-0.5 / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -4.6e-29) tmp = Float64(0.5 * Float64(x / t)); elseif (x <= 8e-175) tmp = Float64(z * Float64(-0.5 / t)); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -4.6e-29) tmp = 0.5 * (x / t); elseif (x <= 8e-175) tmp = z * (-0.5 / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -4.6e-29], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8e-175], N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;x \leq 8 \cdot 10^{-175}:\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -4.59999999999999982e-29Initial program 100.0%
Taylor expanded in x around inf 65.2%
if -4.59999999999999982e-29 < x < 8e-175Initial program 100.0%
Taylor expanded in z around inf 56.2%
*-commutative56.2%
associate-*l/56.2%
associate-*r/55.9%
Simplified55.9%
if 8e-175 < x Initial program 100.0%
Taylor expanded in y around inf 31.6%
associate-*r/31.6%
Simplified31.6%
Final simplification49.1%
(FPCore (x y z t) :precision binary64 (if (<= x -5e-28) (* 0.5 (/ x t)) (if (<= x 1e-173) (/ (* z -0.5) t) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -5e-28) {
tmp = 0.5 * (x / t);
} else if (x <= 1e-173) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / 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 (x <= (-5d-28)) then
tmp = 0.5d0 * (x / t)
else if (x <= 1d-173) then
tmp = (z * (-0.5d0)) / t
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -5e-28) {
tmp = 0.5 * (x / t);
} else if (x <= 1e-173) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -5e-28: tmp = 0.5 * (x / t) elif x <= 1e-173: tmp = (z * -0.5) / t else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -5e-28) tmp = Float64(0.5 * Float64(x / t)); elseif (x <= 1e-173) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -5e-28) tmp = 0.5 * (x / t); elseif (x <= 1e-173) tmp = (z * -0.5) / t; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -5e-28], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1e-173], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-28}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;x \leq 10^{-173}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -5.0000000000000002e-28Initial program 100.0%
Taylor expanded in x around inf 65.2%
if -5.0000000000000002e-28 < x < 1e-173Initial program 100.0%
Taylor expanded in z around inf 56.2%
*-commutative56.2%
associate-*l/56.2%
Simplified56.2%
if 1e-173 < x Initial program 100.0%
Taylor expanded in y around inf 31.6%
associate-*r/31.6%
Simplified31.6%
Final simplification49.2%
(FPCore (x y z t) :precision binary64 (if (<= y 6.4e+131) (* 0.5 (/ (- x z) t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.4e+131) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y * 0.5) / 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 <= 6.4d+131) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.4e+131) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 6.4e+131: tmp = 0.5 * ((x - z) / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 6.4e+131) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 6.4e+131) tmp = 0.5 * ((x - z) / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 6.4e+131], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.4 \cdot 10^{+131}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 6.4000000000000004e131Initial program 100.0%
Taylor expanded in y around 0 77.3%
if 6.4000000000000004e131 < y Initial program 100.0%
Taylor expanded in y around inf 84.2%
associate-*r/84.2%
Simplified84.2%
Final simplification78.3%
(FPCore (x y z t) :precision binary64 (if (<= y 2.1e+97) (* 0.5 (/ (- x z) t)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.1e+97) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (x + y) * (0.5 / 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 <= 2.1d+97) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.1e+97) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.1e+97: tmp = 0.5 * ((x - z) / t) else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.1e+97) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.1e+97) tmp = 0.5 * ((x - z) / t); else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.1e+97], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{+97}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 2.10000000000000012e97Initial program 100.0%
Taylor expanded in y around 0 78.3%
if 2.10000000000000012e97 < y Initial program 100.0%
Taylor expanded in z around 0 89.9%
associate-*r/89.9%
associate-*l/89.8%
*-commutative89.8%
+-commutative89.8%
Simplified89.8%
Final simplification80.4%
(FPCore (x y z t) :precision binary64 (if (<= x -3.6e-28) (* 0.5 (/ (- x z) t)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.6e-28) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (0.5 * (y - z)) / 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 (x <= (-3.6d-28)) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = (0.5d0 * (y - z)) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.6e-28) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = (0.5 * (y - z)) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.6e-28: tmp = 0.5 * ((x - z) / t) else: tmp = (0.5 * (y - z)) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.6e-28) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(0.5 * Float64(y - z)) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -3.6e-28) tmp = 0.5 * ((x - z) / t); else tmp = (0.5 * (y - z)) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.6e-28], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-28}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if x < -3.5999999999999999e-28Initial program 100.0%
Taylor expanded in y around 0 81.7%
if -3.5999999999999999e-28 < x Initial program 100.0%
Taylor expanded in x around 0 81.5%
associate-*r/81.5%
Simplified81.5%
Final simplification81.6%
(FPCore (x y z t) :precision binary64 (if (<= x -4.6e-28) (* 0.5 (/ x t)) (* z (/ -0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.6e-28) {
tmp = 0.5 * (x / t);
} else {
tmp = z * (-0.5 / 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 (x <= (-4.6d-28)) then
tmp = 0.5d0 * (x / t)
else
tmp = z * ((-0.5d0) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.6e-28) {
tmp = 0.5 * (x / t);
} else {
tmp = z * (-0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -4.6e-28: tmp = 0.5 * (x / t) else: tmp = z * (-0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -4.6e-28) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(z * Float64(-0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -4.6e-28) tmp = 0.5 * (x / t); else tmp = z * (-0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -4.6e-28], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-28}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\
\end{array}
\end{array}
if x < -4.59999999999999971e-28Initial program 100.0%
Taylor expanded in x around inf 65.2%
if -4.59999999999999971e-28 < x Initial program 100.0%
Taylor expanded in z around inf 48.0%
*-commutative48.0%
associate-*l/48.0%
associate-*r/47.9%
Simplified47.9%
Final simplification52.9%
(FPCore (x y z t) :precision binary64 (* 0.5 (/ x t)))
double code(double x, double y, double z, double t) {
return 0.5 * (x / 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.5d0 * (x / t)
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (x / t);
}
def code(x, y, z, t): return 0.5 * (x / t)
function code(x, y, z, t) return Float64(0.5 * Float64(x / t)) end
function tmp = code(x, y, z, t) tmp = 0.5 * (x / t); end
code[x_, y_, z_, t_] := N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{x}{t}
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 36.1%
Final simplification36.1%
herbie shell --seed 2024054
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, B"
:precision binary64
(/ (- (+ x y) z) (* t 2.0)))