
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ y a) (- z t) x))
double code(double x, double y, double z, double t, double a) {
return fma((y / a), (z - t), x);
}
function code(x, y, z, t, a) return fma(Float64(y / a), Float64(z - t), x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / a), $MachinePrecision] * N[(z - t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)
\end{array}
Initial program 95.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.9
Applied rewrites96.9%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) a)))
(if (or (<= t_1 -1e+107) (not (<= t_1 4000000000.0)))
(* (/ y a) (- z t))
(fma (/ (- t) a) y x))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double tmp;
if ((t_1 <= -1e+107) || !(t_1 <= 4000000000.0)) {
tmp = (y / a) * (z - t);
} else {
tmp = fma((-t / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / a) tmp = 0.0 if ((t_1 <= -1e+107) || !(t_1 <= 4000000000.0)) tmp = Float64(Float64(y / a) * Float64(z - t)); else tmp = fma(Float64(Float64(-t) / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e+107], N[Not[LessEqual[t$95$1, 4000000000.0]], $MachinePrecision]], N[(N[(y / a), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision], N[(N[((-t) / a), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+107} \lor \neg \left(t\_1 \leq 4000000000\right):\\
\;\;\;\;\frac{y}{a} \cdot \left(z - t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-t}{a}, y, x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) a) < -9.9999999999999997e106 or 4e9 < (/.f64 (*.f64 y (-.f64 z t)) a) Initial program 91.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.4
Applied rewrites86.4%
Applied rewrites91.6%
if -9.9999999999999997e106 < (/.f64 (*.f64 y (-.f64 z t)) a) < 4e9Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
associate-*l/N/A
associate-*l*N/A
neg-mul-1N/A
lower-fma.f64N/A
distribute-neg-fracN/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.4
Applied rewrites92.4%
Final simplification92.0%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) a)))
(if (or (<= t_1 -1e+107) (not (<= t_1 50000000000000.0)))
(* (/ y a) (- z t))
(fma (/ y a) z x))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double tmp;
if ((t_1 <= -1e+107) || !(t_1 <= 50000000000000.0)) {
tmp = (y / a) * (z - t);
} else {
tmp = fma((y / a), z, x);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / a) tmp = 0.0 if ((t_1 <= -1e+107) || !(t_1 <= 50000000000000.0)) tmp = Float64(Float64(y / a) * Float64(z - t)); else tmp = fma(Float64(y / a), z, x); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e+107], N[Not[LessEqual[t$95$1, 50000000000000.0]], $MachinePrecision]], N[(N[(y / a), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+107} \lor \neg \left(t\_1 \leq 50000000000000\right):\\
\;\;\;\;\frac{y}{a} \cdot \left(z - t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) a) < -9.9999999999999997e106 or 5e13 < (/.f64 (*.f64 y (-.f64 z t)) a) Initial program 91.1%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.8
Applied rewrites86.8%
Applied rewrites92.2%
if -9.9999999999999997e106 < (/.f64 (*.f64 y (-.f64 z t)) a) < 5e13Initial program 99.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6484.0
Applied rewrites84.0%
Final simplification88.5%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1.55e+93) (not (<= t 4.9e+147))) (* (/ (- t) a) y) (fma (/ y a) z x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1.55e+93) || !(t <= 4.9e+147)) {
tmp = (-t / a) * y;
} else {
tmp = fma((y / a), z, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1.55e+93) || !(t <= 4.9e+147)) tmp = Float64(Float64(Float64(-t) / a) * y); else tmp = fma(Float64(y / a), z, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1.55e+93], N[Not[LessEqual[t, 4.9e+147]], $MachinePrecision]], N[(N[((-t) / a), $MachinePrecision] * y), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.55 \cdot 10^{+93} \lor \neg \left(t \leq 4.9 \cdot 10^{+147}\right):\\
\;\;\;\;\frac{-t}{a} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\end{array}
\end{array}
if t < -1.5500000000000001e93 or 4.8999999999999998e147 < t Initial program 93.6%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.4
Applied rewrites77.4%
Taylor expanded in z around 0
Applied rewrites64.2%
if -1.5500000000000001e93 < t < 4.8999999999999998e147Initial program 95.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
Final simplification77.4%
(FPCore (x y z t a) :precision binary64 (if (<= t -1.55e+93) (* (/ y a) (- t)) (if (<= t 4.9e+147) (fma (/ y a) z x) (* (/ (- t) a) y))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.55e+93) {
tmp = (y / a) * -t;
} else if (t <= 4.9e+147) {
tmp = fma((y / a), z, x);
} else {
tmp = (-t / a) * y;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -1.55e+93) tmp = Float64(Float64(y / a) * Float64(-t)); elseif (t <= 4.9e+147) tmp = fma(Float64(y / a), z, x); else tmp = Float64(Float64(Float64(-t) / a) * y); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -1.55e+93], N[(N[(y / a), $MachinePrecision] * (-t)), $MachinePrecision], If[LessEqual[t, 4.9e+147], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision], N[(N[((-t) / a), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.55 \cdot 10^{+93}:\\
\;\;\;\;\frac{y}{a} \cdot \left(-t\right)\\
\mathbf{elif}\;t \leq 4.9 \cdot 10^{+147}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-t}{a} \cdot y\\
\end{array}
\end{array}
if t < -1.5500000000000001e93Initial program 93.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.3
Applied rewrites75.3%
Taylor expanded in z around 0
Applied rewrites65.9%
Applied rewrites66.4%
if -1.5500000000000001e93 < t < 4.8999999999999998e147Initial program 95.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if 4.8999999999999998e147 < t Initial program 94.6%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.6
Applied rewrites80.6%
Taylor expanded in z around 0
Applied rewrites72.0%
(FPCore (x y z t a) :precision binary64 (fma (/ y a) z x))
double code(double x, double y, double z, double t, double a) {
return fma((y / a), z, x);
}
function code(x, y, z, t, a) return fma(Float64(y / a), z, x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{a}, z, x\right)
\end{array}
Initial program 95.1%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6466.3
Applied rewrites66.3%
(FPCore (x y z t a) :precision binary64 (* z (/ y a)))
double code(double x, double y, double z, double t, double a) {
return z * (y / a);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = z * (y / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return z * (y / a);
}
def code(x, y, z, t, a): return z * (y / a)
function code(x, y, z, t, a) return Float64(z * Float64(y / a)) end
function tmp = code(x, y, z, t, a) tmp = z * (y / a); end
code[x_, y_, z_, t_, a_] := N[(z * N[(y / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{y}{a}
\end{array}
Initial program 95.1%
Taylor expanded in z around inf
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6426.0
Applied rewrites26.0%
Applied rewrites30.0%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ a (- z t))))
(if (< y -1.0761266216389975e-10)
(+ x (/ 1.0 (/ t_1 y)))
(if (< y 2.894426862792089e-49)
(+ x (/ (* y (- z t)) a))
(+ x (/ y t_1))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x + (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x + ((y * (z - t)) / a);
} else {
tmp = x + (y / t_1);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = a / (z - t)
if (y < (-1.0761266216389975d-10)) then
tmp = x + (1.0d0 / (t_1 / y))
else if (y < 2.894426862792089d-49) then
tmp = x + ((y * (z - t)) / a)
else
tmp = x + (y / t_1)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x + (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x + ((y * (z - t)) / a);
} else {
tmp = x + (y / t_1);
}
return tmp;
}
def code(x, y, z, t, a): t_1 = a / (z - t) tmp = 0 if y < -1.0761266216389975e-10: tmp = x + (1.0 / (t_1 / y)) elif y < 2.894426862792089e-49: tmp = x + ((y * (z - t)) / a) else: tmp = x + (y / t_1) return tmp
function code(x, y, z, t, a) t_1 = Float64(a / Float64(z - t)) tmp = 0.0 if (y < -1.0761266216389975e-10) tmp = Float64(x + Float64(1.0 / Float64(t_1 / y))); elseif (y < 2.894426862792089e-49) tmp = Float64(x + Float64(Float64(y * Float64(z - t)) / a)); else tmp = Float64(x + Float64(y / t_1)); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = a / (z - t); tmp = 0.0; if (y < -1.0761266216389975e-10) tmp = x + (1.0 / (t_1 / y)); elseif (y < 2.894426862792089e-49) tmp = x + ((y * (z - t)) / a); else tmp = x + (y / t_1); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(a / N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[Less[y, -1.0761266216389975e-10], N[(x + N[(1.0 / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Less[y, 2.894426862792089e-49], N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{a}{z - t}\\
\mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\
\;\;\;\;x + \frac{1}{\frac{t\_1}{y}}\\
\mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\
\;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t\_1}\\
\end{array}
\end{array}
herbie shell --seed 2024318
(FPCore (x y z t a)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
:precision binary64
:alt
(! :herbie-platform default (if (< y -430450648655599/4000000000000000000000000) (+ x (/ 1 (/ (/ a (- z t)) y))) (if (< y 2894426862792089/10000000000000000000000000000000000000000000000000000000000000000) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t)))))))
(+ x (/ (* y (- z t)) a)))