
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y * (z - t)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (- (/ z (- z a)) (/ t (- z a))) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z / (z - a)) - (t / (z - a))), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z / Float64(z - a)) - Float64(t / Float64(z - a))), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] - N[(t / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{z - a} - \frac{t}{z - a}, y, x\right)
\end{array}
Initial program 85.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.7
Applied rewrites97.7%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lift-/.f64N/A
lower--.f64N/A
lower-/.f6497.7
Applied rewrites97.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) (- z a))))
(if (or (<= t_1 -5e+34) (not (<= t_1 5000000000000.0)))
(* (/ y (- z a)) (- z t))
(fma (/ z (- z a)) y x))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / (z - a);
double tmp;
if ((t_1 <= -5e+34) || !(t_1 <= 5000000000000.0)) {
tmp = (y / (z - a)) * (z - t);
} else {
tmp = fma((z / (z - a)), y, x);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / Float64(z - a)) tmp = 0.0 if ((t_1 <= -5e+34) || !(t_1 <= 5000000000000.0)) tmp = Float64(Float64(y / Float64(z - a)) * Float64(z - t)); else tmp = fma(Float64(z / Float64(z - a)), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+34], N[Not[LessEqual[t$95$1, 5000000000000.0]], $MachinePrecision]], N[(N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{z - a}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+34} \lor \neg \left(t\_1 \leq 5000000000000\right):\\
\;\;\;\;\frac{y}{z - a} \cdot \left(z - t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < -4.9999999999999998e34 or 5e12 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) Initial program 70.9%
Taylor expanded in x around 0
distribute-lft-out--N/A
fp-cancel-sub-signN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
div-add-revN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
associate-*r*N/A
distribute-rgt-outN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6486.0
Applied rewrites86.0%
if -4.9999999999999998e34 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < 5e12Initial program 98.8%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6490.1
Applied rewrites90.1%
Final simplification88.2%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -3.6e-37) (not (<= z 2.25e-45))) (fma (/ (- z t) z) y x) (fma (/ y a) t x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -3.6e-37) || !(z <= 2.25e-45)) {
tmp = fma(((z - t) / z), y, x);
} else {
tmp = fma((y / a), t, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -3.6e-37) || !(z <= 2.25e-45)) tmp = fma(Float64(Float64(z - t) / z), y, x); else tmp = fma(Float64(y / a), t, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -3.6e-37], N[Not[LessEqual[z, 2.25e-45]], $MachinePrecision]], N[(N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{-37} \lor \neg \left(z \leq 2.25 \cdot 10^{-45}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{z}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\end{array}
\end{array}
if z < -3.60000000000000007e-37 or 2.2499999999999999e-45 < z Initial program 80.3%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if -3.60000000000000007e-37 < z < 2.2499999999999999e-45Initial program 93.1%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
Final simplification83.1%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -9.2e-39) (not (<= z 2e-47))) (fma (/ z (- z a)) y x) (fma (/ y a) t x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -9.2e-39) || !(z <= 2e-47)) {
tmp = fma((z / (z - a)), y, x);
} else {
tmp = fma((y / a), t, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -9.2e-39) || !(z <= 2e-47)) tmp = fma(Float64(z / Float64(z - a)), y, x); else tmp = fma(Float64(y / a), t, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -9.2e-39], N[Not[LessEqual[z, 2e-47]], $MachinePrecision]], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-39} \lor \neg \left(z \leq 2 \cdot 10^{-47}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\end{array}
\end{array}
if z < -9.20000000000000033e-39 or 1.9999999999999999e-47 < z Initial program 80.4%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6480.5
Applied rewrites80.5%
if -9.20000000000000033e-39 < z < 1.9999999999999999e-47Initial program 93.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.6
Applied rewrites83.6%
Final simplification81.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -7.2e-37) (not (<= z 2e-47))) (fma z (/ y (- z a)) x) (fma (/ y a) t x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -7.2e-37) || !(z <= 2e-47)) {
tmp = fma(z, (y / (z - a)), x);
} else {
tmp = fma((y / a), t, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -7.2e-37) || !(z <= 2e-47)) tmp = fma(z, Float64(y / Float64(z - a)), x); else tmp = fma(Float64(y / a), t, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -7.2e-37], N[Not[LessEqual[z, 2e-47]], $MachinePrecision]], N[(z * N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-37} \lor \neg \left(z \leq 2 \cdot 10^{-47}\right):\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{z - a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\end{array}
\end{array}
if z < -7.20000000000000014e-37 or 1.9999999999999999e-47 < z Initial program 80.4%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6480.5
Applied rewrites80.5%
Applied rewrites77.5%
if -7.20000000000000014e-37 < z < 1.9999999999999999e-47Initial program 93.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.6
Applied rewrites83.6%
Final simplification80.0%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -1.08e-36) (not (<= z 3800000.0))) (+ y x) (fma (/ y a) t x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -1.08e-36) || !(z <= 3800000.0)) {
tmp = y + x;
} else {
tmp = fma((y / a), t, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -1.08e-36) || !(z <= 3800000.0)) tmp = Float64(y + x); else tmp = fma(Float64(y / a), t, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -1.08e-36], N[Not[LessEqual[z, 3800000.0]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.08 \cdot 10^{-36} \lor \neg \left(z \leq 3800000\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\end{array}
\end{array}
if z < -1.08000000000000006e-36 or 3.8e6 < z Initial program 77.7%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6473.0
Applied rewrites73.0%
if -1.08000000000000006e-36 < z < 3.8e6Initial program 94.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.7
Applied rewrites79.7%
Final simplification76.2%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -4.3e-159) (not (<= z 4.6e-262))) (+ y x) (* t (/ y a))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.3e-159) || !(z <= 4.6e-262)) {
tmp = y + x;
} else {
tmp = t * (y / a);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((z <= (-4.3d-159)) .or. (.not. (z <= 4.6d-262))) then
tmp = y + x
else
tmp = t * (y / a)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.3e-159) || !(z <= 4.6e-262)) {
tmp = y + x;
} else {
tmp = t * (y / a);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (z <= -4.3e-159) or not (z <= 4.6e-262): tmp = y + x else: tmp = t * (y / a) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -4.3e-159) || !(z <= 4.6e-262)) tmp = Float64(y + x); else tmp = Float64(t * Float64(y / a)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((z <= -4.3e-159) || ~((z <= 4.6e-262))) tmp = y + x; else tmp = t * (y / a); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.3e-159], N[Not[LessEqual[z, 4.6e-262]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(t * N[(y / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{-159} \lor \neg \left(z \leq 4.6 \cdot 10^{-262}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t \cdot \frac{y}{a}\\
\end{array}
\end{array}
if z < -4.3e-159 or 4.6000000000000002e-262 < z Initial program 84.6%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6462.5
Applied rewrites62.5%
if -4.3e-159 < z < 4.6000000000000002e-262Initial program 91.2%
Taylor expanded in x around 0
distribute-lft-out--N/A
fp-cancel-sub-signN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
div-add-revN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
associate-*r*N/A
distribute-rgt-outN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6453.7
Applied rewrites53.7%
Taylor expanded in z around 0
Applied rewrites44.0%
Applied rewrites51.1%
Final simplification60.7%
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- z a)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (z - a)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(z - a)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{z - a}, y, x\right)
\end{array}
Initial program 85.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.7
Applied rewrites97.7%
(FPCore (x y z t a) :precision binary64 (+ y x))
double code(double x, double y, double z, double t, double a) {
return y + x;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = y + x
end function
public static double code(double x, double y, double z, double t, double a) {
return y + x;
}
def code(x, y, z, t, a): return y + x
function code(x, y, z, t, a) return Float64(y + x) end
function tmp = code(x, y, z, t, a) tmp = y + x; end
code[x_, y_, z_, t_, a_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
y + x
\end{array}
Initial program 85.6%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6456.8
Applied rewrites56.8%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- z a) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y / ((z - a) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((z - a) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(z - a) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((z - a) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{z - a}{z - t}}
\end{array}
herbie shell --seed 2024337
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- z a) (- z t)))))
(+ x (/ (* y (- z t)) (- z a))))