
(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 (/ (- y (- z x)) (* t 2.0)))
double code(double x, double y, double z, double t) {
return (y - (z - x)) / (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 = (y - (z - x)) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (y - (z - x)) / (t * 2.0);
}
def code(x, y, z, t): return (y - (z - x)) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(y - Float64(z - x)) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = (y - (z - x)) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(y - N[(z - x), $MachinePrecision]), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y - \left(z - x\right)}{t \cdot 2}
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
associate-+l-N/A
lower--.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z t) :precision binary64 (if (<= (+ y x) -100.0) (/ (* x 0.5) t) (if (<= (+ y x) 1e-21) (/ (* z -0.5) t) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= -100.0) {
tmp = (x * 0.5) / t;
} else if ((y + x) <= 1e-21) {
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 ((y + x) <= (-100.0d0)) then
tmp = (x * 0.5d0) / t
else if ((y + x) <= 1d-21) 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 ((y + x) <= -100.0) {
tmp = (x * 0.5) / t;
} else if ((y + x) <= 1e-21) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y + x) <= -100.0: tmp = (x * 0.5) / t elif (y + x) <= 1e-21: tmp = (z * -0.5) / t else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y + x) <= -100.0) tmp = Float64(Float64(x * 0.5) / t); elseif (Float64(y + x) <= 1e-21) 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 ((y + x) <= -100.0) tmp = (x * 0.5) / t; elseif ((y + x) <= 1e-21) tmp = (z * -0.5) / t; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y + x), $MachinePrecision], -100.0], N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision], If[LessEqual[N[(y + x), $MachinePrecision], 1e-21], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y + x \leq -100:\\
\;\;\;\;\frac{x \cdot 0.5}{t}\\
\mathbf{elif}\;y + x \leq 10^{-21}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < -100Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6442.5
Applied rewrites42.5%
if -100 < (+.f64 x y) < 9.99999999999999908e-22Initial program 100.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6484.6
Applied rewrites84.6%
if 9.99999999999999908e-22 < (+.f64 x y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6442.5
Applied rewrites42.5%
Final simplification49.9%
(FPCore (x y z t) :precision binary64 (if (<= (+ y x) -100.0) (/ (* x 0.5) t) (if (<= (+ y x) 1e-21) (* z (/ -0.5 t)) (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= -100.0) {
tmp = (x * 0.5) / t;
} else if ((y + x) <= 1e-21) {
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 ((y + x) <= (-100.0d0)) then
tmp = (x * 0.5d0) / t
else if ((y + x) <= 1d-21) 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 ((y + x) <= -100.0) {
tmp = (x * 0.5) / t;
} else if ((y + x) <= 1e-21) {
tmp = z * (-0.5 / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y + x) <= -100.0: tmp = (x * 0.5) / t elif (y + x) <= 1e-21: tmp = z * (-0.5 / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y + x) <= -100.0) tmp = Float64(Float64(x * 0.5) / t); elseif (Float64(y + x) <= 1e-21) 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 ((y + x) <= -100.0) tmp = (x * 0.5) / t; elseif ((y + x) <= 1e-21) tmp = z * (-0.5 / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y + x), $MachinePrecision], -100.0], N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision], If[LessEqual[N[(y + x), $MachinePrecision], 1e-21], N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y + x \leq -100:\\
\;\;\;\;\frac{x \cdot 0.5}{t}\\
\mathbf{elif}\;y + x \leq 10^{-21}:\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < -100Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6442.5
Applied rewrites42.5%
if -100 < (+.f64 x y) < 9.99999999999999908e-22Initial program 100.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6484.6
Applied rewrites84.6%
Applied rewrites84.5%
if 9.99999999999999908e-22 < (+.f64 x y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6442.5
Applied rewrites42.5%
Final simplification49.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (/ (* z -0.5) t))) (if (<= z -1.5e+19) t_1 (if (<= z 8.2e+182) (/ (+ y x) (* t 2.0)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (z * -0.5) / t;
double tmp;
if (z <= -1.5e+19) {
tmp = t_1;
} else if (z <= 8.2e+182) {
tmp = (y + x) / (t * 2.0);
} else {
tmp = t_1;
}
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 = (z * (-0.5d0)) / t
if (z <= (-1.5d+19)) then
tmp = t_1
else if (z <= 8.2d+182) then
tmp = (y + x) / (t * 2.0d0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * -0.5) / t;
double tmp;
if (z <= -1.5e+19) {
tmp = t_1;
} else if (z <= 8.2e+182) {
tmp = (y + x) / (t * 2.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * -0.5) / t tmp = 0 if z <= -1.5e+19: tmp = t_1 elif z <= 8.2e+182: tmp = (y + x) / (t * 2.0) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * -0.5) / t) tmp = 0.0 if (z <= -1.5e+19) tmp = t_1; elseif (z <= 8.2e+182) tmp = Float64(Float64(y + x) / Float64(t * 2.0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * -0.5) / t; tmp = 0.0; if (z <= -1.5e+19) tmp = t_1; elseif (z <= 8.2e+182) tmp = (y + x) / (t * 2.0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision]}, If[LessEqual[z, -1.5e+19], t$95$1, If[LessEqual[z, 8.2e+182], N[(N[(y + x), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z \cdot -0.5}{t}\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+19}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{+182}:\\
\;\;\;\;\frac{y + x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.5e19 or 8.20000000000000006e182 < z Initial program 100.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6476.3
Applied rewrites76.3%
if -1.5e19 < z < 8.20000000000000006e182Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6488.7
Applied rewrites88.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (/ -0.5 t)))) (if (<= z -65000.0) t_1 (if (<= z 5.8e+114) (/ (* x 0.5) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * (-0.5 / t);
double tmp;
if (z <= -65000.0) {
tmp = t_1;
} else if (z <= 5.8e+114) {
tmp = (x * 0.5) / t;
} else {
tmp = t_1;
}
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 = z * ((-0.5d0) / t)
if (z <= (-65000.0d0)) then
tmp = t_1
else if (z <= 5.8d+114) then
tmp = (x * 0.5d0) / t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z * (-0.5 / t);
double tmp;
if (z <= -65000.0) {
tmp = t_1;
} else if (z <= 5.8e+114) {
tmp = (x * 0.5) / t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = z * (-0.5 / t) tmp = 0 if z <= -65000.0: tmp = t_1 elif z <= 5.8e+114: tmp = (x * 0.5) / t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(z * Float64(-0.5 / t)) tmp = 0.0 if (z <= -65000.0) tmp = t_1; elseif (z <= 5.8e+114) tmp = Float64(Float64(x * 0.5) / t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z * (-0.5 / t); tmp = 0.0; if (z <= -65000.0) tmp = t_1; elseif (z <= 5.8e+114) tmp = (x * 0.5) / t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -65000.0], t$95$1, If[LessEqual[z, 5.8e+114], N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \frac{-0.5}{t}\\
\mathbf{if}\;z \leq -65000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+114}:\\
\;\;\;\;\frac{x \cdot 0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -65000 or 5.8000000000000001e114 < z Initial program 100.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6471.4
Applied rewrites71.4%
Applied rewrites71.3%
if -65000 < z < 5.8000000000000001e114Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6453.1
Applied rewrites53.1%
Final simplification60.5%
(FPCore (x y z t) :precision binary64 (if (<= (+ y x) -5e-119) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= -5e-119) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
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 + x) <= (-5d-119)) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (y - z) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= -5e-119) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y - z) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y + x) <= -5e-119: tmp = (x - z) / (t * 2.0) else: tmp = (y - z) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y + x) <= -5e-119) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(y - z) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y + x) <= -5e-119) tmp = (x - z) / (t * 2.0); else tmp = (y - z) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y + x), $MachinePrecision], -5e-119], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y + x \leq -5 \cdot 10^{-119}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if (+.f64 x y) < -4.99999999999999993e-119Initial program 100.0%
Taylor expanded in y around 0
lower--.f6471.8
Applied rewrites71.8%
if -4.99999999999999993e-119 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
lower--.f6465.9
Applied rewrites65.9%
Final simplification68.8%
(FPCore (x y z t) :precision binary64 (if (<= (+ y x) 1e-21) (/ (- x z) (* t 2.0)) (/ (+ y x) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= 1e-21) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y + x) / (t * 2.0);
}
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 + x) <= 1d-21) then
tmp = (x - z) / (t * 2.0d0)
else
tmp = (y + x) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y + x) <= 1e-21) {
tmp = (x - z) / (t * 2.0);
} else {
tmp = (y + x) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y + x) <= 1e-21: tmp = (x - z) / (t * 2.0) else: tmp = (y + x) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y + x) <= 1e-21) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); else tmp = Float64(Float64(y + x) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y + x) <= 1e-21) tmp = (x - z) / (t * 2.0); else tmp = (y + x) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y + x), $MachinePrecision], 1e-21], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(y + x), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y + x \leq 10^{-21}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y + x}{t \cdot 2}\\
\end{array}
\end{array}
if (+.f64 x y) < 9.99999999999999908e-22Initial program 100.0%
Taylor expanded in y around 0
lower--.f6476.3
Applied rewrites76.3%
if 9.99999999999999908e-22 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6482.0
Applied rewrites82.0%
Final simplification78.6%
(FPCore (x y z t) :precision binary64 (* z (/ -0.5 t)))
double code(double x, double y, double z, double t) {
return z * (-0.5 / 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 = z * ((-0.5d0) / t)
end function
public static double code(double x, double y, double z, double t) {
return z * (-0.5 / t);
}
def code(x, y, z, t): return z * (-0.5 / t)
function code(x, y, z, t) return Float64(z * Float64(-0.5 / t)) end
function tmp = code(x, y, z, t) tmp = z * (-0.5 / t); end
code[x_, y_, z_, t_] := N[(z * N[(-0.5 / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{-0.5}{t}
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6437.2
Applied rewrites37.2%
Applied rewrites37.2%
Final simplification37.2%
herbie shell --seed 2024220
(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)))