
(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 7 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
(let* ((t_1 (/ z (* t -2.0))) (t_2 (* 0.5 (/ x t))))
(if (<= y -2.5e-220)
t_2
(if (<= y 5.9e-126)
t_1
(if (<= y 1.35e-15) t_2 (if (<= y 2.65e-5) t_1 (* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
double t_1 = z / (t * -2.0);
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -2.5e-220) {
tmp = t_2;
} else if (y <= 5.9e-126) {
tmp = t_1;
} else if (y <= 1.35e-15) {
tmp = t_2;
} else if (y <= 2.65e-5) {
tmp = t_1;
} else {
tmp = 0.5 * (y / 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) :: t_2
real(8) :: tmp
t_1 = z / (t * (-2.0d0))
t_2 = 0.5d0 * (x / t)
if (y <= (-2.5d-220)) then
tmp = t_2
else if (y <= 5.9d-126) then
tmp = t_1
else if (y <= 1.35d-15) then
tmp = t_2
else if (y <= 2.65d-5) then
tmp = t_1
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z / (t * -2.0);
double t_2 = 0.5 * (x / t);
double tmp;
if (y <= -2.5e-220) {
tmp = t_2;
} else if (y <= 5.9e-126) {
tmp = t_1;
} else if (y <= 1.35e-15) {
tmp = t_2;
} else if (y <= 2.65e-5) {
tmp = t_1;
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = z / (t * -2.0) t_2 = 0.5 * (x / t) tmp = 0 if y <= -2.5e-220: tmp = t_2 elif y <= 5.9e-126: tmp = t_1 elif y <= 1.35e-15: tmp = t_2 elif y <= 2.65e-5: tmp = t_1 else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) t_1 = Float64(z / Float64(t * -2.0)) t_2 = Float64(0.5 * Float64(x / t)) tmp = 0.0 if (y <= -2.5e-220) tmp = t_2; elseif (y <= 5.9e-126) tmp = t_1; elseif (y <= 1.35e-15) tmp = t_2; elseif (y <= 2.65e-5) tmp = t_1; else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z / (t * -2.0); t_2 = 0.5 * (x / t); tmp = 0.0; if (y <= -2.5e-220) tmp = t_2; elseif (y <= 5.9e-126) tmp = t_1; elseif (y <= 1.35e-15) tmp = t_2; elseif (y <= 2.65e-5) tmp = t_1; else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z / N[(t * -2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5e-220], t$95$2, If[LessEqual[y, 5.9e-126], t$95$1, If[LessEqual[y, 1.35e-15], t$95$2, If[LessEqual[y, 2.65e-5], t$95$1, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z}{t \cdot -2}\\
t_2 := 0.5 \cdot \frac{x}{t}\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{-220}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 5.9 \cdot 10^{-126}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-15}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-5}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < -2.5000000000000001e-220 or 5.89999999999999972e-126 < y < 1.35000000000000005e-15Initial program 100.0%
Taylor expanded in x around inf 42.1%
if -2.5000000000000001e-220 < y < 5.89999999999999972e-126 or 1.35000000000000005e-15 < y < 2.65e-5Initial program 100.0%
Taylor expanded in z around inf 59.6%
associate-*r/59.6%
associate-*l/59.3%
metadata-eval59.3%
associate-/r*59.3%
*-commutative59.3%
associate-*l/59.6%
metadata-eval59.6%
distribute-lft-neg-in59.6%
neg-mul-159.6%
remove-double-neg59.6%
Simplified59.6%
if 2.65e-5 < y Initial program 100.0%
Taylor expanded in y around inf 71.8%
Final simplification53.4%
(FPCore (x y z t) :precision binary64 (if (<= y 2.2e+51) (* 0.5 (/ (- x z) t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.2e+51) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / 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.2d+51) then
tmp = 0.5d0 * ((x - z) / t)
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.2e+51) {
tmp = 0.5 * ((x - z) / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.2e+51: tmp = 0.5 * ((x - z) / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.2e+51) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.2e+51) tmp = 0.5 * ((x - z) / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.2e+51], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{+51}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < 2.19999999999999992e51Initial program 100.0%
Taylor expanded in y around 0 75.5%
if 2.19999999999999992e51 < y Initial program 100.0%
Taylor expanded in y around inf 76.7%
Final simplification75.8%
(FPCore (x y z t) :precision binary64 (if (<= y 2.45e-5) (* 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.45e-5) {
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.45d-5) 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.45e-5) {
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.45e-5: 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.45e-5) tmp = Float64(0.5 * Float64(Float64(x - z) / t)); else tmp = Float64(Float64(Float64(x + y) * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.45e-5) 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.45e-5], N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.45 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x + y\right) \cdot 0.5}{t}\\
\end{array}
\end{array}
if y < 2.45e-5Initial program 100.0%
Taylor expanded in y around 0 76.3%
if 2.45e-5 < y Initial program 100.0%
Taylor expanded in z around 0 93.3%
associate-*r/93.3%
+-commutative93.3%
Simplified93.3%
Final simplification81.0%
(FPCore (x y z t) :precision binary64 (if (<= x -1.06e-21) (* 0.5 (/ (- x z) t)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.06e-21) {
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 <= (-1.06d-21)) 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 <= -1.06e-21) {
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 <= -1.06e-21: 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 <= -1.06e-21) 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 <= -1.06e-21) 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, -1.06e-21], 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 -1.06 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if x < -1.05999999999999994e-21Initial program 100.0%
Taylor expanded in y around 0 78.7%
if -1.05999999999999994e-21 < x Initial program 100.0%
Taylor expanded in x around 0 76.7%
associate-*r/76.7%
Simplified76.7%
Final simplification77.2%
(FPCore (x y z t) :precision binary64 (if (<= x -1.65e-21) (* 0.5 (/ x t)) (* 0.5 (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.65e-21) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / 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 <= (-1.65d-21)) then
tmp = 0.5d0 * (x / t)
else
tmp = 0.5d0 * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.65e-21) {
tmp = 0.5 * (x / t);
} else {
tmp = 0.5 * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.65e-21: tmp = 0.5 * (x / t) else: tmp = 0.5 * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.65e-21) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(0.5 * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.65e-21) tmp = 0.5 * (x / t); else tmp = 0.5 * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.65e-21], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.65000000000000004e-21Initial program 100.0%
Taylor expanded in x around inf 67.6%
if -1.65000000000000004e-21 < x Initial program 100.0%
Taylor expanded in y around inf 45.1%
Final simplification50.8%
(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 37.9%
Final simplification37.9%
herbie shell --seed 2024043
(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)))