
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - 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 = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - 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 = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (/ y t) (- z x))))
double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
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 / t) * (z - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
def code(x, y, z, t): return x + ((y / t) * (z - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * Float64(z - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * (z - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot \left(z - x\right)
\end{array}
Initial program 93.6%
associate-*l/99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.35e+29) (not (<= x 5.2e+91))) (* x (- 1.0 (/ y t))) (+ x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.35e+29) || !(x <= 5.2e+91)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
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.35d+29)) .or. (.not. (x <= 5.2d+91))) then
tmp = x * (1.0d0 - (y / t))
else
tmp = x + ((y / t) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.35e+29) || !(x <= 5.2e+91)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.35e+29) or not (x <= 5.2e+91): tmp = x * (1.0 - (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.35e+29) || !(x <= 5.2e+91)) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.35e+29) || ~((x <= 5.2e+91))) tmp = x * (1.0 - (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.35e+29], N[Not[LessEqual[x, 5.2e+91]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+29} \lor \neg \left(x \leq 5.2 \cdot 10^{+91}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if x < -1.35e29 or 5.2000000000000001e91 < x Initial program 91.8%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
if -1.35e29 < x < 5.2000000000000001e91Initial program 94.6%
associate-*l/98.7%
Simplified98.7%
Taylor expanded in z around inf 81.6%
associate-*l/87.5%
*-commutative87.5%
Simplified87.5%
Final simplification89.5%
(FPCore (x y z t) :precision binary64 (if (<= t -4.6e-14) x (if (<= t 5.8e-56) (/ (- x) (/ t y)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -4.6e-14) {
tmp = x;
} else if (t <= 5.8e-56) {
tmp = -x / (t / y);
} else {
tmp = x;
}
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 (t <= (-4.6d-14)) then
tmp = x
else if (t <= 5.8d-56) then
tmp = -x / (t / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -4.6e-14) {
tmp = x;
} else if (t <= 5.8e-56) {
tmp = -x / (t / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -4.6e-14: tmp = x elif t <= 5.8e-56: tmp = -x / (t / y) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -4.6e-14) tmp = x; elseif (t <= 5.8e-56) tmp = Float64(Float64(-x) / Float64(t / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -4.6e-14) tmp = x; elseif (t <= 5.8e-56) tmp = -x / (t / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -4.6e-14], x, If[LessEqual[t, 5.8e-56], N[((-x) / N[(t / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.6 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.8 \cdot 10^{-56}:\\
\;\;\;\;\frac{-x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -4.59999999999999996e-14 or 5.79999999999999982e-56 < t Initial program 89.4%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in y around 0 61.4%
if -4.59999999999999996e-14 < t < 5.79999999999999982e-56Initial program 99.0%
associate-*l/98.2%
Simplified98.2%
Taylor expanded in x around inf 60.1%
mul-1-neg60.1%
unsub-neg60.1%
Simplified60.1%
Taylor expanded in y around inf 49.4%
associate-*r/49.4%
neg-mul-149.4%
Simplified49.4%
distribute-frac-neg49.4%
distribute-rgt-neg-out49.4%
add-sqr-sqrt17.9%
sqrt-unprod16.5%
sqr-neg16.5%
sqrt-unprod2.6%
add-sqr-sqrt7.0%
clear-num7.0%
un-div-inv7.0%
add-sqr-sqrt2.6%
sqrt-unprod16.5%
sqr-neg16.5%
sqrt-unprod17.9%
add-sqr-sqrt48.6%
Applied egg-rr48.6%
Final simplification55.8%
(FPCore (x y z t) :precision binary64 (if (<= t -6.8e-15) x (if (<= t 3.2e-61) (* x (/ (- y) t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -6.8e-15) {
tmp = x;
} else if (t <= 3.2e-61) {
tmp = x * (-y / t);
} else {
tmp = x;
}
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 (t <= (-6.8d-15)) then
tmp = x
else if (t <= 3.2d-61) then
tmp = x * (-y / t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -6.8e-15) {
tmp = x;
} else if (t <= 3.2e-61) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -6.8e-15: tmp = x elif t <= 3.2e-61: tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -6.8e-15) tmp = x; elseif (t <= 3.2e-61) tmp = Float64(x * Float64(Float64(-y) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -6.8e-15) tmp = x; elseif (t <= 3.2e-61) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -6.8e-15], x, If[LessEqual[t, 3.2e-61], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -6.8 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 3.2 \cdot 10^{-61}:\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -6.8000000000000001e-15 or 3.2000000000000001e-61 < t Initial program 89.4%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in y around 0 61.4%
if -6.8000000000000001e-15 < t < 3.2000000000000001e-61Initial program 99.0%
associate-*l/98.2%
Simplified98.2%
Taylor expanded in x around inf 60.1%
mul-1-neg60.1%
unsub-neg60.1%
Simplified60.1%
Taylor expanded in y around inf 49.4%
associate-*r/49.4%
neg-mul-149.4%
Simplified49.4%
Final simplification56.1%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ y t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (y / 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 = x * (1.0d0 - (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (y / t));
}
def code(x, y, z, t): return x * (1.0 - (y / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (y / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{y}{t}\right)
\end{array}
Initial program 93.6%
associate-*l/99.1%
Simplified99.1%
Taylor expanded in x around inf 66.1%
mul-1-neg66.1%
unsub-neg66.1%
Simplified66.1%
Final simplification66.1%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 93.6%
associate-*l/99.1%
Simplified99.1%
Taylor expanded in y around 0 39.8%
Final simplification39.8%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / 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 = x - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2024040
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:herbie-target
(- x (+ (* x (/ y t)) (* (- z) (/ y t))))
(+ x (/ (* y (- z x)) t)))