
(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 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.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.7
Applied rewrites98.7%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.1e+82) (fma (/ (- t z) a) y x) (if (<= a 7.2e-106) (fma (/ (- z t) z) y x) (fma (/ t a) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.1e+82) {
tmp = fma(((t - z) / a), y, x);
} else if (a <= 7.2e-106) {
tmp = fma(((z - t) / z), y, x);
} else {
tmp = fma((t / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.1e+82) tmp = fma(Float64(Float64(t - z) / a), y, x); elseif (a <= 7.2e-106) tmp = fma(Float64(Float64(z - t) / z), y, x); else tmp = fma(Float64(t / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.1e+82], N[(N[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[a, 7.2e-106], N[(N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.1 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - z}{a}, y, x\right)\\
\mathbf{elif}\;a \leq 7.2 \cdot 10^{-106}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{z}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\end{array}
\end{array}
if a < -1.1000000000000001e82Initial program 71.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in a around 0
lower-/.f64N/A
lower--.f6452.7
Applied rewrites52.7%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6489.3
Applied rewrites89.3%
if -1.1000000000000001e82 < a < 7.20000000000000025e-106Initial program 91.4%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6486.6
Applied rewrites86.6%
if 7.20000000000000025e-106 < a Initial program 86.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in z around 0
lower-/.f6482.9
Applied rewrites82.9%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.02e-104) (fma (/ z (- z a)) y x) (if (<= a 7.2e-106) (fma (/ (- z t) z) y x) (fma (/ t a) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.02e-104) {
tmp = fma((z / (z - a)), y, x);
} else if (a <= 7.2e-106) {
tmp = fma(((z - t) / z), y, x);
} else {
tmp = fma((t / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.02e-104) tmp = fma(Float64(z / Float64(z - a)), y, x); elseif (a <= 7.2e-106) tmp = fma(Float64(Float64(z - t) / z), y, x); else tmp = fma(Float64(t / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.02e-104], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[a, 7.2e-106], N[(N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.02 \cdot 10^{-104}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{elif}\;a \leq 7.2 \cdot 10^{-106}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{z}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\end{array}
\end{array}
if a < -1.02000000000000001e-104Initial program 76.8%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6480.7
Applied rewrites80.7%
if -1.02000000000000001e-104 < a < 7.20000000000000025e-106Initial program 92.0%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6490.2
Applied rewrites90.2%
if 7.20000000000000025e-106 < a Initial program 86.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in z around 0
lower-/.f6482.9
Applied rewrites82.9%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (fma (/ z (- z a)) y x))) (if (<= z -2.15e-40) t_1 (if (<= z 1.3e-29) (+ (/ (* y t) a) x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma((z / (z - a)), y, x);
double tmp;
if (z <= -2.15e-40) {
tmp = t_1;
} else if (z <= 1.3e-29) {
tmp = ((y * t) / a) + x;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(z / Float64(z - a)), y, x) tmp = 0.0 if (z <= -2.15e-40) tmp = t_1; elseif (z <= 1.3e-29) tmp = Float64(Float64(Float64(y * t) / a) + x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[z, -2.15e-40], t$95$1, If[LessEqual[z, 1.3e-29], N[(N[(N[(y * t), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{if}\;z \leq -2.15 \cdot 10^{-40}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-29}:\\
\;\;\;\;\frac{y \cdot t}{a} + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.1500000000000001e-40 or 1.3000000000000001e-29 < z Initial program 77.8%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6485.3
Applied rewrites85.3%
if -2.1500000000000001e-40 < z < 1.3000000000000001e-29Initial program 97.1%
Taylor expanded in z around 0
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
Final simplification82.3%
(FPCore (x y z t a) :precision binary64 (if (<= z -4.1e-40) (+ x y) (if (<= z 6.6e+132) (fma (/ t a) y x) (+ x y))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -4.1e-40) {
tmp = x + y;
} else if (z <= 6.6e+132) {
tmp = fma((t / a), y, x);
} else {
tmp = x + y;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -4.1e-40) tmp = Float64(x + y); elseif (z <= 6.6e+132) tmp = fma(Float64(t / a), y, x); else tmp = Float64(x + y); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4.1e-40], N[(x + y), $MachinePrecision], If[LessEqual[z, 6.6e+132], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-40}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+132}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -4.09999999999999963e-40 or 6.6000000000000006e132 < z Initial program 76.5%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6481.7
Applied rewrites81.7%
if -4.09999999999999963e-40 < z < 6.6000000000000006e132Initial program 94.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.5
Applied rewrites97.5%
Taylor expanded in z around 0
lower-/.f6474.7
Applied rewrites74.7%
Final simplification78.2%
(FPCore (x y z t a) :precision binary64 (if (<= z -4.1e-40) (+ x y) (if (<= z 6.6e+132) (fma (/ y a) t x) (+ x y))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -4.1e-40) {
tmp = x + y;
} else if (z <= 6.6e+132) {
tmp = fma((y / a), t, x);
} else {
tmp = x + y;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -4.1e-40) tmp = Float64(x + y); elseif (z <= 6.6e+132) tmp = fma(Float64(y / a), t, x); else tmp = Float64(x + y); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4.1e-40], N[(x + y), $MachinePrecision], If[LessEqual[z, 6.6e+132], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-40}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+132}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -4.09999999999999963e-40 or 6.6000000000000006e132 < z Initial program 76.5%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6481.7
Applied rewrites81.7%
if -4.09999999999999963e-40 < z < 6.6000000000000006e132Initial program 94.1%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6474.1
Applied rewrites74.1%
Final simplification77.8%
(FPCore (x y z t a) :precision binary64 (if (<= y -1.4e+140) (* (/ t a) y) (+ x y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= -1.4e+140) {
tmp = (t / a) * y;
} else {
tmp = x + y;
}
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 (y <= (-1.4d+140)) then
tmp = (t / a) * y
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= -1.4e+140) {
tmp = (t / a) * y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if y <= -1.4e+140: tmp = (t / a) * y else: tmp = x + y return tmp
function code(x, y, z, t, a) tmp = 0.0 if (y <= -1.4e+140) tmp = Float64(Float64(t / a) * y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (y <= -1.4e+140) tmp = (t / a) * y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[y, -1.4e+140], N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+140}:\\
\;\;\;\;\frac{t}{a} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -1.39999999999999991e140Initial program 63.5%
Taylor expanded in x around 0
associate-/l*N/A
div-subN/A
distribute-lft-out--N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6469.0
Applied rewrites69.0%
Taylor expanded in z around 0
Applied rewrites38.5%
Applied rewrites48.0%
if -1.39999999999999991e140 < y Initial program 88.0%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6468.4
Applied rewrites68.4%
Final simplification66.1%
(FPCore (x y z t a) :precision binary64 (if (<= t 9e+272) (+ x y) (* (/ y a) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 9e+272) {
tmp = x + y;
} else {
tmp = (y / a) * t;
}
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 (t <= 9d+272) then
tmp = x + y
else
tmp = (y / a) * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 9e+272) {
tmp = x + y;
} else {
tmp = (y / a) * t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= 9e+272: tmp = x + y else: tmp = (y / a) * t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= 9e+272) tmp = Float64(x + y); else tmp = Float64(Float64(y / a) * t); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= 9e+272) tmp = x + y; else tmp = (y / a) * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, 9e+272], N[(x + y), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 9 \cdot 10^{+272}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{a} \cdot t\\
\end{array}
\end{array}
if t < 9.00000000000000059e272Initial program 85.3%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6465.6
Applied rewrites65.6%
if 9.00000000000000059e272 < t Initial program 86.4%
Taylor expanded in x around 0
associate-/l*N/A
div-subN/A
distribute-lft-out--N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6499.8
Applied rewrites99.8%
Taylor expanded in z around 0
Applied rewrites58.3%
Applied rewrites71.9%
Final simplification65.7%
(FPCore (x y z t a) :precision binary64 (+ x y))
double code(double x, double y, double z, double t, double a) {
return x + y;
}
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
end function
public static double code(double x, double y, double z, double t, double a) {
return x + y;
}
def code(x, y, z, t, a): return x + y
function code(x, y, z, t, a) return Float64(x + y) end
function tmp = code(x, y, z, t, a) tmp = x + y; end
code[x_, y_, z_, t_, a_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 85.4%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6463.9
Applied rewrites63.9%
Final simplification63.9%
(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 2024294
(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))))