
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (+ x -1.0)))) (if (<= (+ (* x y) t_0) INFINITY) (fma y x t_0) (* x y))))
double code(double x, double y, double z) {
double t_0 = z * (x + -1.0);
double tmp;
if (((x * y) + t_0) <= ((double) INFINITY)) {
tmp = fma(y, x, t_0);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * Float64(x + -1.0)) tmp = 0.0 if (Float64(Float64(x * y) + t_0) <= Inf) tmp = fma(y, x, t_0); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(x * y), $MachinePrecision] + t$95$0), $MachinePrecision], Infinity], N[(y * x + t$95$0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(x + -1\right)\\
\mathbf{if}\;x \cdot y + t\_0 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(y, x, t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 (-.f64 x #s(literal 1 binary64)) z)) < +inf.0Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift--.f64N/A
sub-negN/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
if +inf.0 < (+.f64 (*.f64 x y) (*.f64 (-.f64 x #s(literal 1 binary64)) z)) Initial program 0.0%
Taylor expanded in y around inf
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.35e+143)
(* x z)
(if (<= x -0.00036)
(* x y)
(if (<= x 1.0)
(- z)
(if (<= x 6e+64) (* x z) (if (<= x 1.66e+187) (* x y) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+143) {
tmp = x * z;
} else if (x <= -0.00036) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 6e+64) {
tmp = x * z;
} else if (x <= 1.66e+187) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.35d+143)) then
tmp = x * z
else if (x <= (-0.00036d0)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else if (x <= 6d+64) then
tmp = x * z
else if (x <= 1.66d+187) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+143) {
tmp = x * z;
} else if (x <= -0.00036) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 6e+64) {
tmp = x * z;
} else if (x <= 1.66e+187) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.35e+143: tmp = x * z elif x <= -0.00036: tmp = x * y elif x <= 1.0: tmp = -z elif x <= 6e+64: tmp = x * z elif x <= 1.66e+187: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.35e+143) tmp = Float64(x * z); elseif (x <= -0.00036) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); elseif (x <= 6e+64) tmp = Float64(x * z); elseif (x <= 1.66e+187) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.35e+143) tmp = x * z; elseif (x <= -0.00036) tmp = x * y; elseif (x <= 1.0) tmp = -z; elseif (x <= 6e+64) tmp = x * z; elseif (x <= 1.66e+187) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.35e+143], N[(x * z), $MachinePrecision], If[LessEqual[x, -0.00036], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), If[LessEqual[x, 6e+64], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.66e+187], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+143}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -0.00036:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 6 \cdot 10^{+64}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.66 \cdot 10^{+187}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.3500000000000001e143 or 1 < x < 6.0000000000000004e64 or 1.6600000000000001e187 < x Initial program 93.7%
Taylor expanded in y around 0
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6453.7
Applied rewrites53.7%
Taylor expanded in x around inf
Applied rewrites53.1%
if -1.3500000000000001e143 < x < -3.60000000000000023e-4 or 6.0000000000000004e64 < x < 1.6600000000000001e187Initial program 98.1%
Taylor expanded in y around inf
lower-*.f6450.2
Applied rewrites50.2%
if -3.60000000000000023e-4 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6470.6
Applied rewrites70.6%
Final simplification61.4%
herbie shell --seed 2024228
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))