
(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 91.4%
associate-*l/98.7%
Simplified98.7%
*-commutative98.7%
clear-num98.7%
un-div-inv98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x y z t) :precision binary64 (if (or (<= x -3.2e+36) (not (<= x 1.12e-27))) (* x (- 1.0 (/ y t))) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -3.2e+36) || !(x <= 1.12e-27)) {
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 <= (-3.2d+36)) .or. (.not. (x <= 1.12d-27))) 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 <= -3.2e+36) || !(x <= 1.12e-27)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -3.2e+36) or not (x <= 1.12e-27): 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 <= -3.2e+36) || !(x <= 1.12e-27)) 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 <= -3.2e+36) || ~((x <= 1.12e-27))) 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, -3.2e+36], N[Not[LessEqual[x, 1.12e-27]], $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 -3.2 \cdot 10^{+36} \lor \neg \left(x \leq 1.12 \cdot 10^{-27}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -3.1999999999999999e36 or 1.1199999999999999e-27 < x Initial program 88.6%
associate-*l/99.9%
Simplified99.9%
*-commutative99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 91.9%
*-commutative91.9%
mul-1-neg91.9%
sub-neg91.9%
Simplified91.9%
if -3.1999999999999999e36 < x < 1.1199999999999999e-27Initial program 93.8%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in z around inf 84.7%
associate-*l/88.8%
*-commutative88.8%
Simplified88.8%
Final simplification90.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.05e+44) (not (<= x 3.6e-27))) (* x (- 1.0 (/ y t))) (+ x (/ z (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.05e+44) || !(x <= 3.6e-27)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z / (t / y));
}
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.05d+44)) .or. (.not. (x <= 3.6d-27))) then
tmp = x * (1.0d0 - (y / t))
else
tmp = x + (z / (t / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.05e+44) || !(x <= 3.6e-27)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.05e+44) or not (x <= 3.6e-27): tmp = x * (1.0 - (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.05e+44) || !(x <= 3.6e-27)) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.05e+44) || ~((x <= 3.6e-27))) tmp = x * (1.0 - (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.05e+44], N[Not[LessEqual[x, 3.6e-27]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+44} \lor \neg \left(x \leq 3.6 \cdot 10^{-27}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if x < -1.04999999999999993e44 or 3.5999999999999999e-27 < x Initial program 88.6%
associate-*l/99.9%
Simplified99.9%
*-commutative99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 91.9%
*-commutative91.9%
mul-1-neg91.9%
sub-neg91.9%
Simplified91.9%
if -1.04999999999999993e44 < x < 3.5999999999999999e-27Initial program 93.8%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in z around inf 84.7%
associate-*l/88.8%
*-commutative88.8%
Simplified88.8%
clear-num88.8%
div-inv88.9%
Applied egg-rr88.9%
Final simplification90.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.6e+43) (not (<= x 3.6e-27))) (- x (* x (/ y t))) (+ x (/ z (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.6e+43) || !(x <= 3.6e-27)) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
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+43)) .or. (.not. (x <= 3.6d-27))) then
tmp = x - (x * (y / t))
else
tmp = x + (z / (t / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.6e+43) || !(x <= 3.6e-27)) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.6e+43) or not (x <= 3.6e-27): tmp = x - (x * (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.6e+43) || !(x <= 3.6e-27)) tmp = Float64(x - Float64(x * Float64(y / t))); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.6e+43) || ~((x <= 3.6e-27))) tmp = x - (x * (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.6e+43], N[Not[LessEqual[x, 3.6e-27]], $MachinePrecision]], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+43} \lor \neg \left(x \leq 3.6 \cdot 10^{-27}\right):\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if x < -1.60000000000000007e43 or 3.5999999999999999e-27 < x Initial program 88.6%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 91.9%
*-commutative91.9%
distribute-lft-in91.9%
*-rgt-identity91.9%
mul-1-neg91.9%
distribute-rgt-neg-in91.9%
unsub-neg91.9%
Simplified91.9%
if -1.60000000000000007e43 < x < 3.5999999999999999e-27Initial program 93.8%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in z around inf 84.7%
associate-*l/88.8%
*-commutative88.8%
Simplified88.8%
clear-num88.8%
div-inv88.9%
Applied egg-rr88.9%
Final simplification90.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+66) (not (<= y 8.6e-5))) (* x (/ (- y) t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+66) || !(y <= 8.6e-5)) {
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 ((y <= (-3d+66)) .or. (.not. (y <= 8.6d-5))) 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 ((y <= -3e+66) || !(y <= 8.6e-5)) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3e+66) or not (y <= 8.6e-5): tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+66) || !(y <= 8.6e-5)) 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 ((y <= -3e+66) || ~((y <= 8.6e-5))) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+66], N[Not[LessEqual[y, 8.6e-5]], $MachinePrecision]], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+66} \lor \neg \left(y \leq 8.6 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.00000000000000002e66 or 8.6000000000000003e-5 < y Initial program 82.7%
associate-*l/98.9%
Simplified98.9%
Taylor expanded in x around inf 60.0%
*-commutative60.0%
associate-*r/60.0%
neg-mul-160.0%
Simplified60.0%
Taylor expanded in y around inf 49.5%
associate-*r/49.5%
mul-1-neg49.5%
Simplified49.5%
if -3.00000000000000002e66 < y < 8.6000000000000003e-5Initial program 97.4%
associate-*l/98.6%
Simplified98.6%
Taylor expanded in y around 0 57.1%
Final simplification54.0%
(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 91.4%
associate-*l/98.7%
Simplified98.7%
Final simplification98.7%
(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 91.4%
associate-*l/98.7%
Simplified98.7%
*-commutative98.7%
clear-num98.7%
un-div-inv98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 64.0%
*-commutative64.0%
mul-1-neg64.0%
sub-neg64.0%
Simplified64.0%
Final simplification64.0%
(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 91.4%
associate-*l/98.7%
Simplified98.7%
Taylor expanded in y around 0 38.7%
Final simplification38.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 2023192
(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)))