
(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 7 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 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 96.1%
*-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
metadata-eval96.1%
neg-mul-196.1%
associate-+r+96.1%
unsub-neg96.1%
+-commutative96.1%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -5e-78) (* x y) (if (<= x 1.8e-65) (- z) (if (<= x 1.22e+232) (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-78) {
tmp = x * y;
} else if (x <= 1.8e-65) {
tmp = -z;
} else if (x <= 1.22e+232) {
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 <= (-5d-78)) then
tmp = x * y
else if (x <= 1.8d-65) then
tmp = -z
else if (x <= 1.22d+232) 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 <= -5e-78) {
tmp = x * y;
} else if (x <= 1.8e-65) {
tmp = -z;
} else if (x <= 1.22e+232) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5e-78: tmp = x * y elif x <= 1.8e-65: tmp = -z elif x <= 1.22e+232: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5e-78) tmp = Float64(x * y); elseif (x <= 1.8e-65) tmp = Float64(-z); elseif (x <= 1.22e+232) 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 <= -5e-78) tmp = x * y; elseif (x <= 1.8e-65) tmp = -z; elseif (x <= 1.22e+232) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5e-78], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.8e-65], (-z), If[LessEqual[x, 1.22e+232], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-78}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-65}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{+232}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -4.9999999999999996e-78 or 1.7999999999999999e-65 < x < 1.21999999999999994e232Initial program 93.9%
Taylor expanded in y around inf 57.4%
if -4.9999999999999996e-78 < x < 1.7999999999999999e-65Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 76.7%
neg-mul-176.7%
Simplified76.7%
if 1.21999999999999994e232 < x Initial program 93.8%
*-commutative93.8%
sub-neg93.8%
distribute-rgt-in93.8%
metadata-eval93.8%
neg-mul-193.8%
associate-+r+93.8%
unsub-neg93.8%
+-commutative93.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 76.7%
Taylor expanded in x around inf 76.7%
*-commutative76.7%
Simplified76.7%
Final simplification65.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -45000.0) (not (<= x 0.0006))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -45000.0) || !(x <= 0.0006)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - 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 <= (-45000.0d0)) .or. (.not. (x <= 0.0006d0))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -45000.0) || !(x <= 0.0006)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -45000.0) or not (x <= 0.0006): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -45000.0) || !(x <= 0.0006)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -45000.0) || ~((x <= 0.0006))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -45000.0], N[Not[LessEqual[x, 0.0006]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -45000 \lor \neg \left(x \leq 0.0006\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -45000 or 5.99999999999999947e-4 < x Initial program 92.8%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
if -45000 < x < 5.99999999999999947e-4Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 98.5%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-76) (not (<= x 1.15e-63))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-76) || !(x <= 1.15e-63)) {
tmp = x * (z + y);
} else {
tmp = -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 <= (-8.5d-76)) .or. (.not. (x <= 1.15d-63))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-76) || !(x <= 1.15e-63)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-76) or not (x <= 1.15e-63): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-76) || !(x <= 1.15e-63)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.5e-76) || ~((x <= 1.15e-63))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-76], N[Not[LessEqual[x, 1.15e-63]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-76} \lor \neg \left(x \leq 1.15 \cdot 10^{-63}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.50000000000000038e-76 or 1.15e-63 < x Initial program 93.9%
Taylor expanded in x around inf 93.6%
+-commutative93.6%
Simplified93.6%
if -8.50000000000000038e-76 < x < 1.15e-63Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 76.7%
neg-mul-176.7%
Simplified76.7%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e-76) (not (<= x 1.36e-65))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-76) || !(x <= 1.36e-65)) {
tmp = x * y;
} else {
tmp = -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 <= (-4.2d-76)) .or. (.not. (x <= 1.36d-65))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-76) || !(x <= 1.36e-65)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-76) or not (x <= 1.36e-65): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-76) || !(x <= 1.36e-65)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.2e-76) || ~((x <= 1.36e-65))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-76], N[Not[LessEqual[x, 1.36e-65]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-76} \lor \neg \left(x \leq 1.36 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.19999999999999985e-76 or 1.35999999999999999e-65 < x Initial program 93.9%
Taylor expanded in y around inf 55.6%
if -4.19999999999999985e-76 < x < 1.35999999999999999e-65Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 76.7%
neg-mul-176.7%
Simplified76.7%
Final simplification63.1%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 96.1%
*-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
metadata-eval96.1%
neg-mul-196.1%
associate-+r+96.1%
unsub-neg96.1%
+-commutative96.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 75.2%
Taylor expanded in x around 0 32.8%
neg-mul-132.8%
Simplified32.8%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 96.1%
*-commutative96.1%
sub-neg96.1%
distribute-rgt-in96.1%
metadata-eval96.1%
neg-mul-196.1%
associate-+r+96.1%
unsub-neg96.1%
+-commutative96.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 75.2%
Taylor expanded in x around 0 32.8%
neg-mul-132.8%
Simplified32.8%
add-sqr-sqrt16.9%
sqrt-unprod19.5%
sqr-neg19.5%
sqrt-unprod1.2%
add-log-exp4.0%
add-sqr-sqrt9.3%
add-sqr-sqrt9.3%
sqrt-unprod9.3%
*-un-lft-identity9.3%
exp-prod9.3%
add-sqr-sqrt4.0%
sqrt-unprod5.0%
sqr-neg5.0%
sqrt-unprod0.9%
add-sqr-sqrt1.7%
exp-prod1.7%
*-un-lft-identity1.7%
exp-neg1.8%
rgt-mult-inverse2.7%
metadata-eval2.7%
metadata-eval2.7%
Applied egg-rr2.7%
herbie shell --seed 2024140
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))