
(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 -8.5e+24)
(/ x (* t 2.0))
(if (or (<= x -6.3e-73) (and (not (<= x -3.35e-121)) (<= x 3e-284)))
(* (/ z t) -0.5)
(/ y (* t 2.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -8.5e+24) {
tmp = x / (t * 2.0);
} else if ((x <= -6.3e-73) || (!(x <= -3.35e-121) && (x <= 3e-284))) {
tmp = (z / t) * -0.5;
} else {
tmp = y / (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 (x <= (-8.5d+24)) then
tmp = x / (t * 2.0d0)
else if ((x <= (-6.3d-73)) .or. (.not. (x <= (-3.35d-121))) .and. (x <= 3d-284)) then
tmp = (z / t) * (-0.5d0)
else
tmp = y / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -8.5e+24) {
tmp = x / (t * 2.0);
} else if ((x <= -6.3e-73) || (!(x <= -3.35e-121) && (x <= 3e-284))) {
tmp = (z / t) * -0.5;
} else {
tmp = y / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -8.5e+24: tmp = x / (t * 2.0) elif (x <= -6.3e-73) or (not (x <= -3.35e-121) and (x <= 3e-284)): tmp = (z / t) * -0.5 else: tmp = y / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -8.5e+24) tmp = Float64(x / Float64(t * 2.0)); elseif ((x <= -6.3e-73) || (!(x <= -3.35e-121) && (x <= 3e-284))) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(y / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -8.5e+24) tmp = x / (t * 2.0); elseif ((x <= -6.3e-73) || (~((x <= -3.35e-121)) && (x <= 3e-284))) tmp = (z / t) * -0.5; else tmp = y / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -8.5e+24], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -6.3e-73], And[N[Not[LessEqual[x, -3.35e-121]], $MachinePrecision], LessEqual[x, 3e-284]]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{+24}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{elif}\;x \leq -6.3 \cdot 10^{-73} \lor \neg \left(x \leq -3.35 \cdot 10^{-121}\right) \land x \leq 3 \cdot 10^{-284}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t \cdot 2}\\
\end{array}
\end{array}
if x < -8.49999999999999959e24Initial program 100.0%
Taylor expanded in x around inf 63.1%
if -8.49999999999999959e24 < x < -6.29999999999999956e-73 or -3.3500000000000001e-121 < x < 3e-284Initial program 100.0%
Taylor expanded in z around inf 55.3%
*-commutative55.3%
Simplified55.3%
if -6.29999999999999956e-73 < x < -3.3500000000000001e-121 or 3e-284 < x Initial program 100.0%
Taylor expanded in y around inf 44.8%
Final simplification52.1%
(FPCore (x y z t)
:precision binary64
(if (<= y 1.9e+47)
(/ (- x z) (* t 2.0))
(if (or (<= y 1.5e+68) (not (<= y 1.5e+77)))
(/ (+ x y) (* t 2.0))
(* (/ z t) -0.5))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e+47) {
tmp = (x - z) / (t * 2.0);
} else if ((y <= 1.5e+68) || !(y <= 1.5e+77)) {
tmp = (x + y) / (t * 2.0);
} else {
tmp = (z / t) * -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 <= 1.9d+47) then
tmp = (x - z) / (t * 2.0d0)
else if ((y <= 1.5d+68) .or. (.not. (y <= 1.5d+77))) then
tmp = (x + y) / (t * 2.0d0)
else
tmp = (z / t) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e+47) {
tmp = (x - z) / (t * 2.0);
} else if ((y <= 1.5e+68) || !(y <= 1.5e+77)) {
tmp = (x + y) / (t * 2.0);
} else {
tmp = (z / t) * -0.5;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.9e+47: tmp = (x - z) / (t * 2.0) elif (y <= 1.5e+68) or not (y <= 1.5e+77): tmp = (x + y) / (t * 2.0) else: tmp = (z / t) * -0.5 return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.9e+47) tmp = Float64(Float64(x - z) / Float64(t * 2.0)); elseif ((y <= 1.5e+68) || !(y <= 1.5e+77)) tmp = Float64(Float64(x + y) / Float64(t * 2.0)); else tmp = Float64(Float64(z / t) * -0.5); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.9e+47) tmp = (x - z) / (t * 2.0); elseif ((y <= 1.5e+68) || ~((y <= 1.5e+77))) tmp = (x + y) / (t * 2.0); else tmp = (z / t) * -0.5; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.9e+47], N[(N[(x - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.5e+68], N[Not[LessEqual[y, 1.5e+77]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{+47}:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+68} \lor \neg \left(y \leq 1.5 \cdot 10^{+77}\right):\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\end{array}
\end{array}
if y < 1.9000000000000002e47Initial program 100.0%
Taylor expanded in y around 0 75.5%
if 1.9000000000000002e47 < y < 1.5000000000000001e68 or 1.4999999999999999e77 < y Initial program 99.9%
Taylor expanded in z around 0 86.9%
+-commutative86.9%
Simplified86.9%
if 1.5000000000000001e68 < y < 1.4999999999999999e77Initial program 100.0%
Taylor expanded in z around inf 93.8%
*-commutative93.8%
Simplified93.8%
Final simplification78.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.9e+181) (not (<= z 3.7e+207))) (* (/ z t) -0.5) (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.9e+181) || !(z <= 3.7e+207)) {
tmp = (z / t) * -0.5;
} else {
tmp = (x + y) / (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 ((z <= (-5.9d+181)) .or. (.not. (z <= 3.7d+207))) then
tmp = (z / t) * (-0.5d0)
else
tmp = (x + y) / (t * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.9e+181) || !(z <= 3.7e+207)) {
tmp = (z / t) * -0.5;
} else {
tmp = (x + y) / (t * 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -5.9e+181) or not (z <= 3.7e+207): tmp = (z / t) * -0.5 else: tmp = (x + y) / (t * 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -5.9e+181) || !(z <= 3.7e+207)) tmp = Float64(Float64(z / t) * -0.5); else tmp = Float64(Float64(x + y) / Float64(t * 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -5.9e+181) || ~((z <= 3.7e+207))) tmp = (z / t) * -0.5; else tmp = (x + y) / (t * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -5.9e+181], N[Not[LessEqual[z, 3.7e+207]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{+181} \lor \neg \left(z \leq 3.7 \cdot 10^{+207}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\
\end{array}
\end{array}
if z < -5.8999999999999997e181 or 3.7e207 < z Initial program 100.0%
Taylor expanded in z around inf 88.9%
*-commutative88.9%
Simplified88.9%
if -5.8999999999999997e181 < z < 3.7e207Initial program 100.0%
Taylor expanded in z around 0 81.8%
+-commutative81.8%
Simplified81.8%
Final simplification83.1%
(FPCore (x y z t) :precision binary64 (if (<= y 1850000.0) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1850000.0) {
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 <= 1850000.0d0) 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 <= 1850000.0) {
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 <= 1850000.0: 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 (y <= 1850000.0) 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 <= 1850000.0) 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[y, 1850000.0], 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 \leq 1850000:\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t \cdot 2}\\
\end{array}
\end{array}
if y < 1.85e6Initial program 100.0%
Taylor expanded in y around 0 75.1%
if 1.85e6 < y Initial program 100.0%
Taylor expanded in x around 0 84.4%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (if (<= x -8.5e+24) (/ x (* t 2.0)) (* (/ z t) -0.5)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -8.5e+24) {
tmp = x / (t * 2.0);
} else {
tmp = (z / t) * -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 (x <= (-8.5d+24)) then
tmp = x / (t * 2.0d0)
else
tmp = (z / t) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -8.5e+24) {
tmp = x / (t * 2.0);
} else {
tmp = (z / t) * -0.5;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -8.5e+24: tmp = x / (t * 2.0) else: tmp = (z / t) * -0.5 return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -8.5e+24) tmp = Float64(x / Float64(t * 2.0)); else tmp = Float64(Float64(z / t) * -0.5); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -8.5e+24) tmp = x / (t * 2.0); else tmp = (z / t) * -0.5; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -8.5e+24], N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{+24}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\
\end{array}
\end{array}
if x < -8.49999999999999959e24Initial program 100.0%
Taylor expanded in x around inf 63.1%
if -8.49999999999999959e24 < x Initial program 100.0%
Taylor expanded in z around inf 39.8%
*-commutative39.8%
Simplified39.8%
Final simplification45.8%
(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 35.9%
associate-*r/35.9%
metadata-eval35.9%
distribute-lft-neg-in35.9%
*-commutative35.9%
distribute-neg-frac35.9%
associate-*r/35.8%
distribute-rgt-neg-in35.8%
distribute-neg-frac35.8%
metadata-eval35.8%
Simplified35.8%
Final simplification35.8%
(FPCore (x y z t) :precision binary64 (* (/ z t) -0.5))
double code(double x, double y, double z, double t) {
return (z / t) * -0.5;
}
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 / t) * (-0.5d0)
end function
public static double code(double x, double y, double z, double t) {
return (z / t) * -0.5;
}
def code(x, y, z, t): return (z / t) * -0.5
function code(x, y, z, t) return Float64(Float64(z / t) * -0.5) end
function tmp = code(x, y, z, t) tmp = (z / t) * -0.5; end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{z}{t} \cdot -0.5
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 35.9%
*-commutative35.9%
Simplified35.9%
Final simplification35.9%
herbie shell --seed 2024096
(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)))