
(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 5 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 90.7%
associate-*l/97.2%
Simplified97.2%
*-commutative97.2%
clear-num97.2%
un-div-inv97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z t) :precision binary64 (if (<= z -7e+20) (+ x (* z (/ y t))) (if (<= z 7e+25) (- x (* x (/ y t))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -7e+20) {
tmp = x + (z * (y / t));
} else if (z <= 7e+25) {
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 (z <= (-7d+20)) then
tmp = x + (z * (y / t))
else if (z <= 7d+25) 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 (z <= -7e+20) {
tmp = x + (z * (y / t));
} else if (z <= 7e+25) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -7e+20: tmp = x + (z * (y / t)) elif z <= 7e+25: tmp = x - (x * (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -7e+20) tmp = Float64(x + Float64(z * Float64(y / t))); elseif (z <= 7e+25) 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 (z <= -7e+20) tmp = x + (z * (y / t)); elseif (z <= 7e+25) tmp = x - (x * (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -7e+20], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 7e+25], 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}\;z \leq -7 \cdot 10^{+20}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+25}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -7e20Initial program 90.0%
associate-*l/98.4%
Simplified98.4%
Taylor expanded in z around inf 81.2%
associate-*l/89.5%
*-commutative89.5%
Simplified89.5%
if -7e20 < z < 6.99999999999999999e25Initial program 94.9%
associate-*l/96.9%
Simplified96.9%
Taylor expanded in x around inf 87.7%
distribute-lft-in87.7%
mul-1-neg87.7%
distribute-rgt-neg-in87.7%
distribute-lft-neg-out87.7%
*-rgt-identity87.7%
neg-mul-187.7%
associate-*r*87.7%
associate-*r/86.0%
mul-1-neg86.0%
unsub-neg86.0%
associate-*r/87.7%
Simplified87.7%
if 6.99999999999999999e25 < z Initial program 83.2%
associate-*l/96.7%
Simplified96.7%
Taylor expanded in z around inf 81.9%
associate-*l/91.3%
*-commutative91.3%
Simplified91.3%
clear-num91.4%
div-inv91.6%
Applied egg-rr91.6%
Final simplification89.1%
(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 90.7%
associate-*l/97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x y z t) :precision binary64 (+ x (* z (/ y t))))
double code(double x, double y, double z, double t) {
return x + (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 + (z * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + (z * (y / t));
}
def code(x, y, z, t): return x + (z * (y / t))
function code(x, y, z, t) return Float64(x + Float64(z * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + (z * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \frac{y}{t}
\end{array}
Initial program 90.7%
associate-*l/97.2%
Simplified97.2%
Taylor expanded in z around inf 70.0%
associate-*l/76.0%
*-commutative76.0%
Simplified76.0%
Final simplification76.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 90.7%
associate-*l/97.2%
Simplified97.2%
Taylor expanded in y around 0 39.0%
Final simplification39.0%
(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 2023275
(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)))