
(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 4 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.9%
associate-*l/97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (x y z t) :precision binary64 (if (<= z -4.4e-61) (+ x (* (/ y t) z)) (if (<= z 8.8e-19) (- x (* x (/ y t))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4.4e-61) {
tmp = x + ((y / t) * z);
} else if (z <= 8.8e-19) {
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 <= (-4.4d-61)) then
tmp = x + ((y / t) * z)
else if (z <= 8.8d-19) 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 <= -4.4e-61) {
tmp = x + ((y / t) * z);
} else if (z <= 8.8e-19) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -4.4e-61: tmp = x + ((y / t) * z) elif z <= 8.8e-19: tmp = x - (x * (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -4.4e-61) tmp = Float64(x + Float64(Float64(y / t) * z)); elseif (z <= 8.8e-19) 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 <= -4.4e-61) tmp = x + ((y / t) * z); elseif (z <= 8.8e-19) tmp = x - (x * (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -4.4e-61], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 8.8e-19], 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 -4.4 \cdot 10^{-61}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{elif}\;z \leq 8.8 \cdot 10^{-19}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -4.40000000000000017e-61Initial program 92.9%
associate-*l/97.9%
Simplified97.9%
Taylor expanded in z around inf 84.2%
associate-*l/87.8%
*-commutative87.8%
Simplified87.8%
if -4.40000000000000017e-61 < z < 8.7999999999999994e-19Initial program 95.4%
associate-*l/95.8%
Simplified95.8%
Taylor expanded in z around 0 89.4%
associate-*r/90.6%
associate-*l*90.6%
neg-mul-190.6%
*-commutative90.6%
Simplified90.6%
if 8.7999999999999994e-19 < z Initial program 92.4%
associate-*l/98.5%
Simplified98.5%
Taylor expanded in z around inf 83.1%
associate-*l/88.0%
*-commutative88.0%
Simplified88.0%
clear-num88.0%
un-div-inv88.1%
Applied egg-rr88.1%
Final simplification89.1%
(FPCore (x y z t) :precision binary64 (+ x (* (/ y t) z)))
double code(double x, double y, double z, double t) {
return x + ((y / t) * z);
}
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)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * z);
}
def code(x, y, z, t): return x + ((y / t) * z)
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * z)) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * z); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot z
\end{array}
Initial program 93.9%
associate-*l/97.1%
Simplified97.1%
Taylor expanded in z around inf 68.0%
associate-*l/72.3%
*-commutative72.3%
Simplified72.3%
Final simplification72.3%
(FPCore (x y z t) :precision binary64 (+ x (/ z (/ t y))))
double code(double x, double y, double z, double t) {
return x + (z / (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 / (t / y))
end function
public static double code(double x, double y, double z, double t) {
return x + (z / (t / y));
}
def code(x, y, z, t): return x + (z / (t / y))
function code(x, y, z, t) return Float64(x + Float64(z / Float64(t / y))) end
function tmp = code(x, y, z, t) tmp = x + (z / (t / y)); end
code[x_, y_, z_, t_] := N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z}{\frac{t}{y}}
\end{array}
Initial program 93.9%
associate-*l/97.1%
Simplified97.1%
Taylor expanded in z around inf 68.0%
associate-*l/72.3%
*-commutative72.3%
Simplified72.3%
clear-num72.0%
un-div-inv72.4%
Applied egg-rr72.4%
Final simplification72.4%
(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 2024011
(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)))