
(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 8 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 (/ (- z x) (/ t y))))
double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
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 + ((z - x) / (t / y))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
def code(x, y, z, t): return x + ((z - x) / (t / y))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) / Float64(t / y))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) / (t / y)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z - x}{\frac{t}{y}}
\end{array}
Initial program 92.5%
associate-*l/98.0%
Simplified98.0%
*-commutative98.0%
clear-num98.0%
un-div-inv98.1%
Applied egg-rr98.1%
Final simplification98.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.6e-27) (not (<= x 1.25e-12))) (* x (- 1.0 (/ y t))) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.6e-27) || !(x <= 1.25e-12)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z * (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.6d-27)) .or. (.not. (x <= 1.25d-12))) then
tmp = x * (1.0d0 - (y / t))
else
tmp = x + (z * (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.6e-27) || !(x <= 1.25e-12)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.6e-27) or not (x <= 1.25e-12): tmp = x * (1.0 - (y / t)) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.6e-27) || !(x <= 1.25e-12)) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(z * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.6e-27) || ~((x <= 1.25e-12))) tmp = x * (1.0 - (y / t)); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.6e-27], N[Not[LessEqual[x, 1.25e-12]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-27} \lor \neg \left(x \leq 1.25 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.59999999999999995e-27 or 1.24999999999999992e-12 < x Initial program 92.6%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 88.6%
mul-1-neg88.6%
unsub-neg88.6%
Simplified88.6%
if -1.59999999999999995e-27 < x < 1.24999999999999992e-12Initial program 92.3%
associate-*l/95.7%
Simplified95.7%
Taylor expanded in z around inf 86.2%
associate-*l/91.2%
*-commutative91.2%
Simplified91.2%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (<= x -7.8e-28) (* x (- 1.0 (/ y t))) (if (<= x 1.25e-12) (+ x (* z (/ y t))) (- x (* x (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -7.8e-28) {
tmp = x * (1.0 - (y / t));
} else if (x <= 1.25e-12) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (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 <= (-7.8d-28)) then
tmp = x * (1.0d0 - (y / t))
else if (x <= 1.25d-12) then
tmp = x + (z * (y / t))
else
tmp = x - (x * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -7.8e-28) {
tmp = x * (1.0 - (y / t));
} else if (x <= 1.25e-12) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -7.8e-28: tmp = x * (1.0 - (y / t)) elif x <= 1.25e-12: tmp = x + (z * (y / t)) else: tmp = x - (x * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -7.8e-28) tmp = Float64(x * Float64(1.0 - Float64(y / t))); elseif (x <= 1.25e-12) tmp = Float64(x + Float64(z * Float64(y / t))); else tmp = Float64(x - Float64(x * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -7.8e-28) tmp = x * (1.0 - (y / t)); elseif (x <= 1.25e-12) tmp = x + (z * (y / t)); else tmp = x - (x * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -7.8e-28], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.25e-12], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-28}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-12}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -7.79999999999999998e-28Initial program 90.3%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 90.2%
mul-1-neg90.2%
unsub-neg90.2%
Simplified90.2%
if -7.79999999999999998e-28 < x < 1.24999999999999992e-12Initial program 92.3%
associate-*l/95.7%
Simplified95.7%
Taylor expanded in z around inf 86.2%
associate-*l/91.2%
*-commutative91.2%
Simplified91.2%
if 1.24999999999999992e-12 < x Initial program 94.8%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in z around 0 85.8%
mul-1-neg85.8%
associate-/l*87.1%
distribute-neg-frac87.1%
Simplified87.1%
distribute-frac-neg87.1%
unsub-neg87.1%
div-inv87.1%
clear-num87.1%
Applied egg-rr87.1%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (<= x -3e-28) (- x (/ x (/ t y))) (if (<= x 3.2e-13) (+ x (* z (/ y t))) (- x (* x (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3e-28) {
tmp = x - (x / (t / y));
} else if (x <= 3.2e-13) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (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 <= (-3d-28)) then
tmp = x - (x / (t / y))
else if (x <= 3.2d-13) then
tmp = x + (z * (y / t))
else
tmp = x - (x * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3e-28) {
tmp = x - (x / (t / y));
} else if (x <= 3.2e-13) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3e-28: tmp = x - (x / (t / y)) elif x <= 3.2e-13: tmp = x + (z * (y / t)) else: tmp = x - (x * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3e-28) tmp = Float64(x - Float64(x / Float64(t / y))); elseif (x <= 3.2e-13) tmp = Float64(x + Float64(z * Float64(y / t))); else tmp = Float64(x - Float64(x * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -3e-28) tmp = x - (x / (t / y)); elseif (x <= 3.2e-13) tmp = x + (z * (y / t)); else tmp = x - (x * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3e-28], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.2e-13], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-28}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-13}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -3.00000000000000003e-28Initial program 90.3%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in z around 0 80.5%
mul-1-neg80.5%
associate-/l*90.2%
distribute-neg-frac90.2%
Simplified90.2%
distribute-frac-neg90.2%
unsub-neg90.2%
div-inv90.2%
clear-num90.2%
Applied egg-rr90.2%
clear-num90.2%
un-div-inv90.2%
Applied egg-rr90.2%
if -3.00000000000000003e-28 < x < 3.2e-13Initial program 92.3%
associate-*l/95.7%
Simplified95.7%
Taylor expanded in z around inf 86.2%
associate-*l/91.2%
*-commutative91.2%
Simplified91.2%
if 3.2e-13 < x Initial program 94.8%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in z around 0 85.8%
mul-1-neg85.8%
associate-/l*87.1%
distribute-neg-frac87.1%
Simplified87.1%
distribute-frac-neg87.1%
unsub-neg87.1%
div-inv87.1%
clear-num87.1%
Applied egg-rr87.1%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (<= t -1.5e+20) x (if (<= t 5.6e-131) (* (/ y t) (- x)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.5e+20) {
tmp = x;
} else if (t <= 5.6e-131) {
tmp = (y / t) * -x;
} 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 <= (-1.5d+20)) then
tmp = x
else if (t <= 5.6d-131) then
tmp = (y / t) * -x
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 <= -1.5e+20) {
tmp = x;
} else if (t <= 5.6e-131) {
tmp = (y / t) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.5e+20: tmp = x elif t <= 5.6e-131: tmp = (y / t) * -x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.5e+20) tmp = x; elseif (t <= 5.6e-131) tmp = Float64(Float64(y / t) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.5e+20) tmp = x; elseif (t <= 5.6e-131) tmp = (y / t) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.5e+20], x, If[LessEqual[t, 5.6e-131], N[(N[(y / t), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.5 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.6 \cdot 10^{-131}:\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -1.5e20 or 5.5999999999999999e-131 < t Initial program 89.6%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in y around 0 64.2%
if -1.5e20 < t < 5.5999999999999999e-131Initial program 96.9%
associate-*l/96.1%
Simplified96.1%
Taylor expanded in z around 0 63.2%
mul-1-neg63.2%
associate-/l*62.3%
distribute-neg-frac62.3%
Simplified62.3%
distribute-frac-neg62.3%
unsub-neg62.3%
div-inv62.3%
clear-num62.3%
Applied egg-rr62.3%
Taylor expanded in y around inf 53.9%
mul-1-neg53.9%
associate-*r/53.0%
*-commutative53.0%
distribute-rgt-neg-in53.0%
Simplified53.0%
Final simplification59.9%
(FPCore (x y z t) :precision binary64 (+ x (* (- z x) (/ y t))))
double code(double x, double y, double z, double t) {
return x + ((z - x) * (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 + ((z - x) * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) * (y / t));
}
def code(x, y, z, t): return x + ((z - x) * (y / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z - x\right) \cdot \frac{y}{t}
\end{array}
Initial program 92.5%
associate-*l/98.0%
Simplified98.0%
Final simplification98.0%
(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 92.5%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in x around inf 70.2%
mul-1-neg70.2%
unsub-neg70.2%
Simplified70.2%
Final simplification70.2%
(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 92.5%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in y around 0 43.7%
Final simplification43.7%
(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 2024021
(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)))